prupert
August 14th, 2009, 01:00 PM
Hi
I have a transcode script that coverts my .ts files created by my HTPC into .mkv files using handbrake. You can find the script at the end of the post here:
http://ubuntuforums.org/showthread.php?t=1218041
Generally, it works really well, however, sometimes, and I am not sure why, Handbrake freaks out and crashes, and the files don't get converted. In case this happens, I want to add some checks to the end of my script, to check if the files were converted or not.
To do this, I was thinking I can use find to search for all .ts files in the source folder and then use find to search for all .mkv files in the destination folder and if the filenames are the same, then obviously the conversion has worked and it can delete the source files.
The problem I am having is, since the files are in two different folders, and since they now have different extentions, I have no clue how to get the script to check.
I have got this far:
#!/bin/bash
# an attempt to check that all the files were formed correctly
find /mnt/media/documents/ruperts/TV -name "*.ts" -print0 | xargs -0 ls > /home/server/scripts/temp.txt
# find /mnt/media/documents/ruperts/TV -name "*.ts" > /home/server/scripts/temp.txt
find /media/video/Video/TV/tmp/ -name "*.mkv" > /home/server/scripts/temp1.txt
if [ "/home/server/scripts/temp.txt" = "/home/server/scripts/temp1.txt" ]; then
echo trans completed succesfully, starting clear up on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
find /media/video/Video/TV/tmp/ -name "*.mkv" -exec mv {} /media/video/Video/TV \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.ts" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.edl" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.txt" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.chap" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
echo ts files deleted and moved script stopped on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
else
echo mkv not present, trans failed on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
fi
But clearly this does not work.
Essentially, say I had the following in /mnt/media/documents/ruperts/TV:
program 1.ts
program2.ts
If the transcode worked successfully, I should then have in /media/video/Video/TV/tmp/:
program 1.mkv
program2.mkv
So the script should hopefully find just the file names in both folders, so it should see:
program 1
program2
And thus it would know the transcode worked, but I dont know how I can parse the file names to get this result....
Can anyone help me??
Thanks
I have a transcode script that coverts my .ts files created by my HTPC into .mkv files using handbrake. You can find the script at the end of the post here:
http://ubuntuforums.org/showthread.php?t=1218041
Generally, it works really well, however, sometimes, and I am not sure why, Handbrake freaks out and crashes, and the files don't get converted. In case this happens, I want to add some checks to the end of my script, to check if the files were converted or not.
To do this, I was thinking I can use find to search for all .ts files in the source folder and then use find to search for all .mkv files in the destination folder and if the filenames are the same, then obviously the conversion has worked and it can delete the source files.
The problem I am having is, since the files are in two different folders, and since they now have different extentions, I have no clue how to get the script to check.
I have got this far:
#!/bin/bash
# an attempt to check that all the files were formed correctly
find /mnt/media/documents/ruperts/TV -name "*.ts" -print0 | xargs -0 ls > /home/server/scripts/temp.txt
# find /mnt/media/documents/ruperts/TV -name "*.ts" > /home/server/scripts/temp.txt
find /media/video/Video/TV/tmp/ -name "*.mkv" > /home/server/scripts/temp1.txt
if [ "/home/server/scripts/temp.txt" = "/home/server/scripts/temp1.txt" ]; then
echo trans completed succesfully, starting clear up on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
find /media/video/Video/TV/tmp/ -name "*.mkv" -exec mv {} /media/video/Video/TV \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.ts" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.edl" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.txt" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.chap" -exec rm {} \; >> /mnt/media/documents/ruperts/TV/trans.log
echo ts files deleted and moved script stopped on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
else
echo mkv not present, trans failed on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
fi
But clearly this does not work.
Essentially, say I had the following in /mnt/media/documents/ruperts/TV:
program 1.ts
program2.ts
If the transcode worked successfully, I should then have in /media/video/Video/TV/tmp/:
program 1.mkv
program2.mkv
So the script should hopefully find just the file names in both folders, so it should see:
program 1
program2
And thus it would know the transcode worked, but I dont know how I can parse the file names to get this result....
Can anyone help me??
Thanks