How do I programmatically rename movie and TV show files in iTunes library for XBMC compatibility?

I have a collection of movies and TV shows in iTunes and I would like to rename them to an XBMC compatible naming convention without breaking links in iTunes.

All the necessary metadata (season number, display name, episode number, etc.) seems to be in the XML file that iTunes manages, and the episode name is the current filename. So, programmatically renaming files seems pretty simple, but how do you keep your iTunes library right at the same time? Is it enough to rewrite the XML file to point to the new filenames?

I'd rather not get into applescript if I can avoid it (life is too short), but if it's easier to do, I can look at it. Otherwise, I would ideally like to do it in ruby.

+1


source to share


6 answers


On Windows, Apple provides an iTunes COM for Windows SDK that works reasonably well. It is built using a COM interface, so it works with almost all languages ​​available for Windows. It provides methods for renaming tracks and playlists. I used this to do everything with my library.

I don't know what's available on MAC, but I think AppleScript is the best way to access what's available. There is a project called "EyeTunes" that provides the Cocoa framework. There is a site dedicated to Applescript ( "Doug AppleScripts for iTunes" ). Here is a site showing how to access iTunes from perl .



If you want to rename both the file and the iTunes name, then it's probably best to change the track title, remove the file from the library, rename the file, and then add the track again. You will need to save information like last played, playcount, etc.

+2


source


Not sure if you are on a Windows box, but honestly, if you can write even a small Javascript iTunes COM API , it is very easy to use.

Below is an example of how it will look. (this is NOT tested, so use it as a reference only.)



var    ITTrackKindFile  = 1;
var iTunesApp = WScript.CreateObject("iTunes.Application");
var deletedTracks = 0;
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;
var    RenameTarget;

while (i > 0)
{
    var currTrack = tracks.Item(numTracks);

    // is this a file track?
    if (currTrack.Kind == ITTrackKindFile)
    {
            RenameTarget = "Stuff from other properties"
        currTrack.Name = RenameTarget; //
    }
    numTracks++;
}

      

Good luck.

+2


source


Late, but I need exactly the same for Plex on OS X.

My solution was to write a Python script that asks iTunes for its TV shows via the AppleScript bridge, gets the file path from each track location attribute, and then creates a symbolic link to the original file using iTunes metadata to give the bind a name suitable for Plex / XBMC etc.

The advantage is that you can painlessly create multiple sets of links with different naming schemes, for example. My name is Earl S01E10.m4v or my name is Earl 01x10 White Lie Christmas.m4v

The core script is (where track

is the link provided by the appcript bridge):

def trackInfo(track):
"""returns tuple (filename, filepath, show)

track is iTunes playlist track from appscript bridge,

filename is of format "Showname 01x02 Episode Name.avi" where 
01 is the season number, 02 the episode number and the extension
will match that of filepath.

filepath is the UNIX path to the original file.
"""
try:
    path = track.location().path
except CommandError:
    return None, None, None
ext = os.path.splitext(path)[1]
name = "%s %02dx%02d %s%s" % (track.show(), track.season_number(), 
                                track.episode_number(), track.name(), ext)
return name, path, track.show()

      

+2


source


I am using ident2 on mac to rename my shows - works great!

+1


source


Check out EpNamer at http://www.epnamer.com/ . It requires .NET, but exactly what you are looking for and XBMC is what I use too.

You can also look into Media Companion as you are most likely using XBMC library functions, which you can read about here:

http://xbmc.org/forum/showthread.php?p=217769

It will make .nfo and .tbn files for every movie and TV show you have, which XBMC will scratch before going online for information.

Enjoy!

0


source


Another way to play iTunes xml file is using plist .

0


source







All Articles