Scripting iTunes – Turning Films into TV shows

A while back, I posted about using the iTunes API for automating tasks in my music & video collection.

However, I didn’t go into a lot of detail, and so  now I thought I’d share a bit more – in particular how to automatically organise videos into the “TV shows” section in iTunes.

Previously I had tried to drag my freshly downloaded/ripped videos into the “TV Shows” area, but they always ended up in “Films” – and the only videos in my TV shows section were ones that I actually bought off the iTunes store.

A quick bit of googling, and lots of experimentation later – I wrote a fairly simple jscript:

var iTunesApp = WScript.CreateObject("iTunes.Application");
var tracks = iTunesApp.SelectedTracks;
var numTracks = tracks.Count;
for (i = 1; i <= numTracks; i++)
  var currTrack = tracks.Item(i);
  var name = currTrack.Name
  var se= name.substring(name.lastIndexOf(".")+1);
  var show = name.substring(0,name.lastIndexOf("."));
  var bits = se.substring(1).toUpperCase().split("E");
  var season = bits[0];
  var episode = bits[1];

  currTrack.Show = show;
  currTrack.SeasonNumber = season;
  currTrack.EpisodeNumber = episode;
  currTrack.Album = show;
  currTrack.Artist = show;
  currTrack.TrackNumber = episode;
for (i = numTracks; i >= 1; i--)
  var currTrack = tracks.Item(i);
  urrTrack.VideoKind = 3;

The script splits the filename up into show name, season number and episode number, and then sets the “VideoKind” to 3, which means TV Show.

The only requirement is that the starting filename should be in the format Show.Name.S01E01.mp4



Leave a comment

Filed under Apple, Useful

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s