Converting from iTunes to Banshee

This past week I purchased for myself a mini laptop. I wanted something nice and portable that I could use for personal use on trips and do hobby projects on. This thing is great. I got Ubuntu installed and started playing around since it’s been a couple years since I had a Linux desktop, and even then I usually had a Mac OS X laptop I used with it. As such, when it came to copy over my music and such, I needed to convert to a new music player. I’ve settled on Banshee for the moment.

Problem: There’s no import tool out there to go from iTunes to the current version of Banshee.

Solution: However, the process turned out to be not so hard for me. Here’s what I did:

  1. Copied the iTunes music folder from my Mac to the music folder on my new laptop.
  2. Started up Banshee and used Media > Import Media… to tell Banshee where to find all the files and let it do it’s thing.
  3. Went back into iTunes on my old machine and used File > Library > Export Library… to generate a Library.xml file, which I copied to the new laptop
  4. Ran a Perl script I wrote to pull out the play lists, song play counts, last play date, and ratings and push them into the Banshee database

Fortunately the Library.xml file output by iTunes is in a standard format that is pretty easy to understand. Also, Banshee keeps much of the information about your music and such in a SQLite database. So, I could very easily automatically copy over all the ratings and other information I’ve been assembling for the past several years.

Here’s the conversion script, itunes-to-banshee.pl that I wrote for download:

Download itunes-to-banshee.pl

Update (thanks to Rolo): You will need to install a few dependencies as well. On Debian or Ubuntu, this is done by installing:

  • libdatetime-perl
  • libdatetime-format-iso8601-perl
  • libclass-dbi-sqlite-perl
  • libxml-twig-perl
  • libmime-base64-perl

This can be done from Synaptics or by running this on the command-line:

sudo apt-get install libdatetime-perl libdatetime-format-iso8601-perl \
    libclass-dbi-sqlite-perl libxml-twig-perl libmime-base64-perl

Once Banshee has finished adding your song files to its music library, close Banshee. Make a backup copy of banshee.db to somewhere in case something goes wrong (which can be found at ~/.config/banshee-1/banshee.db). Then run:

perl itunes-to-banshee.pl Library.xml ~/.config/banshee-1/banshee.db

This may take a few minutes, depending on how many songs you have. It might show you some warnings if your Library.xml is weird (remember I wrote this just for me). It may also tell you if it can’t find some songs in Banshee that it found in your Library.xml. (It did for me because I’d deleted some songs from the disk and iTunes never figured it out.)

Once it finishes, start Banshee back up and it should have the play lists, ratings, play counts, and last played date set for all the songs that had such information in iTunes.

There are a couple things you might want to know about how the program works. First, it does not touch smart play lists. I don’t know and don’t particularly care how to read the smart playlist configuration from iTunes. I was able to recreate the smart play lists I had in a few minutes.

Second, the import script uses the song title and song file size to match songs from the iTunes library in the Banshee library. This is probably safe since I’ve never seen two CDs with the same songs on them end up being the same size, but it’s theoretically possible it could be a problem.

Third, if you have duplicates in your library, this script will only change one of them. I’d recommend weeding those out first.

I’m not interested in maintaining the script, but I’ll answer questions about it. If you ask really nicely and I’m in a good mood and the change you want is very small, I might be willing to make it, but that’s a lot of “ifs” to line up.

Cheers.

0 TrackBacks

Listed below are links to blogs that reference this entry: Converting from iTunes to Banshee.

TrackBack URL for this entry: http://contentment.org/mt/mt-tb.cgi/651

7 Comments

Just what I needed! Thanks :>.

Just to anyone else not familiar with Perl, the script has a few dependencies. So on my Ubuntu box I had to run:

sudo aptitude libdatetime-perl libdatetime-format-iso8601-perl libclass-dbi-sqlite-perl

To get the DateTime and SQLLite dependencies first.

Cheers.

Rolo.

Ah, yes! Thank you for pointing that out. I meant to include the dependencies. I will update the article.

Hi Andy,

I have a question that maybe you can answer. Do I have to copy all of the music files over? Let me explain:

I have a dual boot WinXP/Ubuntu Jaunty which is on one partition (C:). All of my music is on partition D. I have Banshee on Jaunty and iTunes is on Windows.

Thanks!

I don't think so. As long as Banshee has scanned your music files, it shouldnt' matter where they are stored.

Cheers,
Sterling

Thanks for the how to and the Wonderfull Script.
That was the Last thing i needed to switch from OSX to ubuntu.

One more Linux User!

Thanks for the great script!

In order to get it to work in Banshee 1.6 Beta 2 (1.5.1), I had to make a few changes.

1) Trying to match both the song title and size didn't work for me for whatever reason. I don't have any songs with the same name, so dropped the size matching requirements by changing

SELECT TrackID FROM CoreTracks WHERE Title = ? AND FileSize = ?}, undef, $value->{'Name'}, $value->{'Size'});

to

SELECT TrackID FROM CoreTracks WHERE Title = ?}, undef, $value->{'Name'});

This made it so that the playcounts could be imported properly.


2) Banshee might have changed the database format or something since your original release, because I was getting these errors:

DBD::SQLite::db do failed: called with 2 bind variables when 3 are needed at itunes-to-banshee.pl line 232.

To fix this, I changed the playlist insertion code from

$dbh->do(q{
INSERT INTO CorePlaylists(PrimarySourceID, PlaylistID, Name)
VALUES (?, ?, ?)
}, undef,
++$playlist_id,
$value->{'Name'},
);

to

$dbh->do(q{
INSERT INTO CorePlaylists(PrimarySourceID, PlaylistID, Name)
VALUES (?, ?, ?)
}, undef,
1,
++$playlist_id,
$value->{'Name'},
);


After these changes, the script ran beautifully for me and it is awesome to finally have my iTunes playlists in Banshee.

Hopefully this info will be useful in case someone else has the same problems that I initially encountered.

- joey

Thanks for this Andrew! It seems to be the only thing on the web that has been able to help me with this. I've been at it for days... I'm new to ubuntu and I think I followed your instructions properly. I was able to import song ratings to Banshee :) but unfortunately none of my playlists were imported :( I keep getting this error:


DBD::SQLite::db do failed: PRIMARY KEY must be unique(19) at dbdimp.c line 403 at itunes-to-banshee.pl line 248.

any suggestions of what could be wrong would be very much appreciated...(i'm running Banshee 1.4.3, Ubuntu 9.04)

Thanks!

Leave a comment

About this Entry

This page contains a single entry by Andrew Sterling Hanenkamp published on May 22, 2009 6:12 PM.

The Best Way to Add Icons was the previous entry in this blog.

Wascally Perl Operators is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.