Setting iTunes metadata for downloaded TV shows

Below is a small piece of thoroughly untested AppleScript (well, it worked for me at least once) that will process files you might have downloaded from a torrent and attempt to parse out show, season and episode information from the file name.Below is a small piece of thoroughly untested AppleScript (well, it worked for me at least once) that will process files you might have downloaded from a torrent and attempt to parse out show, season and episode information from the file name. This relies on files being named in a regular way, but that’s been the case for everything I’ve downloaded recently.

Not that you’d illegally download torrents of course. Not if the major content producers weren’t such jackasses anyway.

My workflow for this is something like:

  1. find and download shows with Xtorrent

  2. convert to iTunes with Movie2iTunes (I’d love to know if there is a better way)

  3. go to the “Recently Added” smart playlist in iTunes and select all the newly-downloaded shows

  4. run this script

  5. grab your FrontRow remote and enjoy!

Opps, I left out “profit”! Feel free to send me stuff.

Here’s the script:

set AppleScript's text item delimiters to "."

tell application "iTunes"
    repeat with sel in selection
        
        -- try work out show, season and episode from file name (e.g. Californication.S01E04.HDTV.XViD-Caph.avi)
        
        set tokens to text items of (name of sel as text)
        
        set myShow to item 1 of tokens
        set myEpisodeId to item 2 of tokens
        set mySeason to text 2 through 3 of myEpisodeId as number
        set myEpisode to text 5 through 6 of myEpisodeId as number
        --display dialog myShow & " season " & mySeason & " episode " & myEpisode
        
        tell sel
            set video kind to TV show
            set album to myShow
            set year to "2007"
            set genre to "Drama"
            set show to myShow
            set season number to mySeason
            set episode number to myEpisode
            set episode ID to myEpisodeId
        end tell
        
    end repeat
end tell

I'm in America

I’m visiting family in the USA for Christmas. You can keep up with what we’re doing (well, at least photos) on my family blog.

I’ll be resuming my regular cracking pace of blogging in the new year… :-)

Adding captions in Aperture

I’ve just started using Apple’s Aperture to manage my photos (family and other), and I’m pretty pleased with it so far. One thing, however, that is harder than it needs to be is entering captions. As far as I can tell, the only way to do this in Aperture is to click on the photo in the browser, mouse over to the Information panel and click in the caption field (making sure you’ve selected IPTC fields to be displayed), type the caption and mouse back and click in the browser window so it has focus (otherwise any further keys you press will still be typing in the caption field). Then click on the next photo. Eeew.

This is bearable for one or two photos, but when you have a largish batch to do, it is very tedious. It’s also prone to error, such as when you start typing the caption without the field having focus, and Aperture gleefully trying to act on all your keypresses.

So I threw together a small AppleScript that provides a marginally friendlier interface. This is one of my first attempts at AppleScript, so I’d be happy to receive any feedback on better techniques.

Captions in Aperture

Here is a small AppleScript that provides a marginally friendlier interface for entering captions in Aperture than the built in method.

It presents a small dialogue box for each selected photo and allows you to enter a caption. Pressing RETURN or clicking “Ok” saves the caption and takes you to the next selected photo. Pressing ESC or clicking “Skip” leaves the current caption as it is, and moves to the next photo. You can click “Cancel” to stop the script.

I use it by adding a trigger to QuickSilver that binds a hot key (I picked Control-Apple-C, which remarkably seems to be unused by Aperture–it already binds most conceivable key combinations, and even a few no-one has thought of yet) to the script, which can be saved anywhere you like. QS can limit the scope of the binding to a single app, which helps prevent conflicts in other applications.

I’m no AppleScript expert, so I’d be happy to receive any feedback on better techniques. It doesn’t seem like it’s possible in script, but it would also be cool to be able to display a thumbnail in the dialog–just having the name is not necessarily all that helpful.

The source of the script is available in my subversion repository.

And in other news...

I just got a new can of deodorant, and it says “shake well before use”. I figure the night before should be long enough. :-D

The finer points of maintaining a firewall

Last Saturday, I learnt something. (Not that this is an unusual occurrence, of course.) I was trying to upgrade my Ubuntu box to “edgy eft”, and was having trouble downloading packages. It turned out that my ADSL had gone down. And up. And down. sigh So, after a few reboot cycles of the modem and my firewall, I was back up again.

The upgrade completed without too much pain (nice one, Debian and Ubuntu), so I turned my attention to some web site work I needed to do. Only could get through to my web server. Or mail server. Great, I thought, I just get my ’net connection back up and my hosting service goes down. Good excuse to watch the Grand Final, if nothing else. :)

Several hours later, football over for another year and my servers still not accessible, I thought I’d better look into it a bit more closely. My hosting service provides ssh access to the Xen console of my machines, so I tried that. And it worked. And what I saw was many kernel messages about packets from a “bogon” IP address being blocked. And the IP in question resolved to an iinet.net.au (my ADSL provider) domain name. Hmm.

After a bit of investigation, it turned out that with the outage in the morning, my ADSL IP had changed from a 203.214.. network to 124.168... And this netblock has until relatively recently been “reserved” by IANA. As it happens, Shorewall keeps a static list of “bogon” (i.e not normally seen on the public Internet) IP addresses in a configuration file, and this list included the rather sweeping netblock of 96.0.0.0/3, which results in everything from 96/8 up to 126/8 being blocked. But at the start of this year, IANA released the class As from 121/8 to 126/8 to APNIC, who gave them mostly to large Australian ISPs as far as I can tell, and evidently some those (like iiNet) are starting to roll them out to customers.

Anyway, a quick poke around with Google turned up this updated bogons file, so I installed that and restarted my firewall, and everything was fine again. It all goes to show, nothing is simple in the world of internetworking.

A nice touch

When I tried to send an email on my new iiNet last night, I discovered that outgoing port 25 was blocked. This is quite common with ISPs, since it tends to prevent a good deal of spam and other malware activity. But it’s a nuisance for me, since I like to send mail via my own mail server.

But, unlike many other ISPs (not looking at anyone cough bigpond in particular), iiNet let you turn off the blocking if you know what you’re doing.

Nice touch.

An inline "read more" link

Summary pages in Drupal, such as this one, display “teasers” of the nodes (pages or blog entries) if the entry is longer than a certain (configurable) length. If the entry is trimmed this way, Drupal helpfully displays a “read more” link below the teaser. This is ok, but it can be easy to miss if you are just looking at the text of the article, and mentally “tuning out” the noise of the links below.

So I modified my theme’s node.tpl.php (part of the now-default PHPTemplate engine) to hack in a “more” link at the end of the last paragraph:

--- node.tpl.php        (revision 43)
+++ node.tpl.php        (working copy)
@@ -9,6 +9,11 @@
            <span class="taxonomy">[<?php print $terms?>]</span>
          <?php }; ?>
        <?php }; ?>
+    <?php if ($readmore) {
+        // insert a link before the closing P tag if there's more to read
+       $read_more = ' <span class="readmore">...<a href="' . $node_url . '">more</a>...</span>';
+       $content = preg_replace('/<\/p>$/', $read_more . '$1', $content); 
+    }; ?>
     <div class="content"><?php print $content?></div>
     <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
   </div>

This requires a variable, $readmore, to be set in template.php:

function _phptemplate_variables($hook, $vars) {
	switch ($hook) {
	case 'node':
		$vars['readmore'] = ($vars['node']->teaser && $vars['node']->readmore);
		break;
	}
	return $vars;
}

(and some styling in style.css, but you can figure this out for yourself ;) )

And now I have discrete little “…more…” links at the end of the last paragraph of trimmed article summaries.

I kind of feel like this should have been possible by simply adding the link after $content rather than stuffing something into it with a regex, and causing it to be displayed inline with CSS, but my CSSfu is not strong enough. Suggestions welcome…

Back on the air

After a frustrating weekend of ADSL outages a couple of weeks ago, thanks either to my ISP or, more likely, their upstream provider (the Australian Monopoly Telco Who Shall Not Be Named), I started hunting around for a new ISP. Just on a whim, I checked my exchange on the ADSL2+ roll-out status page at iiNet. And lo! It’s available!

So I signed up for their standard plan, which gives me “up to” 24Mbps and 10GB download per month (plus another 10GB off peak). Given that I haven’t had to try too hard to keep within my current 5GB (+5GB) plan, and iiNet’s 10+10 is $20/mo less, it seemed like a good place to start. I also get their local phone service (bundled with ADSL2+) and VoIP, which should be interesting.

The downside of upgrading from ADSL to ADLS2+ is that there’s no “fast churn”. In other words, I had to disconnect my current service and then wait for the new one to be provisioned. But now it’s active! (And only three business days later, which is better than I expected.)

I don’t have the new ADSL2+ modem yet, but even with my current modem (a Netcomm NB1300) I’ve seen download speeds of about 380KBps (that’s bytes there sonny), which is fairly impressive. Uploads are going at about 60-80KBps, which is a lot better than the old 24KBps. My line attentuation is hovering around the 50dB mark according to the NB1300, which I’m led to believe means I probably won’t get much more than 10Mbps anyway, but we’ll see how it goes when the new modem arrives.

It’s amazing how long five days felt without ’net connectivity, though… :-D

Giving up on blosxom

I’m giving up on blosxom. Not that there’s anything wrong with it, but the advantages of keeping my blog in Drupal are too great to ignore.

I liked the idea of blosxom, and I love having a local copy of my blog in plain text (and being able to manage it in subversion), but the hassle of maintaining another bunch of HTML/CSS, and the extra work involved in adding functionality like comments, is just not worth it.

So, look over here for future (frequent?) posts. :) I’ll get around to bringing the blosxom content across and putting in redirects soon.