
(Even taking this screenshot was grating.)
I am a big fan of the way iTunes handles media. Lots of people hate it; and I can understand that. Above all else iTunes wants, needs,*insists on nice, orderly content. For people whose media collection is a bit haphazard, iTunes is a awash with grey music note boxes, and 'Unknown Artists' categories. It makes it hell to find what you want.
In counterpoint though - and the other thing that iTunes does well; *it rewards the*diligent. Album artwork is gorgeous, TV shows can be sorted by season, music can be sorted by year & genre. It's amazing!
If there's one thing I want to be able to do with my media collection (other than watch it), is use it smartly. I want to be able to able to make a smart playlist that will load TV episodes on and off my iPhone & iPad as I watch them. It want it all in one place, in one format. I want to be able to search. I want to be able to flip through TV show covers. I want iTunes to be able to tell me, "Hey buddy, you haven't watched the Sopranos for a while..." and have it be right!
For those of you who have thought about this before, but given up because of the logistics*involved*getting this all done, I tell you -- it can be done. This is how.
(Note: I used to convert TV shows to m4v, and then manually enter metadata about each show with*MetaX. It was exact, but man, it took forever. I was wasting my life copying and pasting plot summaries from tv.com!)
The Grand Plan
So to get a good idea of where this tutorial is going, here's what I want to be able to do, all automatically. No user interaction needed at any step.
Step 1: Receive Incoming Downloaded Video Files
Step 2: Encode Video files into iTunes-friendly format
Step 3: Rename Files
Step 4: Tag files with metadata & add artwork
Step 5: Sort to folders & Add to iTunes library
Here's what I want the final outcome to look like:

...and here's what it looks like from a file-management perspective.

I have an external drive, which has a folder called*TV Shows on it. Within*TV Shows, there are*show sub-folders for shows (in this case*Arrested Development). Within a show folder, there are sub-folders for each season (Season 1, Season 2 etc) and finally within those, the shows themselves. The shows are all encoded in h.264, and each episode is named with the format:
[Show Name] - S[Season Number]E[Episode Number].m4v
This is an important point which I will elaborate on later, but this kind of file/folder setup plays really well with XBMC-based media centre front-ends, like*Plex or*Boxee.
Software needed: Hazel - US$21.95

One of my favourite tools on the Mac for organising media is a system preferences pane called*Hazel. What does Hazel do? In its own words:
Hazel watches whatever folders you tell it to, automatically organizing your files according to the rules you create....Automatically put your music in your Music folder, movies in Movies. Keep your downloads off the desktop and put them where they are supposed to be.
Sounds tame, but this is an insanely powerful tool. Once a file is dropped into the 'watch' folder/s of Hazel, it acts on the file according to a set of rules. Think of it like a folder action, but much more complex and customisable. Once you've installed Hazel, you will find it in System Preferences.
Step 1: Receive Incoming Downloaded Video Files
This is the first set of rules I set up to handle incoming files. Point Hazel at your downloads folder. Mine is called Complete. If you are awesome and you're using Transmission, you can actually set up a*separate*folder where completed downloads are moved to. This works really well with Hazel, because it never confuses completed files with incomplete files. We're going to set up a series of rules for this folder to follow.

Let's break these three rules down.
Rule 1 -*Run on sub-folders

Think of this rule as the folder inspector. It breaks down folders, examining the contents of any sub-folder that is within your download folder. All of the rest of the rules can then be run against any itens buried in folders. So if your download folder looks like this:

It will examine each one of those sub-folders, and extract the video files from each.
It also only runs once on every folder, so that it doesn't bog down your system constantly re-examining folders that have already been actioned. I also added an action to change any folder acted upon turn blue - just as an easy visual cue to see folders that are done. I suppose you could say, I just blue myself.
Note: It's very important that this is the top rule. It actions against all the rules below, so it has to go highest in the order within Hazel.
Rule 2 -*Move Music to iTunes

This is unrelated to video files, but this rule finds any mp3 file in your downloads folder, and moves it to a folder called 'Automatically Add to iTunes' - you can find that folder in your iTunes Music folder.

This folder is kind of a hidden secret that appeared in iTunes 9. Any mp3 file that is added to it is automatically sorted in iTunes. Awesome!
Rule 3 - Convert avi to m4v

This rule is designed to trigger an Automator workflow for any .avi file in your folder that will create an iTunes-friendly copy of the video, which leads nicely into...
Step 2: Encode Video files into iTunes-friendly format
Before we get into that though, we need to go back to our folder structure for a second...

Create a folder called*Encoded. This is*where you should specify for your files to be saved to in your Automator workflow.
Now before you're done, you need to create the Automator workflow first. Open up Automator.
Here's a screenshot of the workflow you need to create.

(click to enlarge)
For more information on creating this workflow, have a squiz at Matt's excellent article on*Getting Your Feet Wet With Automator. It has all the basics for putting together a simple workflow like this, and it's a great read.
This workflow basically exports a copy of the avi file into Apple TV format, and saves it in the*Encoded folder. It also gives it a Spotlight comment, so we know it's been encoded from our workflow. Just a heads-up, you will also need a copy of Perian installed so that Automator can do this sucessfully with .avi files.
Getting back to our rules...

Once you've created this Automator workflow, save it, and then link to it in your Hazel rule.
The final bit of this rule is trashing the original avi file. I do this for space reasons, but I know lots of people keep both versions, so it's not entirely necessary.
So now, every time you get a completed .avi file in this folder, it will detect it, and trigger an action to automatically create an iTunes friendly copy of it.
Summing up
This is the first step in a set of tutorials on sorting media automatically with Hazel. At the end of this tutorial you should be able to drop completed incoming files into a dowloads folder, and have all video files automatically encoded into AppleTV format.

Stay tuned for Part 2 tomorrow!







Organising media with Hazel - Part 1