I found a page a while back that had a perl script that imports your iTunes playlists into MythTV’s MythMusic. The MythMusic playlist editor isn’t a pleasure to deal with, plus if you already have all of your playlists set up the way you want them in iTunes, why not just synchronize your hard dragging and dropping? So the script on this page didn’t work at all for me, so it was time to hit the drawing board.

My setup goes like this: I have my iTunes Music folder on a portable terabyte drive which I periodically rsync using cgywin…

rsync -av –delete /cygdrive/f/iTunes Music/

Since iTunes renames files when you rename songs in their tags when you have that setting enabled, I leave it on and make sure I delete when I do the rsync, so that any files moved locally are just re-synced remotely.

Once the files are all there, in the same directories they exist in locally, I just rsync the iTunes Music Libary.xml file so that I can mine it for my playlists.

rsync -av –delete
/cygdrive/f/iTunes Music Library.xml

Then periodically, you just have to scan for new music in the MythMusic settings interface and then run the PHP script.

It goes through the iTunes XML and gets all the information it needs (probably not the most efficient method, but whatever, RAM’s cheap) and then builds or re-builds the playlists in MythMusic.

The whole process takes a little while to complete and it will echo out all of the files it couldn’t figure out how to make work, but overall for my collection of 18855 it successfully maps 17982 of them, so it’s only missing my m4a files and some Bj√∂rk.

Easy Installation Instructions

# cd /usr/src
# svn co

Username is guest, password is blank

The resulting script can also be tossed into a cron job to be done automagically.

If you have any patches to improve the script they’re quite welcome and I’ll update the post, send them to mythmusic at weezey dot com.

Update 2009-04-21: I finally had a chance to commit the changes that James L sent me. The script runs a whole lot faster now and complains about life a whole lot less.

Pepper - 2009-05-25 19:48:17
So I seem to be running into a case sensitivity problem with m library. Anyone know of a good way to either recursively rename everything to lowercase or make the script insensitive? My php is just a little rusty at the moment
Ian - 2009-04-22 02:18:00
Jeff, if you follow up, try the new version, fixes a lot of that.

Tim, too much could be up, maybe try a PHP support channel on IRC.
Tim - 2009-03-30 02:05:00
I'm trying to run this script. It get no output when I run it from the command line.I was able to get a standard "hello world" php script to work, so I think I have php setup correctly. Any thoughts? I'm on mythbuntu 8.10 with mythtv 0.21. I'm fairly new to mythtv and linux...
Jeff - 2008-12-03 21:36:00
This script is great, but I do have a slight problem.It appears that many tracks with unusual characters in their paths (parentheses, accented characters, etc) result in a "Could not map" error.I'm currently fiddling with the source to try and fix it, though my PHP skills are pretty rusty...

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>