Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mac.jedi

macrumors 6502
Original poster
Feb 1, 2008
355
3
The O.C.
RIP-o-Matic - (almost) Automated Ripping
or, How I almost went crazy trying to build a HandBrake workflow.

Like many, I've been searching the "inter-webs" for some automation tips that would help me reduce the amount of labor involved in creating a video library. All the ripping, encoding, tagging, etc … took up a lot of time and required a lot of getting up and down, (yeah, I've grown THAT lazy).

Unfortunately, most of what I found were others asking the same questions as I was, but not really getting any complete answers. I did however, find some great resources that (with a lot of patience and maybe some luck), finally turned into an (almost) automated ripping solution.

Now, I'm not a programmer, I'm a Creative Director. I've only used Macs and thought, PYTHON was a snake, PERL was something they take out of an oyster, and a SHELL was what was left after you ate the oyster. I'm not really that much of "newb", but what I was reading definitely made me feel like one.

It is my hope this post will help those who are looking to do something similar with their workflows and maybe make this rabbit hole a little less deep. I'd also look forward to hearing what others are doing and learn techniques that could help me fine-tune this process.



Overview:
I wanted a workflow that I could feed DVD's and RIP a bunch of Video TS folders to an "Encode" folder.

Then I wanted to be able to automatically scan that folder and encode each of the DVD's TITLES (-t) that were over a specified amount of time (20 minutes). This would give me the ability to not have to queue each episode of a TV show or really care if it's a movie or tv show.

I then wanted a way to automatically tag each episode or movie and finally import them into an iTunes located on a remote machine (local network).

And finally be able to spend time with my wife and enjoy the content on our AppleTV.

And now for a DISCLAIMER: I CANNOT GUARANTEE THAT THIS SETUP WILL WORK FOR ALL AND AS ALWAYS, USE CAUTION BEFORE ATTEMPTING TO DO ANYTHING LISTED BELOW. THOUGH THIS HAS WORKED FOR ME, I DON'T KNOW IF WILL WORK FOR YOU, OR CONTINUE TO WORK AS APPLICATIONS CHANGE. THIS WORKFLOW IS BASED AROUND MY PERSONAL HARDWARE AND NETWORK SETUP AND WILL REQUIRE CUSTOMIZATION FOR THIS TO WORK ON OTHER SYSTEMS. SO PLEASE BE WARNED.


Hardware Overview:

RIP Station
Mac Pro 8-Core 2.8 GHz running 10.5.2 with (4) 1 TB Seagate drives and 6GB of RAM.
(3) drives are software RAID-0 with 3 partitions: SpeedDisk, Boot Disk & Data. The other Seagate drive has 2 partitions, a Boot Disk clone and a Time Machine backup of the boot volume and SpeedDisk. I've also got a WD 2TB RAID-0 drive for cloning the Data drive. I'm a backup freak!

iTunes Computer
iMac Intel Core Duo 1.83 GHz running 10.5.2 with 2GB of RAM and two external 500GB LaCie drives (1 for the iTunes Library and other data, and the other is a clone of that drive). This computer is also backed up with 1TB Time Capsule via Time Machine.

AppleTV 2.0x


Software Overview:
Mac OS: 10.5.2 Leopard
iTunes v7.6.2
iCal v3.0.2
Mac the Ripper v3.0x (or other ripping software that creates TS Video files)
HandBrakeCLI v0.9.2
TextMate v1.5.7 (Free Trial, but I will definitely buy as it's the best text editor I've ever used.)
MetaX (Great little app, but requires a lot of user intervention. I use it primarily for adding artwork and descriptions, but need to investigate how to make this easier.)


Scripts Overview:

MediaForkCLI-batch.sh
http://www.realisticsoftware.com/pages/mediafork.html#MFbatch
This script is outdated and needs some finessing, but works great. This is the script that gets all the title info from a TS file and manages the encodes that HandBrakeCLI performs. It also allows me to define the minimum title length which is most important for batch encoding TV Shows.

batchScript.scpt
This AppleScript is triggered by an iCal Alarm to run the MediaForkCLI-batch.sh file with defined encoding parameters.

[my] Rename TVShow from File-droplet.app
This droplet is a script that gets the episode names from a text file. The season number and show name comes from the name of that file. The script parses that data and renames a series of m4v files, sequentially numbering each episode with the following file naming convention: Season#_Episode#_Show Name_Episode Title.m4v

[my] Add to iTunes Auto-tag Script-Final.scpt
This AppleScript parses the video files' filename, adds them to iTunes, and tells iTunes to set the Episode or Movie name, season#, episode#, episodeID, Video Kind and Show Name.



Setup and Installation
Again the following is based on my setup. What works for me, may not work for you and you'll probably want to do things differently. Be careful, if you don't know what you're doing, research and plan what you want to do and try to get answers from those familiar with the subjects before attempting any of these steps.

So, the first thing I'd do is download and install the applications listed above if they aren't already on your system. Don't worry about installing HandBrakeCLI yet as I'll discuss that later.

Mac the Ripper
Now, I have two SuperDrives in my Mac Pro. For $29 bucks (OtherWorldComputing.com) you can install a second drive and RIP two discs at once. To do this I make another copy of Mac the Ripper and call it Mac the Ripper2. Now I don't know if this is any faster, but it does cut user intervention in half and saves me from having to get up and feed the beast another disc. You may also want to change your System Preferences to automatically launch MTR when you insert a DVD. To do this go to System Preferences, CDs and DVDs, and under the "When you insert a video DVD", select "Open other application" and choose Mac the Ripper. MTR will automatically launch when you insert a DVD and start scanning the disc.

iTunes
Our iTunes Library is located on an external HD connected to our iMac, this is also the machine that syncs our iPods and AppleTV. For us it works best having a single iTunes Library that we make all our playlists, iTunes purchases and podcasts. All our audio and podcast content is located in this library. All the videos (except podcasts) are located on the Mac Pro.

Two things you'll probably want to do if you keep your content in different places is:
  1. Go to the iTunes Preferences "Advanced" tab and click OFF the checkbox "Copy files to iTunes Music folder when adding to library"
  2. If you have an AppleTV you might want turn off syncing for TV Shows and Movies.

Folder Setup
Back on the Mac Pro, I created three folders on my SpeedDisk partition: Encode, Process, and Scripts. I then created 4 folders on my Data partition: Movies, TV Shows, RIPs, and Episode Lists.

Install HandBrakeCLI
Open up the HandBrakeCLI disk image and launch Terminal. In order for the MediaForkCLI-batch.sh script to talk to HandBrakeCLI, I needed to copy HandBrakeCLI via the terminal to my /user/bin directory. I also needed to use the sudo command to copy the file. Unfortunately, I don't know enough about this stuff to figure out why it wouldn't install in my /usr/local/bin directory. In any case, I had to type the following into the terminal:

Code:
sudo cp /Volumes/HandBrake/HandBrakeCLI /usr/bin

Terminal will ask you to provide your password, hit return. HandBrake will then be copied to that location.

Setup MediaForkCLI-batch.sh
After downloading the MediaForkCLI-batch.sh file, move it to your desired location, mine was my SpeedDisk/Scripts folder. Open the file with TextMate, read the overview text to get familiar with the script and make the following edits to the text file:

1. Set the variables under the "# set the global variables to default" section:
Code:
toolName="HandBrakeCLI" # Changed to HandBrakeCLI from MediaForkCLI
toolPath="/usr/bin/$toolName" # Changed to /usr/bin/$toolName
toolTrackArgs="-t 0"
toolArgs="-2 -w 640"		# also of interest -v
inputSearchDir="/Volumes/SpeedDisk/Encode/" # Changed to the directory where my Video TS Rips are
outputDir="/Volumes/SpeedDisk/Process/" # Changed to the directory where I want my encodes to go
minTrackTime="20"			# this is in minutes, changed to a 20 minute minimum title length.

2. I don't know if this was necessary, but I then made the file executable by selecting the Bundles in the top menu (or in tools menu on the bottom of the window), then select Shell Script, then select Make Script Executable.

And that's it for that.

To execute the MediaForkCLI-batch script in Terminal, you just need to tell Terminal where the script is and what if any parameters you want to set for HandBrakeCLI. It's basically looks like this: Path/MediaForkCLI-batch.sh --preset="AppleTV" --minGetTime 50

Using the parameters above, it would then encode every Title in every TS Folder found in the location specified that's longer than 50 minutes using the AppleTV preset. For more info in setting parameters, visit http://handbrake.fr and read the CLI Guide.


Setup batchScript.scpt
This AppleScript is triggered by an iCal Alarm to run the MediaForkCLI-batch.sh file with defined encoding parameters. The script I use is very simple. FYI: I use the AppleTV preset, but add two-pass and turbo first pass. I didn't know you could tag parameters onto a preset, but it seems to work.

Type the following into TextMate or Script Editor.

Code:
set batchScript to "/Volumes/SpeedDisk/Scripts/MediaForkCLI-batch.sh " & "--preset=\"AppleTV\"" & " -2" & " -T"
	
	do shell script batchScript


Now to make this work you'll need to do a couple of things:

1. Modify the path to your MediaForkCLI-batch.sh file and set the parameters you'd like to have.
2. Keep in mind you need to leave spaces between the parameters and put any presets in quotes. Also, AppleScript needs a \ before a quote you want listed as text in order for it to compile. Check out http://macscripter.net for help in writing AppleScript.


Setup iCal
Create an event (I named mine Batch Encode) and set the start time and end time. I've found that the end time needed to be at least a minute after the start time to avoid an error message that said the script failed (even though it didn't) but it was annoying nonetheless. Next, set the alarm to "Run Script" and set the notification to 0 minutes before. Under "Run Script", navigate and select the batchScript.scpt file. Set the repeat interval to everyday or the interval at which you'd like iCal to run the script. I set mine for everyday at 12AM.


[my] Rename TVShow from File-droplet.app
This droplet is a script that gets data from a text file and renames a series of m4v files in order with the following file naming convention: Season#_Episode#(sequential)_Show Name_Episode Title.ext

To quickly rename and have iTunes tag your episodes, you need to create a text file for each season you've encoded and want to rename:

Basically all I do is copy and paste an entire season of episode names into a txt file (one on each paragraph line) like the example below:

name 1
name 2
name 3

Save and name this text file with the show name and season number (season three as shown in the following example): Show Name_03.txt

To edit this script, you'll need to change the default location to the location of your episode list folder and save this file as an application using Script Editor.

Code:
on open dropped_items
	
	set textInfo to choose file default location alias "Data:Episode Lists:" with prompt "Choose file which contains the title list" without invisibles
	set titleList to paragraphs of (read textInfo)
	tell application "Finder" to set {name:txNm, name extension:txEx} to info for textInfo
	set AppleScript's text item delimiters to "_"
	
	set txNm to text 1 thru ((count txNm) - (count txEx) - 1) of txNm
	set showInfo to every text item of txNm
	set txEx to "." & txEx
	set AppleScript's text item delimiters to ""
	set idx to 1
	
	repeat with i from 1 to count dropped_items
		set {name:Nm, name extension:Ex} to info for (item i of dropped_items) as alias
		if Ex is missing value then set Ex to ""
		if Ex is not "" then
			set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
			set Ex to "." & Ex
		end if
		tell application "Finder" to set name of item i of dropped_items to item 2 of showInfo & "_" & text -2 thru -1 of ("00" & (idx as string)) & "_" & item 1 of showInfo & "_" & item i of titleList & Ex
		set idx to idx + 1
	end repeat
end open
----------------------------------------------------

[my] Add to iTunes Auto-tag Script-Final.scpt
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 the TV Show and Movies Folders. The script is executed whenever new files are added to these folders.

In order for this to execute on a remote machine, you'll need to enable "Remote Apple Events" in the Sharing Preference Pane on the remote machine. If your setup is all on one machine you can easily edit this script by removing the remMachine variables and and just use "tell application "iTunes"". For more info visit http://dougscripts.com/

Code:
on adding folder items to my_folder after receiving the_files

	global allRemPlaylists, remMachine
	-- change this to your info:
	set remMachine to "eppc://username:userpass@your-computer.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"
*)
	
	using terms from application "iTunes"
		try
			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 name of movieTrack to movieFile
						set video kind of movieTrack to movie
						
					end if*)
					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



The A-Team Ending
"I love it when a plan comes together"

So, if you're still with me, I know you are committed. Once everything is in order, this is how the process works.

1. Get a bunch of DVD's.
2A. Insert a DVD and launch MTR (or it auto-launched if you changed your system preferences)
2B. With two SuperDrives things are a little complicated. If you are running two instances of MTR they both try to read the same disk at the same time. To get around this, insert the second DVD, wait for it to mount and let MTR scan it. Then launch your second instance of MTR (MTR2 - your duplicate copy) it will now be able scan the disc. Change the drive selection on either instance of Mac the Ripper so they are each pointed to a different disc. Hit the "Go" button on and then the other choosing your Encode folder as the destination (they will remember that location for the next rip).
3. When completed, keep feeding the beast more disks.
4. If you've configured an iCal event the MediaForkCLI-batch script will run at a specified time and if you're like me and want this to take place while you're asleep, you'll wake up to a bunch of fresh encodes.
5A. If this is a movie, I rename the file how I'd like the name to appear in iTunes.
5B. If this is a TV show season, make sure all the episodes are present. I go to tv.com or other site and copy and paste the episode names into a text file (just the episode names) and name the file as described above. Now, I drag all the episode m4v files onto the [my] Rename TVShow from File-droplet.app and it will prompt you to choose the correct text file for that season. The script will automatically rename each episode.
6. Use MetaX to add artwork or comments, but you can do that after it in iTunes as well.
7. Drag the completed files to the hard drive where you want the final videos stored. Then if you've enabled the add to itunes folder action when you add the files to their designated folders (movies or tv shows) they will automatically add to iTunes and tag the appropriate content.

Well, that's about it. I know there is more to fine tune this process, but it's taken quite a lot to get this far. Good luck! I hope you have an easier time trying to get this going than I did.

I'll keep an eye on this post for a while, so if you have any questions, I'll do my best to answer them.

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.