Powershell script for moving sample mkvs into folder

Come up with a useful post-processing script? Share it here!
Post Reply
newk
Newbie
Newbie
Posts: 9
Joined: April 30th, 2012, 10:08 am

Powershell script for moving sample mkvs into folder

Post by newk »

Hi,
I am new at scripting but have started working on a script in Windows 10 for moving files in releasefolders named *sample*.mkv into a Sample folder. Because this functionality is not built into sabnzbd I believe?

I have one version of the script that works when launching it in the local releasefolder so to speak outside of sabnzbd.
E.G: Place saample.ps1 in c:\test\Very.l33t.2021.CAM.VCD-NOGRP and run it and it creates the Sample folder if not found and moves *sample*.mkv into it.

That looks like this:

Code: Select all

$local = Get-Location
$File = Get-ChildItem -Path $local\*sample*.mkv
$Folder = "$local\Sample"
$Folder2 = "$local\SAMPLE"

if( ( ( Test-Path $Folder ) -or ( Test-Path $Folder2 ) ) )
{
    "Sample already found"; break
}

    else
{
    New-Item -Path $Folder -ItemType "directory"
    Move-Item -Path $File -Destination $Folder
}
I then tried modifying it a bit and tying it together with sabnzbd using a wrapper batchfile (.bat) that looks like this:

Code: Select all

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Script\saample.ps1" -SAB_FINAL_NAME "%3"
The above saample.ps1 used in the .bat:

Code: Select all

$File = Get-ChildItem -Path "$SAB_FINAL_NAME\*sample*.mkv"
$Folder = "$SAB_FINAL_NAME\Sample"
$Folder2 = "$SAB_FINAL_NAME\SAMPLE"

if( ( ( Test-Path $Folder ) -or ( Test-Path $Folder2 ) ) )
{
    "Sample already found"; break
}

    else
{
    New-Item -Path $Folder -ItemType "directory"
    Move-Item -Path $File -Destination $Folder
}
However, when running this it just created C:\Sample and exits.
And if running it again I get "Sample already found", so that part works...

Can somebody point me in the right direction? I am not sure at all at how to use SAB_FINAL_NAME & %3 properly here.
I just found python examples here: https://sabnzbd.org/wiki/scripts/post-p ... s#env_vars
Batch to powershell maybe adds an extra layer of complexity?

Worst case scenario; if noone has any input maybe you even have a working script I can use?
Thanks

User avatar
sander
Release Testers
Release Testers
Posts: 7955
Joined: January 22nd, 2008, 2:22 pm

Re: Powershell script for moving sample mkvs into folder

Post by sander »

If your goal is to delete samples, checkout http://127.0.0.1:8080/sabnzbd/config/sw ... re_samples

Ignore Samples
Filter out sample files (e.g. video samples/proofs). Delete after download.

newk
Newbie
Newbie
Posts: 9
Joined: April 30th, 2012, 10:08 am

Re: Powershell script for moving sample mkvs into folder

Post by newk »

sander wrote: October 5th, 2021, 7:01 am If your goal is to delete samples, checkout http://127.0.0.1:8080/sabnzbd/config/sw ... re_samples

Ignore Samples
Filter out sample files (e.g. video samples/proofs). Delete after download.
Thanks, but my goal is to keep the samples. I like to keep the releases original and even re-create the directory structure and files (nfo, sfv, sample) with ReScene and ReSample if they are missing. Old habit from the olden days..
More info here -> http://rescene.wikidot.com
So the goal here is to keep the sample.mkv but instead of if being located in the same directory as the .rars, nfo + sfv (which it is when the download has finished) I would like it to be moved to its own Sample-folder.

newk
Newbie
Newbie
Posts: 9
Joined: April 30th, 2012, 10:08 am

Re: Powershell script for moving sample mkvs into folder

Post by newk »

Jesus christ. I thought someone might have had a solution for me, but dude from India is trying to sell a water purifier :D

Puzzled
Full Member
Full Member
Posts: 131
Joined: September 2nd, 2017, 3:02 am

Re: Powershell script for moving sample mkvs into folder

Post by Puzzled »

Add some debug output to the scripts. Print the directory the scripts are using as base and each command they are executing with the variables expanded. I don't know PS so I can't help you with the exact commands.

aguywhocantcode
Newbie
Newbie
Posts: 1
Joined: December 10th, 2021, 6:47 pm

Re: Powershell script for moving sample mkvs into folder

Post by aguywhocantcode »

It's not a Powershell script but it does what you're looking for. I'm a new user so I can't post link unedited https:// forums.sabnzbd. org/viewtopic.php?t=7966 It'll throw Sample, Subs and Proof into their own folders. I ended up hacking this script up to ignore downloads that contain mp3s since it would take any mp3s that contain the words sameple, subs or proof and put them in their own folder.

Code: Select all

@ECHO OFF

REM ----------- mrlss-SUD-v1b9.bat
REM ----------- movie release sorter - Sort/Unrar/Delete - version 1 build 9
REM ----------- sabnzbd - post-processing-script (windows)
REM 
REM ----------- description: - checks for nfo file
REM ------------------------ - creates sample, subs, proof and/or ac3 subfolders
REM ------------------------ - moves files and/or RARs to its subfolders 
REM ------------------------ - extracts movie file/s to the main dir
REM ------------------------ - deletes rar files and other stuff in main dir
REM ------------------------ - get a nice report and status line at the end
REM 
REM -- usage: - CHANGE "G:" TO YOUR HD-LETTER WHERE SABNZBD-DOWNLOAD-FOLDER IS LOCATED!
REM ---------
REM --------- - ADJUST THE WinRAR-INSTALL-PATH "%programfiles%\WinRAR\"
REM --------- - FOR 64bit WIN VISTA/7 YOU CAN USE "%ProgramFiles(x86)%"
REM ---------
REM --------- - SAVE CHANGES! xD
REM ---------
REM --------- - GO TO SABNZBD CONFIG, MAKE A NEW CATEGORY, CHOOSE "+REPAIR"!!!,
REM --------- - CHOOSE mrlss-SUD-v1b9.bat FROM SCRIPT FOLDER AND SAVE,
REM --------- - USE THE NEW CATEGORY WHEN ADDING NZBS FROM MOVIE RELEASES. HF!
REM 
REM ----------------- info: - use this script at your own risk (errors might occur)!
REM ----------------------- - checkout sabnzbd forums and help to improve if u like! ;)

SetLocal EnableDelayedExpansion

:MAIN

REM ------------------------- adjust letter to your hard-drive here!!!

D:
cd %1

REM variables for report at the end
set nfovar=0
set mp3var=0
set samplevar=0
set proofvar=0
set subsvar=0
set status=%7
REM checking for/printing jobname, nfo, sample, proof, subs and ac3addon
REM if available creating subfolders and moving files
REM subs and ac3addon files wont be extracted this way
:RLS
echo.
echo Release....: %3

:NFO
echo.
if exist *.nfo echo NFO: Yes & set nfovar=1 & goto MP3
echo NFO: No

:MP3
echo.
if exist *.mp3 echo MP3: Yes & set proofvar=0 & goto eof
echo MP3: No

:SAMPLE
echo.
if exist *sample*.* echo Sample: Yes & goto sam1
echo Sample: No
goto PROOF
:sam1
set samplevar=1
mkdir Sample >NUL 2>&1 
move *sample*.* Sample >NUL 2>&1
:PROOF
if exist *proof*.* echo Proof: Yes & goto proof1
echo Proof: No
goto SUBS
:proof1
if exist *.mp3 echo Proof: Yes & goto NFOT2
set proofvar=1
mkdir Proof >NUL 2>&1  
move *proof*.* Proof >NUL 2>&1
:SUBS
if exist *subs*.* echo Subs: Yes & goto subs1
echo Subs: No
goto NFOT2
:subs1
set subsvar=1
mkdir Subs >NUL 2>&1
move *subs*.* Subs >NUL 2>&1

:NFOT2
echo.
set /a Summe=%samplevar%+%proofvar%+%subsvar%
if %nfovar% EQU 0 echo Script-Status: OK-(-MOVIE-)-(--%Summe%--Subfolder/s)-(MiSSiNG NFO)
if %nfovar% EQU 1 echo Script-Status: OK-(-MOVIE-)-(--%Summe%--Subfolder/s)-(NFO)

goto eof

:DOEX2
echo.
echo.
echo %time% Extracting archive %1...
echo.
unrar.exe e %1 %location%
echo.
echo.
echo %time% Extraction complete.
echo.
echo.
if %status% EQU 0 echo Post-Process-Status: OK -E2-
if not %status% EQU 0 echo Post-Process-Error -E2-

:eof
ENDLOCAL

Post Reply