Script for Mounting ISO and extracting files

Come up with a useful post-processing script? Share it here!
Post Reply
drpete12
Newbie
Newbie
Posts: 5
Joined: March 2nd, 2015, 9:15 pm

Script for Mounting ISO and extracting files

Post by drpete12 » March 2nd, 2015, 9:19 pm

Hi

I searched but couldn't find anything. Is it possible (or has it been done already) to have a script that looks to see if finished download is an iso and if it is to mount it, extract (or copy) all the files into the directory and unmount and delete iso. I am at a loss as I am running Sab on unraid and now have to do all this from command line (and I am a newbie to command line :) )

Any help or ideas would be greatly appreciated

thanks

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

Re: Script for Mounting ISO and extracting files

Post by sander » March 3rd, 2015, 1:08 am

drpete12 wrote: now I have to do all this from command line (and I am a newbie to command line :) )
What are the commands you use for that?

Because ... you can put those commands together and you have a script.

drpete12
Newbie
Newbie
Posts: 5
Joined: March 2nd, 2015, 9:15 pm

Re: Script for Mounting ISO and extracting files

Post by drpete12 » March 5th, 2015, 7:48 pm

I have a friend helping me. here is what he has written. I have not put it into SAB yet but thought I would post what I have and you guys can look it over. Here goes:

#!/bin/bash
find "$1" -name '*.[iI][sS][oO]' -type f | while read iso_exist;
do
if [ "$iso_exist" ]; then
tempdir="/tmp/$RANDOM"
mkdir "$tempdir"
mount -o loop "$iso_exist" "$tempdir" 2>/dev/null
find $tempdir -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr | tail -1 | awk '{ print $9}' | while read biggest_file;
do
#fullpath1="$1"
folder_tmp_dir=${iso_exist##*/}
folder_name=`echo "$folder_tmp_dir" | sed 's/\.[^.]*$//'`
file_ext=${biggest_file##*.}
file_name=${biggest_file##*/}
cp "$biggest_file" "$1"
mv "$1"/"$file_name" "$1"/"$folder_name"."$file_ext"
umount "$tempdir"
[ $tempdir ] && rmdir "$tempdir"
rm "$iso_exist"
done
else exit 1
fi
done



the idea is it mounts, pulls biggest file out (usually the movie m2ts file) and then copies and unmount and deletes iso.

If you guys see anything please let me know.

Thanks

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

Re: Script for Mounting ISO and extracting files

Post by sander » March 6th, 2015, 5:50 am

Ouch ... bash-scripting. I can't help you with that. If your friend makes it working for you, that would be nice.

drpete12
Newbie
Newbie
Posts: 5
Joined: March 2nd, 2015, 9:15 pm

Re: Script for Mounting ISO and extracting files

Post by drpete12 » March 6th, 2015, 7:44 am

Hi Sander

My friend is pretty knowledgable. If just asked for a linux script. How would it be better than bash? If you tell me what would be better I will ask for that. Should it be done in PY???

Thanks for any help

Peter

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

Re: Script for Mounting ISO and extracting files

Post by sander » March 6th, 2015, 9:21 am

If it works, it's OK, isn't it?

drpete12
Newbie
Newbie
Posts: 5
Joined: March 2nd, 2015, 9:15 pm

Re: Script for Mounting ISO and extracting files

Post by drpete12 » March 6th, 2015, 1:15 pm

I placed the script in the directory where the other scripts are but it didn't show up in the list of choices for post-processing. Script was called iso.sh but I changed it to ISO.py and it shows up in list ( I assume I shouldn't do this but not sure how to get it to show in list)

Also, is there a way I can run the script manually in SAB to point it to downloaded file/directory or do i have to do an entire download and then see if it works.

Thanks

porkchop999
Newbie
Newbie
Posts: 1
Joined: May 6th, 2015, 12:03 am

Re: Script for Mounting ISO and extracting files

Post by porkchop999 » June 23rd, 2015, 2:51 pm

Did you get this going?

an3k
Newbie
Newbie
Posts: 18
Joined: June 16th, 2015, 10:49 am

Re: Script for Mounting ISO and extracting files

Post by an3k » June 25th, 2015, 6:08 am

drpete12 wrote:the idea is it mounts, pulls biggest file out (usually the movie m2ts file) and then copies and unmount and deletes iso.
That is a really bad idea! Many Blu-rays are authored in a way that contains the movie split into many smaller files. Just because I have this BD currently read into BDInfo:
Blu-ray Disc 3 of the Alien Anthology (Facehugger Edition) contains the movie Alien 3 in two editions. 1) Original cinema release from 1992 and 2) Special Edition from 2003. Because both movies share many scenes and to avoid having those stored twice on Disc the movie is split into plenty of files.

Files used in Cinema Release:

Code: Select all

Name            Time In         Length          Size            Total Bitrate   
----            -------         ------          ----            -------------   
00750.M2TS      0:00:00.000     0:03:29.751     0               0               
00700.M2TS      0:03:29.751     0:08:31.135     0               0               
00753.M2TS      0:12:00.886     0:01:37.347     0               0               
00701.M2TS      0:13:38.234     0:01:42.143     0               0               
00755.M2TS      0:15:20.377     0:06:28.471     0               0               
00703.M2TS      0:21:48.849     0:08:31.093     0               0               
00757.M2TS      0:30:19.943     0:01:25.627     0               0               
00704.M2TS      0:31:45.570     0:01:49.025     0               0               
00759.M2TS      0:33:34.595     0:02:15.260     0               0               
00705.M2TS      0:35:49.855     0:05:43.926     0               0               
00761.M2TS      0:41:33.782     0:04:49.872     0               0               
00706.M2TS      0:46:23.655     0:01:49.651     0               0               
00763.M2TS      0:48:13.306     0:02:53.298     0               0               
00707.M2TS      0:51:06.605     0:06:06.699     0               0               
00765.M2TS      0:57:13.304     0:01:03.480     0               0               
00708.M2TS      0:58:16.784     0:02:47.375     0               0               
00767.M2TS      1:01:04.160     0:02:24.769     0               0               
00709.M2TS      1:03:28.929     0:07:05.383     0               0               
00769.M2TS      1:10:34.313     0:01:40.558     0               0               
00710.M2TS      1:12:14.872     0:00:32.991     0               0               
00771.M2TS      1:12:47.863     0:01:27.462     0               0               
00711.M2TS      1:14:15.325     0:02:21.516     0               0               
00773.M2TS      1:16:36.842     0:02:33.736     0               0               
00712.M2TS      1:19:10.578     0:10:27.668     0               0               
00775.M2TS      1:29:38.247     0:13:37.858     0               0               
00713.M2TS      1:43:16.106     0:05:38.588     0               0               
00777.M2TS      1:48:54.694     0:05:57.440     0               0               
Files used in Special Edition:

Code: Select all

Name            Time In         Length          Size            Total Bitrate   
----            -------         ------          ----            -------------   
00750.M2TS      0:00:00.000     0:03:29.751     0               0               
00752.M2TS      0:03:29.751     0:11:10.711     0               0               
00753.M2TS      0:14:40.462     0:01:37.347     0               0               
00754.M2TS      0:16:17.810     0:01:38.223     0               0               
00755.M2TS      0:17:56.033     0:06:28.471     0               0               
00756.M2TS      0:24:24.504     0:13:18.756     0               0               
00757.M2TS      0:37:43.260     0:01:25.627     0               0               
00758.M2TS      0:39:08.888     0:02:16.845     0               0               
00759.M2TS      0:41:25.733     0:02:15.260     0               0               
00760.M2TS      0:43:40.993     0:08:32.428     0               0               
00761.M2TS      0:52:13.421     0:04:49.872     0               0               
00762.M2TS      0:57:03.294     0:02:30.024     0               0               
00763.M2TS      0:59:33.319     0:02:53.298     0               0               
00764.M2TS      1:02:26.617     0:07:24.902     0               0               
00765.M2TS      1:09:51.520     0:01:03.480     0               0               
00766.M2TS      1:10:55.000     0:03:17.822     0               0               
00767.M2TS      1:14:12.823     0:02:24.769     0               0               
00768.M2TS      1:16:37.592     0:18:33.779     0               0               
00769.M2TS      1:35:11.372     0:01:40.558     0               0               
00770.M2TS      1:36:51.930     0:02:43.538     0               0               
00771.M2TS      1:39:35.469     0:01:27.462     0               0               
00772.M2TS      1:41:02.931     0:02:37.782     0               0               
00773.M2TS      1:43:40.714     0:02:33.736     0               0               
00774.M2TS      1:46:14.451     0:12:50.603     0               0               
00775.M2TS      1:59:05.054     0:13:37.858     0               0               
00776.M2TS      2:12:42.913     0:06:12.288     0               0               
00777.M2TS      2:18:55.201     0:05:57.440     0               0               
The biggest file is 00768.M2TS but is only 0:18:33.779 in length. To be sure you always get the whole movie you should extract the directories BDMV\STREAM\ and BDMV\PLAYLIST\ completely. You then have to manually check with BDInfo. It lists all playlists and all files referenced in that playlist. In my case 00800.MPLS is the whole Cinema Release and 00801.MPLS is the whole Special Edition movie. After that I load the playlist of the edition I want into tsMuxeR and then can either demux video, audio, subtitles as independent files or remux to various other formats. However, I prefer demuxing and then remuxing with MKVMerge.

an3k
Newbie
Newbie
Posts: 18
Joined: June 16th, 2015, 10:49 am

Re: Script for Mounting ISO and extracting files

Post by an3k » June 25th, 2015, 6:20 am

drpete12 wrote:I placed the script in the directory where the other scripts are but it didn't show up in the list of choices for post-processing. Script was called iso.sh but I changed it to ISO.py and it shows up in list ( I assume I shouldn't do this but not sure how to get it to show in list)

Also, is there a way I can run the script manually in SAB to point it to downloaded file/directory or do i have to do an entire download and then see if it works.

Thanks
Do NOT rename a bash-script (iso.sh) to a python script (iso.py)! First Go to Config > Folders and set a path for Post-Processing Scripts Folder, eg. ".sabnzbd/scripts". Then place the scripts you actually want to use in that directory.
If you place your script where the other scripts (Sample-PostProc.sh, etc.) are SABnzbd will not find them because that's not the script directory. Also make sure that the access rights for your script file is correct, eg. 755 (rwxr-xr-x). If that's not the case do chmod 755 iso.sh

SABnzbd simply calls the script and appends "command line options", eg. bash /path/to/script/iso.sh "this is value 1" "this is value 2" "this 2 is value 3" and so on. If you want to testrun your script you can do that manually, just call it the same way SABnzbd would call it and append the SABnzbd and download specific command line options. See http://wiki.sabnzbd.org/user-scripts and to get your installation specific path and other stuff run Sample-PostProc.sh for any download. It does nothing but simply echo'ing the values submitted by SABnzbd. You then can use these to run your script manually.

Post Reply