Part 5: (Tutorial) Automating DVD Backup with FairMount, HandBrake and iTunes

Discussion in 'Apple TV and Home Theater' started by mac.jedi, Nov 14, 2008.

  1. macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #1

    Part 5: Automating DVD Backup with FairMount, HandBrake and iTunes

    Parts to this tutorial:
    Part 1: Introduction
    Part 2: Using AppleScript to Automate Ripping
    Part 3: Using a Batch Script to Automate HandBrake
    Part 4: TV Show Renamer Droplet
    Part 5: Add to iTunes and Auto-tag Script

    Add to iTunes and Auto-tag Script

    This AppleScript parses the video files' filenames, creates a playlist named AutoAdd on a remote machine, adds the file to the new iTunes playlist, tells iTunes to set the Episode or Movie name, season#, episode#, episodeID, Video Kind and Show Name. It then deletes the playlist leaving the files in their respective TV or Movie playlists.

    This was created to be a folder action attached to a TV Shows and/or Movies Folder. The script is executed whenever new files are added to these folders.

    Optional: If you keep your files on one machine and your iTunes Library is located on a remote machine (like a Mac Mini), you could edit this script to add the files the remote machine's iTunes Library. See the optional steps listed below.


    Creating Your Script:

    1. Select, copy and paste the script below into a new Script Editor document.

      Code:
      -- ADD TO ITUNES AND AUTO-TAG SCRIPT
      
      (* This AppleScript parses the video files' filenames, creates a playlist named AutoAdd on a remote machine, adds the file to the new iTunes playlist, tells iTunes to set the Episode or Movie name, season#, episode#, episodeID, Video Kind and Show Name. It then deletes the playlist leaving the files in their respective TV or Movie playlists.
      
      This was created to be a folder action attached to a TV Shows and/or Movies Folder. The script is executed whenever new files are added to these folders.
      
      OPTIONAL: If you are adding to remote computer's iTunes Library, you will need to make a couple edits to this script: 
      	1. Add the remMachine variable below. 
      	2. On the line: Tell application "iTunes", delete the "--" before "of machine remMachine" so it reads: tell application "iTunes" of machine remMachine.
      	3. Enable "Remote Apple Events" in the Sharing Preference Pane on the remote machine. For more info visit http://dougscripts.com/ *)
      
      on adding folder items to my_folder after receiving the_files
      	
      	global allRemPlaylists, remMachine
      	-- OPTIONAL: If you are adding to remote computer's iTunes Library
      	-- Change the remMachine to your remote machine's info:
      	set remMachine to "eppc://username:userpass@remote_ip.local"
      	(*
      where username is something like "doug",
      userpass is the password, 
      remote_ip is the IP address see in the remote
      machine's Sharing Pane, something
      like "192.168.2.1" or "your-remote-machine.local"
      Note: On some configurations an administrator username and password are needed.
      *)
      	
      	using terms from application "iTunes"
      		try
      			
      			-- OPTIONAL: If you are adding to remote computer's iTunes Library-
      			-- Edit the line below and delete the "--" before "of machine remMachine". It should read: tell application "iTunes" of machine remMachine
      			tell application "iTunes" --of machine remMachine
      				launch
      				
      				make new user playlist with properties {name:"AutoAdd"}
      				repeat with i from 1 to number of items in the_files
      					set this_file to (item i of the_files)
      					add this_file to playlist "AutoAdd"
      				end repeat
      				
      				(*
      				-- if you have iTunes set to 
      				--"Copy files to iTunes Music folder when adding to library"
      				-- then you might want to delete the original file...
      				-- if so, remove comments from this block and 
      				-- use the UNIX commands below to delete the file
      				
      				set the file_path to the quoted form of the POSIX path of this_file
      				do shell script ("rm -f " & file_path)
      				
      				*)
      				set userPlaylist to user playlist "AutoAdd"
      				set movieTracks to (tracks of userPlaylist)
      				repeat with movieTrack in movieTracks
      					set movieTrackName to name of movieTrack as string
      					set AppleScript's text item delimiters to "_"
      					set tokens to (every text item of movieTrackName) as list
      					
      					if the (count of items in tokens) > 1 then
      						set video kind of movieTrack to TV show
      						set season number of movieTrack to item 1 of tokens
      						set episode number of movieTrack to item 2 of tokens
      						set name of movieTrack to item 4 of tokens
      						set disc number of movieTrack to item 1 of tokens
      						set show of movieTrack to item 3 of tokens
      						set episode ID of movieTrack to ((item 1 of tokens as integer) * 100 + (item 2 of tokens)) as integer
      					end if
      					set comment of movieTrack to "original track name: " & movieTrackName
      				end repeat
      				delete user playlist "AutoAdd"
      			end tell
      		end try
      	end using terms from
      end adding folder items to
      
    2. Choose Script > Compile (CMD-K)


      Optional: If you are adding to are remote machine:
      • Change the "remMachine" variable: Insert the remote machines's username, password and IP address (eppc://username:userpass@remote_ip.local)
      • On the line: Tell application "iTunes", delete the "--" before "of machine remMachine" so it reads: tell application "iTunes" of machine remMachine.
      • Enable Remote Apple Events on the remote machine:
        • Open System Preferences and click Sharing.
        • Turn on Remote Apple Events by checking the checkbox.
        • Close the window to save your settings.

    3. Save the edited script as "Add to iTunes Auto-Tag.scpt".
    4. Move the script file to your Mac's main Folder Action Scripts folder (Macintosh HD/Library/Scripts/Folder Action Scripts/). Note: The script may not execute if located elsewhere on your system.



    Enabling Folder Actions

    1. Right-Click (Control+Click) on the folder you want to attach the folder action to (ex. ~/Movies).
    2. Scroll to the bottom of the pop-up and Select More > Enable Folder Actions

      [​IMG]

    3. Right-Click (Control+Click) on the folder again and Select More > Attach a Folder Action

      [​IMG]

    4. Navigate and Choose your "Add to iTunes Auto-Tag.scpt"

      [​IMG]

    5. The script should now execute whenever files are added to this folder.

      Note: If you keep your movie files and TV files in separate folders, you may want to repeat these steps on your other media folders.
     
  2. macrumors regular

    Joined:
    Apr 12, 2007
    #2
    I am having trouble getting this part of the tutorial to work. The rest works beautifully and I have now ripped almost half my DVD collection and the mac mini is slowly chugging along trying to encode them to mp4s.

    However even after following the Part 5 tutorial to the T, the files are not getting auto tagged or inserted into my itunes library. Any idea what I am dong wrong? Is there a setting I need to turn on somewhere for the script to work?

    My setup is as follows. Mac mini with all the media residing on an external 1 TB drive connected through firewire. All the files, DVDRips, Encoded files, scripts etc sit on the same external drive. Not sure what other info would help you to help me, but let me know and I'll post it up here.

    Thanks for looking.
     
  3. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #3
    Sorry you had some trouble, I feel your pain.

    I just tried it on my MacBook Air and had the same problem. I've found enabling Folder Actions to be a little flaky, even though it shows it's enabled and attached.

    In any case, I just got it to work by moving the script file to the Mac's main Folder Action Scripts folder (Macintosh HD/Library/Scripts/Folder Action Scripts/). Once there, follow the steps below.

    1. Right-Click (Control+Click) on the folder you want to attach the folder action to (ex. ~/Movies).
    2. Scroll to the bottom of the pop-up and Select More > Enable Folder Actions
    3. Right-Click (Control+Click) on the folder again and Select More > Attach a Folder Action
    4. Navigate and Choose your "Add to iTunes Auto-Tag.scpt"
    5. The script should now execute whenever files are added to this folder.

    Hope this helps!
     
  4. macrumors regular

    Joined:
    Apr 12, 2007
    #4
    Thanks!!!! You've just saved me over 6 months of work

    Thank you mac.jedi... that did the trick.. I've been putting off tagging and adding all the ripped tv shows and dvd's to my itunes collection for ages..

    Now in just 2 days, i've already added all 6 seasons of 24 and 3 seasons of prison break to my collection and the list is growing.. finally i can get it all in my itunes library...

    You sir, are pure genius!!!!!
     
  5. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #5
    I'm happy to hear of your success! Thanks for the kudos, but I can't take all the credit. I'm no genius, just determined. I scoured the internets for weeks trying to cobble this together. It took a lot of trial and error, but I sure learned a lot in the process.

    It's scary how easy it is to rip and encode once you've got it set up (especially if you've got an 8-Core Mac Pro with dual-DVD drives). I've been running this and streamlining it since last may and now have almost 5TB worth of encodes and TS files and I've still got about 100 DVDs to go!
     
  6. macrumors newbie

    Joined:
    Mar 31, 2008
    #6
    Hi - Dumb question, but on what folder do u enable this script on? Is it the batchencode folder that the handbrake cli outputs to or just some folder (ie /movies) that u manually move the movie files to after it's done?

    thx.
     
  7. macrumors member

    Joined:
    Oct 10, 2009
    #7
    Exactly is it 'movies' or is it 'batchencode? that you set the script to run on?

    Also, will this work with aliases (ex. i have my movies folder set to an alias on a server) or do I need to hard code the IP address of the server in the script?

    Thanks so much for your work on this!

    Update: This works on the movies directory
     
  8. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #8

Share This Page