
So your files have been automatically encoded into h.264, and dropped into a sorting folder. From there they have been automatically renamed into a standard filename. Sweet! So what's next?
Step 4: Tag files with metadata & add artwork
This step draws on the great work done by true Mac media genius who goes by mac.jedi over at the Macrumors forums. He has a wonderful How-to on Automating DVD backup (How-To: Automating DVD & Blu-Ray (Backup, Encoding & Tagging) for Mac OS X 10.6), but what he has also kindly written are a series of scripts for tagging media automatically with metadata.
I won't rip off his work by directly hotlinking to his packaged scripts, but if you go to his thread, you'll see the following:

Grab the .dmg file - it's about 15.4mb in total. This will be the base by which we can start automatically tagging these files with metadata.

Run the included installer. This installer with add a bunch of new workflow files and Services that we can start to tap into.

These are the two key Services that we can use. Now, the important part to know about these is that they are based on filename. If you have a standard filename (like we do!), then these two scripts can successfully search for your files on both thetvdb.com, or themoviedb.org, depending on whether they are movies or TV shows. If they can find them there, then they will automatically scrape all the metadata details of the show/movie, and apply it to your file!
For those keeping score, you're probably thinking, "Ah-hah! This is why Part 2 is so gosh-darned important!"
Well played, dear reader. Oh, I feel like I know you so well now, after all we've gone through. Could we be friends, in different circumstances? I'd like to think so.
I command you, rise and be tagged
So let's revisit our Hazel rules:

The highlighted rule down the bottom is going to be doing the heavy lifting for us. Let's take a look.
Rule: Attempt TV Tag for Downloads

Let's break down this rule bit by bit. So if a file...
- has a name that matches the naming scheme we have set [Show] - S[Season]E[Episode]
- has an extension of .m4v
- has a musical genre of 'blank' (this is one of the most reliable ways to tell if a file has been tagged before or not)
- does not have the Spotlight comment 'Tagging Complete' (again, checking to make sure the rule has not tried tagging this file before)
- does not have the colour label of Blue
...then it is ready to be tagged! But wait, those beautiful Services you installed before, where did they go? They all live in your User Library/Services folder, located here:

We do need to make one customisation to the Batch Rip • Add TV Tags.workflow file in here, so double-click it and it will open in Automator.

We want to check the box that says, "Replace original file". This means that the old non-tagged file will be overwritten by the workflow, not just duplicated.

Save this change to the workflow, and close Automator.
This is a sidenote, but I will quickly mention that because these Automator workflows are all Services, you can actually trigger them at any time for any file, just by right clicking on it.

Services in action - isn't it cool?
OK, so continue to set up your rule so that if your file meets your exacting criteria it will trigger the workflow in your Services folder called Batch Rip • Add TV Tags.workflow.

You also want to add that 2nd 'Add comment' rule to replace the pre-existing Spotlight comment. That just lets you know which files are done with tagging, and which aren't.
Now, if all goes well, you should see your sample file automatically trigger the rule you just made. It will look like this while it is working:

Oooh, pretty. That means that the script was successful in finding your show on thetvdb.org, and is now writing a 2nd temporary copy with all the metadata tags embedded into it. Once it is done, it will delete the original untagged copy. An easy way to see the difference between a tagged copy and an untagged copy is the icon used in the Finder. Here's a heads-up comparison:

The finder is smart enough to recognise the tagged file has album artwork now, and uses that for the file icon instead of the random video screengrab of the 2nd.
So, at the end of all this, you should now have a freshly-minted copy of your video file with all that sexy metadata included:

Rule: Mark as Tagged

This rule ensures that any file you have successfully tagged ends up with the blue colour label. Because your previous rule actually ends up creating a brand new copy of the file, you need to now examine that new copy and apply the label.
So if a file...
- has a Spotlight comment of 'Tagging Complete'
- has a filename without the word '-temp-' in it. The dashes are necessary because otherwise it might pick up a show like oh, say Temptation Island, or The Knights Templar. As an avid Temptation Island fan, I found this out right away. Just kidding, nobody watches that show.
Actually, I'm pretty sure if you simultaneously like Temptation Island and own a Mac, Scott Forstall is obligated to break into your house and beat you to death with a iPod Hi-fi.

He'll do it, the dude has crazy eyes. Wait, where were we? Oh yeah...
If your file...
- does not have the colour label of blue
- has a musical genre that is not blank
...then it's definitely been tagged by your process. So we will set its colour label to blue. Now our sorting rule (up next) will know what can be sorted.

Step 5: Sort to folders & Add to iTunes library
Home stretch! So now we've validated that our file has been tagged, our file should look like this:

The final step in our process is to sort it to a logical series of folders, and add it to iTunes. Back in Part 1, I talked about sorting into a folder hierarchy of show & season. It looked like this:

How do we accomplish this automatically? Can you do it, Hazel? Oh hell yes you can. Incoming rule!

Rule: Sort to TV Show folder
Let's take a look at this bad boy in detail:

So if a file...
- has a name that matches the [Show] - S[Season]E[Episode] custom token naming scheme (for more info on this, see Part 2 of this series). This part is really important, because Hazel needs to know the seperate components of this filename again (like Show, Season, Episode), so we can use them below for sorting.
- has a colour label of blue
...then do the following:
- Move the file to your TV Shows folder
- Sort the file into a subfolder
This is where the magic of custom tokens help us out yet again. We can firstly define that the file is sorted into a Show subfolder. Secondly, we can use the little arrow token, to further sort this file into a Season subfolder as well.
Again, Hazel is cropping out my full pattern here, but it looks like this. The stuff in square brackets are all tokens, which you can drag and drop into the pattern area.
[Show][>]Season [Season]
So if your filename is:
Arrested Development - S01E01.m4v
The custom tokens will recognise:
- The show name is Arrested Development
- The Season is 01
One change we need to make to our custom token is to to have Hazel recognise only 1 digit of this Season number. Otherwise, Hazel will create a folder of Season 01, not Season 1. Picky I know, but hey, we've come this far, right? Let's blow this freakin' tutorial right out and go the whole damn hog.
Click on the arrow drop-down on the token, and you get the option to modify it:

Hell yeah boyee. This will now sort this file into a folder hierarchy of:
TV Shows > Arrested Development > Season 1
Even better, if the subfolders don't exist, then they will be created by Hazel.
Before I dig into importing into iTunes, I have to warn you about turning off a setting in iTunes. Head to iTunes > Preferences > Advanced and you'll see this:

If you don't uncheck the box beside Copy files to iTunes Media folder when adding to library, then iTunes will take it upon itself to sort your files. In principle this would be OK, but the naming scheme iTunes uses is woeful, and it means files are very difficult to identify later. So switch it off. This has other implications, though, so be mindful of your current iTunes setup, and how you currently add music to iTunes. Besides, if you followed my 'Automatically Add to iTunes' trick in Part 1, it's already taken care of.
Now you've done that, the import component of this rule is to import into iTunes is really simple.
You have the option to also add the file to a playlist when you import it. I highly recommend this because you can just check the playlist to confirm that stuff is being successfully imported.
Finally, just to be neat, here's an action that removes the colour label we used.
Now the file we've been playing with looks like this:

It's been completely automatically encoded, renamed, tagged, sorted and imported. It looks like this in iTunes:

Isn't life grand?
Summing Up
This set of steps will let you not only convert new material, but also pre-existing stuff. Simply drop files into your Complete folder and let Hazel do all the work for you. As an added bonus, this kind of set up also plays nice with XBMC-based media centre setups, like Plex and Boxee, because the folder names, folder hierarchy and file-naming scheme we have used are totally compatible with how they find metadata -- mainly through file-naming consistency.
If you'd like to ask me any questions about this setup, my Twitter account is @jamescroft. Hit me up there. Thanks for reading!







Organising media with Hazel, Pt 3