Tag Archives: Apple

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

Scripting iTunes

Love it or hate it, iTunes is a massively popular piece of software, not because it’s fast, good looking or ultra-usuable, but because you need it if you’re one of the millions and millions of people that own an iPhone, iPad or iPod.

However, I was recently very pleasantly surprised when I found that iTunes has a COM interface that allows you to very easily script actions – such as bulk renaming your tracks, or bulk-editing track metadata

Although I’m a C# developer, one of the most convenient ways to access this functionality was actually JScript:

var iTunesApp = WScript.CreateObject("iTunes.Application");

I wrote a script to take some videos that were showing as “Movies” section in iTunes, and changed the metadata (“Media Kind”, “Episode Number” and “Season Number”)  and made them show up in the “TV Shows” section of iTunes.

Useful Links:

Leave a comment

Filed under Apple, Useful