myPant0

Q: Convert VIDEO_TS FOLDERS to ISO applescript

Hello

I have several VIDEO_TS folders from my DVD collection. I learn I can use the terminal to convert them to ISO files.

with this terminal conversion I found here.

hdiutil makehybrid -udf -udf-volume-name NameOfYourDVDHere -o ImageFileName.iso /path/to/VIDEO_TS/parent/folder

 

I would like to wrap it in an AppleScript whit these additional options:

 

1st The Script Chooses various VIDEO_TS folder. Previously I already put the VIDEO_TS folder in another named with the film title. Example so the folder will be FILMNAME––>VIDEO_TS and the result should be FILMNAME.ISO

2nd Locates a folder where save the ISO files

3rd Batch performs the conversion through the terminal

4th and more

Continues to convert VIDEO_TS folders until they are all converted

 

Is this easy and possible?

 

Thanks for any help.

Mac mini, OS X Yosemite (10.10.5)

Posted on Sep 28, 2016 8:22 AM

Close

Q: Convert VIDEO_TS FOLDERS to ISO applescript

  • All replies
  • Helpful answers

  • by Camelot,

    Camelot Camelot Sep 28, 2016 11:21 AM in response to myPant0
    Level 8 (47,305 points)
    Mac OS X
    Sep 28, 2016 11:21 AM in response to myPant0

    This is pretty straightforward. Assuming I read your post correctly, you have one directory that contains a number of subdirectories that correspond to individual movies. Each of these subdirectories has a subsequent VIDEO_TS directory.

     

    If that's the case, this should do the trick (untested since I don't have any VIDEO_TS on my system). The comments should give you an idea of what the script is doing, but feel free to ask if you need clarification.

     

    use AppleScript version "2.4" -- Yosemite (10.10) or later

    use scripting additions

     

    -- define where to save the output .iso

    set outputFolder to "/path/to/output/"

    set films_list to {}

     

     

    -- prompt for the top level folder

    set topFolder to (choose folder with prompt "Select the folder that contains your films")

    tell application "Finder"

      -- get a list of the subdirectories (c.f. movie folders) within the selected folder

      set films_folders to every folder of topFolder

      repeat with each_film_folder in films_folders

      -- check there's actually a VIDEO_TS folder inside

      if exists folder "VIDEO_TS" of each_film_folder then

      -- build a list of films

      copy each_film_folder as alias to end of films_list

      end if

      end repeat

      -- now we have a list of valid film folders

     

      -- work through the folders

      repeat with this_film in films_list

      set film_name to name of this_film

      set this_video_ts_file to POSIX path of this_film & "VIDEO_TS"

      -- now we can work our magic:

     

      do shell script "/usr/bin/hdiutil makehybrid -udf -udf-volume-name " & film_name & " -o " & output_folder & film_name & ".iso " & this_video_ts_file

      end repeat

     

    end tell


  • by Hiroto,

    Hiroto Hiroto Sep 29, 2016 4:52 AM in response to myPant0
    Level 5 (7,341 points)
    Sep 29, 2016 4:52 AM in response to myPant0

    Hello

     

    If I'm not mistaken, you might try something like this.

     

     

    set src to (choose folder with prompt "Choose source folder")'s POSIX path
    set dst to (choose folder with prompt "Choose destination folder")'s POSIX path
    set args to ""
    repeat with a in {src, dst}
        set args to args & a's quoted form & space
    end repeat
    
    do shell script "/bin/bash -s <<'EOF' - " & args & "
    SRC=${1%/}
    DST=${2%/}
    while IFS= read -r -d $'\\0' f
    do
        # f = VIDEO_TS directory
        # d = f's parent directory
        # n = d's name
        d=${f%/*}                   
        n=${d##*/}
        hdiutil makehybrid -udf -udf-volume-name \"$n\" -o \"$DST/$n.iso\" \"$d\"
    done < <(find \"$SRC\" -type d -iname VIDEO_TS -print0)
    EOF"
    

     

     

     

    Good luck,

    H

  • by myPant0,

    myPant0 myPant0 Sep 29, 2016 8:16 AM in response to Hiroto
    Level 1 (4 points)
    Desktops
    Sep 29, 2016 8:16 AM in response to Hiroto

    Hello Hiroto thanks for your suggestion

    It does work and creates the ISO file, however parts of the VIDEO_TS files get lost in the process or so it seems.

    When I launch VCL to read the ISO file the Playback and Subtitles options are no longer available while they are in the VIDEO_TS folder.

    In the AppleScript editor the Result stays at

    Result:

    "Creating hybrid image...

    Creating hybrid image...

    Creating hybrid image...

    Creating hybrid image..."


    While noemally it is

    ""

    Or at least this is what usually happens

     

    Is there something I should do?

     

    Regards

  • by myPant0,

    myPant0 myPant0 Sep 29, 2016 8:20 AM in response to Camelot
    Level 1 (4 points)
    Desktops
    Sep 29, 2016 8:20 AM in response to Camelot

    Thanks for your help

    However I am unable to understand the error which happens all the time

    At first I thought I needed to tonly choose a folder with one film but even in this case I still get this error

    Result:

    error "Finder got an error: hdiutil: makehybrid: multiple sources specified

    hdiutil: makehybrid failed - Invalid argument" number 1


    Just in case here is the whole result and various operations performed with the script

    tell application "Script Editor"

    choose folder with prompt "Select the folder that contains your films"

    choose folder with prompt "Choose destination folder"

    end tell

    tell application "Finder"

    get every folder of alias "OtherFilms:America:AL:"

    exists folder "VIDEO_TS" of folder "ISOs" of folder "AL" of folder "America" of disk "OtherFilms"

    exists folder "VIDEO_TS" of folder "The Big Sleep" of folder "AL" of folder "America" of disk "OtherFilms"

    get folder "The Big Sleep" of folder "AL" of folder "America" of disk "OtherFilms"

    exists folder "VIDEO_TS" of folder "untitled folder" of folder "AL" of folder "America" of disk "OtherFilms"

    get name of alias "OtherFilms:America:AL:The Big Sleep:"

    do shell script "/usr/bin/hdiutil makehybrid -udf -udf-volume-name The Big Sleep -o /Volumes/OtherFilms/America/AL/ISOs/The Big Sleep.iso /Volumes/OtherFilms/America/AL/The Big Sleep/VIDEO_TS"

    end tell

    tell current application

    do shell script "/usr/bin/hdiutil makehybrid -udf -udf-volume-name The Big Sleep -o /Volumes/OtherFilms/America/AL/ISOs/The Big Sleep.iso /Volumes/OtherFilms/America/AL/The Big Sleep/VIDEO_TS"

    Result:

    error "Finder got an error: hdiutil: makehybrid: multiple sources specified

    hdiutil: makehybrid failed - Invalid argument" number 1


    Thanks

  • by myPant0,

    myPant0 myPant0 Sep 29, 2016 8:26 AM in response to Hiroto
    Level 1 (4 points)
    Desktops
    Sep 29, 2016 8:26 AM in response to Hiroto

    Usually a VIDEO_TS folder has these files:

    VIDEO_TS.BUP

    VIDEO_TS.IFO

    VTS_01_0.BUP

    VTS_01_0.IFO

    VTS_01_1.VOB

    VTS_01_2.VOB

    VTS_01_3.VOB

    VTS_01_4.VOB

    I am no expert but I think the

    VTS_01_0.BUP

    VTS_01_0.IFO

    files are the one with the general information while the VOB files are the containers for the Audio-VIdeo sections of the DVD

    I point it out because I think at least the Subtitles are stored in the IFO file which does not appear after the conversion while it appears if I convert the VIDEO_TS folder using DISK UTILITIES APP

    I dont know if the Terminal uses the same process as the Disk Utilities App

    In any case Disk Utilities is not scriptable at all ....

    Thanks again

  • by Camelot,

    Camelot Camelot Sep 29, 2016 9:22 AM in response to myPant0
    Level 8 (47,305 points)
    Mac OS X
    Sep 29, 2016 9:22 AM in response to myPant0

    Your problem here is completely different.

     

    the problem is that your film names contain spaces, and spaces are used by the shell to delimit parameters, so when it sees something like "... -udf-volume-name The Big Sleep' this gets interpreted as: "-udf-volume-name The', while "Big" and "Sleep" are interpreted as different parameters, hence the failure.

     

    To get around this you typically need to single-quote any parameter that contains spaces, so:

     

    ... -udf-volume-name 'The Big Sleep' ...

     

    Now the -udf-volume-name switch will see 'The Big Sleep' as its value and the rest should work fine.

     

    Now, that said, there are other errors in your script. You are running checks that are subsequently ignored. For example you start with:

     

    choose folder with prompt "Select the folder that contains your films"


    but you don't store that result anywhere or reference it anywhere in the script.

     

    In addition, you:

     

    get every folder of alias "OtherFilms:America:AL:"


    but then ignore the result and target specific, named directories, which requires that you know in advance what the relevant directories are.


    I suggest going back to my original script, just change the do shell script command to quote the parameters and you should be fine. So change:


      do shell script "/usr/bin/hdiutil makehybrid -udf -udf-volume-name " & film_name & " -o " & output_folder & film_name & ".iso " & this_video_ts_file


    to:

      do shell script "/usr/bin/hdiutil makehybrid -udf -udf-volume-name '" & film_name & "' -o '" & output_folder & film_name & ".iso' " & quoted form of this_video_ts_file


    (note the extra single quotes around the variables)


  • by myPant0,

    myPant0 myPant0 Sep 29, 2016 2:34 PM in response to Camelot
    Level 1 (4 points)
    Desktops
    Sep 29, 2016 2:34 PM in response to Camelot

    Thanks for your patience Camelot

    Certainly the Folders With the film names have spaces ... and I am not at all experienced therefore I wasn't aware of this problem.

    However I only added one line to the script you kindly suggested.

    This because running it as it was in the Editor after copying it from the discussion

    I received this error:

     

    Script Error

    Finder got an error: hdiutil: makehybrid: error creating output file

    hdiutil: makehybrid failed - No such file or directory

     

    As the location of the script was the "shell script" I decided to a second variable defining the "destination folder" as the lines opening your script:

    set outputfolder to "/path/to/output/"

    or attempting to change it as it was in the shell script:

    set output-folder to "/path/to/output/"

    always gave the error so I added the following

    set output_folder to (choose folder with prompt "Select destination folder for conversion")

    basically copying it from the previous line of your script asking to locate the work folder.


    I didn't touch anything at all in the script and I was not aware of the spaces in the film titles as a problem.


    the lines I added in my first reply are not "my version of the script. They are simply what I found in the

    EVENTS list of the script Editor after running the script.

    I simpli copied the events as they happened and pasted them in my first reply to you.


    I now copied again the whole scrip you sent and changed the SHELL SCRIPT as from your latest suggestion but now I get this error:

    error "Finder got an error: hdiutil: makehybrid: error creating output file

    hdiutil: makehybrid failed - No such file or directory" number 1


    And I am totally lost.

    I will no longer copy and paste the EVENTS as I realize they are misleading and suggest I modified your script, when all I did was add a line to tell where the Destination folder was as the script didn't run unless defined.


    Thanks again for your patience and the attention to my problem

    Regards

  • by Camelot,

    Camelot Camelot Sep 29, 2016 2:48 PM in response to myPant0
    Level 8 (47,305 points)
    Mac OS X
    Sep 29, 2016 2:48 PM in response to myPant0

    Certainly the Folders With the film names have spaces ... and I am not at all experienced therefore I wasn't aware of this problem.

    It's OK. Spaces in file names are something that Mac users are very used to, but they do need extra care in the shell.

     

    The problem with:

     

    set output_folder to (choose folder with prompt "Select destination folder for conversion")


    is that choose folder returns an Apple-specific alias object that contains way more data than a simple filename or pathname. The shell has no idea how to deal with aliases or their associated data, so the shell command chokes. The solution (once you know it) is pretty straightforward - just extract the UNIX-style path from the alias, which is something that the shell can handle.


    So instead of:

     

    set output_folder to (choose folder with prompt "Select destination folder for conversion")


    use:


    set output_folder to quoted form of POSIX path of (choose folder with prompt "Select destination folder for conversion")


    the 'POSIX path of..' an alias returns the UNIX-style path (e.g. '/path/to/folder'). Then I've added 'quoted form of...' to properly quote it for the shell in case the path has spaces or other characters that choke the shell.


    If it still doesn't work, edit the shell command to prefix with 'echo' (e.g. do shell script "echo /usr/bin/hdiutil...") and you should see the full command that it's trying to execute. Post that here and it might provide more clues.

  • by Hiroto,

    Hiroto Hiroto Sep 29, 2016 5:53 PM in response to myPant0
    Level 5 (7,341 points)
    Sep 29, 2016 5:53 PM in response to myPant0

    Hello

     

    I'm not sure but you might try the following alternative. It will create .iso on desktop and then move it to destination.

     

    * If perchance your files are on NAS, I think you'd need to first copy the source folder to local volume, run the script and select copy on local volume as source. Directly manipulating files on NAS is not at all good idea.

     

     

    set src to (choose folder with prompt "Choose source folder")'s POSIX path
    set dst to (choose folder with prompt "Choose destination folder")'s POSIX path
    set args to ""
    repeat with a in {src, dst}
        set args to args & a's quoted form & space
    end repeat
    
    do shell script "/bin/bash -s <<'EOF' - " & args & "
    SRC=${1%/}
    DST=${2%/}
    TMP=~/Desktop
    cd \"$TMP\" || exit
    while IFS= read -r -d $'\\0' f
    do
        # f = VIDEO_TS directory
        # d = f's parent directory
        # n = d's name
        d=${f%/*}                   
        n=${d##*/}
        hdiutil makehybrid -udf -udf-volume-name \"$n\" -o \"$n.iso\" \"$d\"
        mv \"$n.iso\" \"$DST\"
    done < <(find \"$SRC\" -type d -iname VIDEO_TS -print0)
    EOF"
    

     

     

    Regards,

    H

  • by myPant0,

    myPant0 myPant0 Oct 1, 2016 10:37 AM in response to Hiroto
    Level 1 (4 points)
    Desktops
    Oct 1, 2016 10:37 AM in response to Hiroto

    Hello Hiroto thanks for your attention

    I am not sure to understand this point: If perchance your files are on NAS

    IU don't know what NAS means (sorry for this, and I will now try the new version of the script

    Thanks

  • by Hiroto,Solvedanswer

    Hiroto Hiroto Oct 1, 2016 4:25 PM in response to myPant0
    Level 5 (7,341 points)
    Oct 1, 2016 4:25 PM in response to myPant0

    Hello

     

    NAS = Network-attached Storage, which is a class of storage accessed via network. E.g., if your OtherFilms volume is on a network and you mount it via AFP, SMB etc, it is NAS. Meanwhile, if your OtherFilms volume is of an external hard disk attached via USB, FireWire etc, it is not NAS (usually).

     

     

    ---

    As for the missing .IFO files, I wonder your original command using hdiutil in Terminal produces complete iso image with those files in question?

     

    In other words, provided that your source VIDEO_TS directory is ~/Desktop/test/FilmName/VIDEO_TS, does the following commands in Terminal produce proper iso image as ~/Destop/test/FilmName.iso:

     

     

    #!/bin/bash
    cd ~/Desktop/test || exit
    hdiutil makehybrid -udf -udf-volume-name FilmName -o FilmName.iso FilmName
    

     

     

    ?

     

    If it does, I see no reason why the following script, that is the same as the preivous alternative except for src and dst, does not:

     

    --APPLESCRIPT 2a
    set src to (path to desktop)'s POSIX path & "test"
    set dst to src
    set args to ""
    repeat with a in {src, dst}
        set args to args & a's quoted form & space
    end repeat
    
    do shell script "/bin/bash -s <<'EOF' - " & args & "
    SRC=${1%/}
    DST=${2%/}
    TMP=~/Desktop
    cd \"$TMP\" || exit
    while IFS= read -r -d $'\\0' f
    do
        # f = VIDEO_TS directory
        # d = f's parent directory
        # n = d's name
        d=${f%/*}                   
        n=${d##*/}
        hdiutil makehybrid -udf -udf-volume-name \"$n\" -o \"$n.iso\" \"$d\"
        mv \"$n.iso\" \"$DST\"
    done < <(find \"$SRC\" -type d -iname VIDEO_TS -print0)
    EOF"
    --END OF APPLESCRIPT 2a
    

     

     

     

    Regards,

    H

  • by myPant0,

    myPant0 myPant0 Oct 3, 2016 4:16 AM in response to Camelot
    Level 1 (4 points)
    Desktops
    Oct 3, 2016 4:16 AM in response to Camelot

    Hello Camelot and thanks again for your time

    Here is the full script after the various corrections you suggested me

     

    use AppleScript version "2.4" -- Yosemite (10.10) or later

    use scripting additions

     

    -- define where to save the output .iso

    set topFolder to (choose folder with prompt "Select the folder that contains your films")

    set output_folder to quoted form of POSIX path of (choose folder with prompt "Select destination folder for conversion")

    tell application "Finder"

    -- get a list of the subdirectories (c.f. movie folders) within the selected folder

      set films_folders to every folder of topFolder

      repeat with each_film_folder in films_folders

      -- check there's actually a VIDEO_TS folder inside

      if exists folder "VIDEO_TS" of each_film_folder then

      -- build a list of films

      copy each_film_folder as alias to end of films_list

      end if

      end repeat

    -- now we have a list of valid film folders

     

    -- work through the folders

      repeat with this_film in films_list

      set film_name to name of this_film

      set this_video_ts_file to POSIX path of this_film & "VIDEO_TS"

      -- now we can work our magic:

     

      -- now we can work our magic:

     

      do shell script "echo/usr/bin/hdiutil makehybrid -udf -udf-volume-name '" & film_name & "' -o '" & output_folder & film_name & ".iso' " & quoted form of this_video_ts_file

      end repeat

     

    end tell

     

    However I am still unable to run it

    I am indeed using Yosemite and Script Editor 2.4 so this should be fine

    I receive now this error

    error "The variable films_list is not defined." number -2753 from "films_list"

    But I am unable to change this variable to make the script run.

    If you still have time I will be very grateful receiving an additional suggestion

    Kind Regards