[BASH] How to create your own postprocessingscript

Come up with a useful post-processing script? Share it here!

Re: [BASH] How to create your own postprocessingscript

Postby grfxninja » June 11th, 2012, 5:53 am

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
grfxninja
Newbie
Newbie
 
Posts: 4
Joined: June 11th, 2012, 5:42 am

Re: [BASH] How to create your own postprocessingscript

Postby sander » June 11th, 2012, 6:10 am

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?
User avatar
sander
Release Testers
Release Testers
 
Posts: 3513
Joined: January 22nd, 2008, 3:22 pm

Re: [BASH] How to create your own postprocessingscript

Postby grfxninja » June 11th, 2012, 11:06 am

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
grfxninja
Newbie
Newbie
 
Posts: 4
Joined: June 11th, 2012, 5:42 am

Re: [BASH] How to create your own postprocessingscript

Postby sander » June 11th, 2012, 11:40 am

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 ... :)
User avatar
sander
Release Testers
Release Testers
 
Posts: 3513
Joined: January 22nd, 2008, 3:22 pm

Re: [BASH] How to create your own postprocessingscript

Postby grfxninja » June 11th, 2012, 9:27 pm

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 :)
grfxninja
Newbie
Newbie
 
Posts: 4
Joined: June 11th, 2012, 5:42 am

Re: [BASH] How to create your own postprocessingscript

Postby sander » June 12th, 2012, 1:13 am

See http://wiki.sabnzbd.org/user-scripts ... so

rm -rf "$1"

is worth a try
User avatar
sander
Release Testers
Release Testers
 
Posts: 3513
Joined: January 22nd, 2008, 3:22 pm

Re: [BASH] How to create your own postprocessingscript

Postby grfxninja » June 12th, 2012, 1:47 am

aah OK, that makes sense. I’ll give it a go.

Cheers for the help :)
grfxninja
Newbie
Newbie
 
Posts: 4
Joined: June 11th, 2012, 5:42 am

Re: [BASH] How to create your own postprocessingscript

Postby meemorize » July 12th, 2012, 6:40 am

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?
meemorize
Newbie
Newbie
 
Posts: 13
Joined: April 12th, 2009, 6:43 am

Re: [BASH] How to create your own postprocessingscript

Postby bugmenot2 » February 28th, 2013, 1:47 pm

Mar2zz wrote:On unix it's always best practice to quote paths, or else your shell will read until the first space or special character, cuts of the variable right there and takes that as input.
Code: Select all
extract-xiso -xsd "$1" "$1/*.iso"


Thank you, just what I looked. but how can I make a new folder based on file name?

extract-xiso -xsd /media/2TB/xbox.extract/ISO_name/ ISO_name.iso
bugmenot2
Newbie
Newbie
 
Posts: 30
Joined: August 18th, 2011, 1:31 am

Previous

Return to Post-Processing Scripts