linux illiterate needs help making a post processing script

Come up with a useful post-processing script? Share it here!
Post Reply
mrgreaper
Newbie
Newbie
Posts: 21
Joined: April 17th, 2008, 11:39 am

linux illiterate needs help making a post processing script

Post by mrgreaper »

ok heres the ultermint plan;

tv episodes converted for my archos upon download! no more queing up on my main pc to converrt cross network

ok first i did ask about this ages ago but at that time i had a differnet plan of attack and the pc was used for more then sabnzbd

i have spent the last two days trying to get a command line conversion tool to do what i do in lathe and finaly im close (just need to tweak the sttings but thats not what i need help with)

ok i can think of two approaches but have ZERO skill at making scripts hell less then zero so i really need help with this (being dyslexic dont help either lol)

aproach one

1) the post process script finds the largest .avi file in the download folder and marks that to a varrible name, lets say $file for ease and the folder name as $folder
2) the post process script hands that varrible to another script (so to not bog down sabnzb)
3) the other script executes the following command "mencoder /$folder/$file -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/$file_DONE.avi"

the pros of that is i will proberly understand it easier once some one explains the how lol and its simple (looking atleast) the disadvantage is i could end up with a few mencoders running at the same time (not sure if that would crash the pc)

aproach two

1) the post process script finds the largest .avi file in the download folder and marks that to a varrible name, lets say $file for ease and the folder name as $folder
2) /$folder/$file is added to the botom of a list
3) once an hour mencoder checks to see if its in the processes list(does linux have one?) if it is then it does nothing if it isnt it moves to 4
4) mencoder starts converting using the first filename and location on the list once done it deletes the first name from the list and does the second
5) repeats till the list is empty at which point it will likely error and close so the next hour mencoder launches it will see no mencoder and do any new ones on the list

i prefer aproach two but anything that will work would be good, i know im asking a lot but i just not linux savy enough to do it myself and trying to figure it out makes my head hurt (like i say it took twodays just to get the command line converter to work woth me putting the command in (and for that i had a lot of help)

my linux distro is ubuntu 8.04 (hardy?) my sabnzbd+ is the latest final build 0.4.4  and any help is greatly appreciated

**************EDIT************************
hat i have done to find a solution so far;
i know that sabnzbd passes the directory name to a script as $1 so that is the folder i need to search though for the largest avi

ls -lR | sort +4n seems to be the key i have found it on several sites telling you how to find the biggest file on your hard drive (im also guessing the R means recursive so it would end up searching all folders but thats where my knowledge and google start to fail (googles is only as effective as the brain using it :( )

i did also think of another aproach, instead of writting them to a text file as in aproach 2 maybe it would be easier to write them to a database (mysql or something) again lots of help available to install mysql not a lot in how to use it like i want to, damn i wish i was better at this

ok while writing this i recieved this code

Code: Select all

files=`ls -S "$1"`
file=`echo $files | cut -d' ' -f1`
fileLC=`echo $file | tr 'A-Z' 'a-z'`
cd $1
from there i could just add mencoder /$1/$file -ovc xvid -oac mp3lame -xvidencopts bitrate=748:aspect=16/9 -lameopts br=80 -vf scale=424:234 -o /home/mrgreaper/archos/$file_DONE.avi" and i guess aproach 1 would be done (if its right, it looks 90% confusing to me)

taking that script i did a search on a few of the commands and found this
echo '$1$file' >> /home/mrgreaper/conv.text
would append the file name and directory to a text file, now how im stuck again how do i read it out to mencoder a line at a time deleting the line afterwards?
Last edited by mrgreaper on November 9th, 2008, 7:11 am, edited 1 time in total.
mrgreaper
Newbie
Newbie
Posts: 21
Joined: April 17th, 2008, 11:39 am

Re: linux illiterate needs help making a post processing script

Post by mrgreaper »

with help from another site, i mean lets face it i wasnt going to get help here!
this is the following script hopefully it will help others

Code: Select all

dir=$1
cd "$dir"
file="$(ls -1S *.avi | head -n 1)" ; echo $file >> /home/mrgreaper/conv.text

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=600:aspect=16/9 -lameopts abr:br=92 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

im adding to it to make files get moved to a different folder etc and when i have it perfected ill post it here, at the mo the additional looks like this

Code: Select all

mv "$dir"/"$file" /home/mrgreaper/done/"$file"

rm "$dir"


find /home/mrgreaper/done -mtime +14 -print0 | xargs -0 rm -f
that means nothing older then 14 days left in the done folder and the original folder should get deleted, but it dont

and guys in future a bit of help would of been nice
mrgreaper
Newbie
Newbie
Posts: 21
Joined: April 17th, 2008, 11:39 am

Re: linux illiterate needs help making a post processing script

Post by mrgreaper »

ok here is the completed script

Code: Select all

dir=$1
cd "$dir"
file="$(ls -1S *.avi | head -n 1)" ; echo $file >> /home/mrgreaper/conv.text

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=600:aspect=16/9 -lameopts abr:br=92 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi

mv "$dir"/"$file" /home/mrgreaper/done/"$file"

rmdir --ignore-fail-on-non-empty "$dir"


find /home/mrgreaper/done -mtime +14 -print0 | xargs -0 rm -f

lets break it down a bit

Code: Select all

dir=$1
cd "$dir"
this takes the $1 which is the completed folder and creates a more workable varible $dir

Code: Select all

file="$(ls -1S *.avi | head -n 1)" ; echo $file >> /home/mrgreaper/conv.text
this was orignly added as i wanted to write the files to a list and then have memcoder encode them seperately so as to not hold up the history que, sadly im no where near that inteligent and with not enough help here i decided to adapt it to create a database in text format so i can check what i have if need be, not terribly useful but hay it dont hurt to leave it in :)

Code: Select all

mencoder "$file" -ovc xvid -oac mp3lame -xvidencopts bitrate=600:aspect=16/9 -lameopts abr:br=92 -vf scale=424:234 -o /home/mrgreaper/archos/"$file"_DONE.avi
this is where the magic happens and the files get converted you can customise this to make different files for different devices just google mencoder and your device, chances are someone will have the best settings for it :) this also saves the converted file into a folder for later transfer and appends the word _DONE.avi to the end so test.avi becomes test.avi_DONE.avi

Code: Select all

mv "$dir"/"$file" /home/mrgreaper/done/"$file"
this moves the original file to a tempory storage folder for my mates to grab or for if the conversion went wrong

Code: Select all

rmdir --ignore-fail-on-non-empty "$dir"
this deletes the folder from the downloads complete section and helps keep it neat (its the newest correction to the script and as such untested)

Code: Select all

find /home/mrgreaper/done -mtime +14 -print0 | xargs -0 rm -f
this bit looks at the tempory storage folder and deletes anything over 14days old

i cant take much credit for this as i was majorly helped (not here) over at linux questions but the concept is all mine lol

you will need to change the dirs if you want to use the script (feel free to) just renember to use / not \ seems linux is REALLY fussy oh and if you add to it or stream line it please post the changed version for others to enjoy :)
Post Reply