Page 2 of 3

Re: [BASH] How to create your own postprocessingscript

Posted: June 11th, 2012, 4:53 am
by grfxninja
Hi,
I haven’t got a clue when it comes to scripting, so I was hoping someone might be able to help me out with something.

I’m running Sabnzbd+ on my iMac. Once the download is finished, iVi Pro picks up the downloaded video and converts it, then drops it into iTunes. This always leaves behind an empty folder that the file was contained in. (iVi deletes the file once it has successfully converted it to put in iTunes)
What I’d like to do is:
- Sabnzbd downloads the file to a temporary folder - in this case we’ll call it “downloads”
- Post Processing script runs doing the following:
- Grab any video files in the folder (avi, mpg, mkv, etc.) and move only those to a separate folder “convert”
- Deletes the original folder
Then iVi Pro can convert the file, and delete the original when finished.

Is this something that could be achieved fairly simply with a post processing script?

Cheers

Re: [BASH] How to create your own postprocessingscript

Posted: June 11th, 2012, 5:10 am
by sander
First do it manually:

cd ... (to directory containing the files)
mv *.mpg /blabla/blabla/convert/
mv *.mkv /blabla/blabla/convert/
mv *.avi /blabla/blabla/convert/
mv *.AVI /blabla/blabla/convert/


Does that work?

Re: [BASH] How to create your own postprocessingscript

Posted: June 11th, 2012, 10:06 am
by grfxninja
Yes, that works fine, as does

Code: Select all

mv *.avi *.mov /path/to/convert 
So I assume I could create 1 “move” line rather than having multiple lines

Re: [BASH] How to create your own postprocessingscript

Posted: June 11th, 2012, 10:40 am
by sander
grfxninja wrote:Yes, that works fine, as does

Code: Select all

mv *.avi *.mov /path/to/convert 
So I assume I could create 1 “move” line rather than having multiple lines
Have you tried?

FYI: I tried:

Code: Select all

drwxrwxr-x  3 sander sander 4096 Jun 11 17:39 ./
drwxr-xr-x 10 sander sander 4096 Jun 11 17:39 ../
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.avi
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.mpg
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.MPG
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.txt
drwxrwxr-x  2 sander sander 4096 Jun 11 17:39 sub/
sander@R540:~/kul/kul2$ mv *.avi *.mpg sub/
sander@R540:~/kul/kul2$ ll
total 12
drwxrwxr-x  3 sander sander 4096 Jun 11 17:39 ./
drwxr-xr-x 10 sander sander 4096 Jun 11 17:39 ../
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.MPG
-rw-rw-r--  1 sander sander    0 Jun 11 17:39 adfa.txt
drwxrwxr-x  2 sander sander 4096 Jun 11 17:39 sub/
sander@R540:~/kul/kul2$ 
So ... :)

Re: [BASH] How to create your own postprocessingscript

Posted: June 11th, 2012, 8:27 pm
by grfxninja
Sorry, you lost me with all that stuff :D

If you’re asking if I tried to move multiple items using a 1 line command, then yes, and it works as expected.
So all I would need to do then is to delete the original folder that those files were contained in - only if the previous mv command was successful.

So I guess - once the script has moved the specified file types - I would need to tell the script to go up one directory level, then delete the directory that it just moved files from. How would I go about specifying the correct directory?

Thanks for your help :)

Re: [BASH] How to create your own postprocessingscript

Posted: June 12th, 2012, 12:13 am
by sander
See http://wiki.sabnzbd.org/user-scripts ... so

rm -rf "$1"

is worth a try

Re: [BASH] How to create your own postprocessingscript

Posted: June 12th, 2012, 12:47 am
by grfxninja
aah OK, that makes sense. I’ll give it a go.

Cheers for the help :)

Re: [BASH] How to create your own postprocessingscript

Posted: July 12th, 2012, 5:40 am
by meemorize
Thanks for this awesome write up!

I'm experimenting with writing a little TVRage lookup script that will get all the episode info and format it nicely then rewrite the video file name for me.

I've got most of the script part worked out, the only bit I'm struggling with is how I can get the final file path (to the actual video file) when the automated TV sorting and renaming is enabled in sab.

Logging out all the arguments I get supplied into my shell script the "clean" name is still based off of the original .nzb file name rather than it being the name after the automated sorting and initial renaming has been done by sab.

Is there any way of firing the script after the TV Sorting and Renaming by sab has been done and be supplied an absolute file path to the output file?

Re: [BASH] How to create your own postprocessingscript

Posted: April 15th, 2015, 9:50 am
by Fexel
Im really new in this.

If I download a password protected .NZB (and of course knew the pw^^) i will name the NZB, i allways like this:
name123 password

name123 = to know later what this download is.
password = The Password to extract.

My Idea of a post proc. script is this:

After the space in the nzbfile name (example: name123>space<password) allways comes the password. So the script should read the letters after the space and use them as the password for the file and -of course- extract it^^.

Is that possible?

Bye

Re: [BASH] How to create your own postprocessingscript

Posted: April 15th, 2015, 11:35 am
by jcfp
Fexel wrote:Is that possible?
Above all, it's unnecessary. Sab has this functionality built-in, see wiki

Re: [BASH] How to create your own postprocessingscript

Posted: April 15th, 2015, 3:53 pm
by Fexel
It dont work with this wiki hint.

name password

dont work. A "/" isnt possible in files. I have to type name password=the password

That is not what i want. So please, maybe someone can tell me how to create a script to let SAB know that "nameOffile" "password" works?


- - -

You can rename the job in the queue.
"My Job / PASSWORD" will set the password. The '/' is used as a separator because it cannot be part of a folder name.

Also not work. Cant edit the File - there is no rename option for me.

Re: [BASH] How to create your own postprocessingscript

Posted: April 18th, 2015, 10:29 am
by Mark88
Hi all,

i'm trying to run a Pre Process script to remove some words in the filenames.
I'm unable to run any script in my terminal when ssh'ing into my Synology Diskstation.
if i dir the folder i can see all the files, but if i try to run the scripts i get file not found.

if i'm unable to test the scripts i'll never be able to run it succesfully.

Can anyone give me some help!?

thnx in advance!

Re: [BASH] How to create your own postprocessingscript

Posted: April 18th, 2015, 2:20 pm
by ALbino
By default the working directory for the script is the program directory (at least on Windows), so you probably need to manually change directories in your script to the one containing your extracted files.

To test you could maybe make a simple example script that just outputs a directory listing to see what's in there.

Re: [BASH] How to create your own postprocessingscript

Posted: October 20th, 2016, 7:54 pm
by Spamixxus
Hello :)

for about three days, I try to create a scriptwrapper of sabnzbd to nzbToMedia and an second script with the same start parameters.

Steps to do:
1. Download an episode in a series
2. Import with "nzbToMedia" in Sick Rage
3. Start the second script

My environment:

Code: Select all

root@sabnzbd_1:/var/db/sabnzbd/scripts/nzbToMedia # uname -a
FreeBSD sabnzbd_1 10.3-STABLE FreeBSD 10.3-STABLE #0 r295946+0ea9076(9.10-STABLE): Mon Oct  3 06:51:23 UTC 2016     root@gauntlet:/freenas-9.10-releng/_BE/objs/freenas-9.10-releng/_BE/os/sys/FreeNAS.amd64  amd64

SABnzbd+
Version: 	1.1.0 [8abcf08]
Zeit seit Start: 	1d
Konfigurationsdatei: 	/var/db/sabnzbd/sabnzbd.ini
Verwendeter cache: 	0 Artikel im Cache (0 B)
Parameter: 	/usr/pbi/sabnzbd-amd64/bin/SABnzbd.py -s 0.0.0.0 --daemon -f /var/db/sabnzbd/sabnzbd.ini --pidfile /var/run/sabnzbd/sabnzbd.pid
Python Version: 	2.7.9 (default, Sep 21 2016, 04:40:22) [GCC 4.2.1 20070831 patched [FreeBSD]] []
OpenSSL: 	OpenSSL 1.0.2d 9 Jul 2015   [TLS v1.2, TLS v1.1, TLS v1, SSL v3, SSL v2]
pyOpenSSL: 	0.15.1 

I have tried a "sh" script without success. With python I have not much experience that I get it work.
For you expert it is easy to realize something like that. :D

Here my attempts: ;(

Sabnzbd+ shows in the Log the following string.

Code: Select all

/var/db/sabnzbd/scripts/nzbToMedia/scriptwrapper.sh(/media/Downloads/Buecher/Hamburger Morgenpost vom 20.10.2016.5, Hamburger Morgenpost vom 20.10.2016.nzb, Hamburger Morgenpost vom 20.10.2016, , buecher, alt.binaries.aubergine, 0, )
sh:

Code: Select all

#!/usr/bin/sh
echo $1 $2 $3 $4 $5 $6 $7 $8
python /var/db/sabnzbd/scripts/nzbToMedia/nzbToSickBeard.py $1 $2 $3 $4 $5 $6 $7 $8
python /var/db/sabnzbd/scripts/nzbToMedia/sabtowizznab.py $1 $2 $3 $4 $5 $6 $7 $8
With my sh script, the String is not one line, because the "" are missing.

Code: Select all

root@sabnzbd_1:/var/db/sabnzbd/scripts/nzbToMedia # cat 1scriptwrapper.sh
#!/bin/sh
echo "1" $1 "2" $2 "3" $3 "4" $4 "5" $5 "6" $6 "7" $7 "8" $8
#python /var/db/sabnzbd/scripts/nzbToMedia/nzbToSickBeard.py $1 $2 $3 $4 $5 $6 $7 $8
#python /var/db/sabnzbd/scripts/nzbToMedia/sabtowizznab.py $1 $2 $3 $4 $5 $6 $7 $8
root@sabnzbd_1:/var/db/sabnzbd/scripts/nzbToMedia # ./1scriptwrapper.sh /media/Downloads/Buecher/Hamburger Morgenpost vom 20.10.2016.5, Hamburger Morgenpost vom 20.10.2016.nzb, Hamburger Morgenpost vom 20.10.2016, , buecher, alt.binaries.aubergine, 0,
1 /media/Downloads/Buecher/Hamburger 2 Morgenpost 3 vom 4 20.10.2016.5, 5 Hamburger 6 Morgenpost 7 vom 8 20.10.2016.nzb,
python:
I think the problem with the "" will be similar to the sh problem.

Code: Select all

root@sabnzbd_1:/var/db/sabnzbd/scripts/nzbToMedia # cat scriptwrapper.sh
#!/usr/bin/python
import sys
import nzbToMedia

try:
    (scriptname,directory,orgnzbname,jobname,reportnumber,category,group,postprocstatus,url) = sys.argv
except:
    try:
        # are we testing only?
        directory = sys.argv[1]
    except:
        print "No commandline parameters found"
        sys.exit(1)

# Only for Test
print "scriptname","directory","orgnzbname","jobname","reportnumber","category","group","postprocstatus","ur"
# Your code goes here

# Success code
sys.exit(0)
So, i think it would be easiest way if you could teach SABnzbd put the call in "" but how and if that's possible I do not know.

lg
Spami

Re: [BASH] How to create your own postprocessingscript

Posted: October 25th, 2016, 8:09 am
by jcfp
Spamixxus wrote:

Code: Select all

#!/usr/bin/sh
echo $1 $2 $3 $4 $5 $6 $7 $8
python /var/db/sabnzbd/scripts/nzbToMedia/nzbToSickBeard.py $1 $2 $3 $4 $5 $6 $7 $8
python /var/db/sabnzbd/scripts/nzbToMedia/sabtowizznab.py $1 $2 $3 $4 $5 $6 $7 $8
With my sh script, the String is not one line, because the "" are missing.
Proper quoting of variables in your script is your own responsibility. Without quoting, thing go awry as soon as you try to pass an argument that just happens to be empty (these disappear) or contains spaces (one argument becomes multiple).

While you're at it, note there's "$@" as a shorthand for all arguments. So simply /path/to/script "$@" would work just fine without the need to write out $1 through $n.