Unused Cycles

April 29, 2009

Amarok 1.4 Sync with iPod Touch 2G in Linux

Filed under: GNU/Linux, iPod Touch — Kevin @ 11:22 am

Since I’ve gotten my iPod Touch 2G, I’ve been forced to use iTunes, which I never really liked. Not just because it’s proprietary, but I really never cared for the interface and how it handles playlists. While four months of iTunes usage has warmed me a bit to it, I like being able to choose what application I use, especially because running iTunes means I have to run Windows XP in a Virtualbox virtual machine. Furthermore, I prefer Amarok 1.4 on KDE’s functionality more than I do iTunes or any other music player. Thankfully, with the recent release of the 24kpwn exploit on the iPod Touch 2G which allows an untethered software jailbreak, it’s possible to use Amarok with the iPod Touch 2G!

First a bit of background. The iPod generally uses a file called “iTunesDB” to store locations and tags of all of the files on your iPod. If you put music on your iPod without it being entered into the database, the iPod software won’t recognize it and you won’t be able to play it. Over the years, people have developed support for writing the iTunesDB without iTunes; on Linux, this is specifically done using libgpod. This database was the same with every iPod, so it was easy to use a new iPod with existing music software. Even the iPod Touch 1G was compatible with libgpod (albeit in a roundabout way).

With the introduction of iPod Touch firmware 2.x, Apple decided to “obfuscate” the database so that it could no longer be reproduced. All of the software that could once sync with iPods (Amarok included) was rendered useless with iPod Touch firmware 2.x.

Thankfully, there’s a workaroud. The database obfuscation is controlled by an XML file found in /System/Library/Lockdown/Checkpoint.xml on the iPod Touch (and iPhone). As it is easy to edit that file with a jailbroken iPod Touch with OpenSSH installed, it’s a matter of changing

<key>DBVersion</key>
<integer>4</integer>

to use database version 2 instead. Version 2 of the database is — you guessed it — the unobfuscated version.

There’s one little problem. When you plug your iPod Touch into your computer and run fdisk -l, it doesn’t show up. The iPod Touch does not identify itself as a mountable drive, so you must do one of two things:

  1. Tunnel an SSH connection through USB using iTunnel (buggy, at least when I compiled from source on Arch Linux), 0r
  2. Mount your iPod Touch via Fuse over WiFi

The second method is great if you’ve got a wireless network to work from. If not, and your wireless card supports ad-hoc mode, you can set up a network just between your computer and iPod. On the other hand, if you do not have access to WiFi at all, your only option is the first, which I’ve found to be quite buggy on Arch Linux. Who knows, maybe you’ll have good luck, but I’ll continue writing this the assumption that you’re using the second method.

If you’re running a decent distribution, there should be a set of scripts called “ipod-convenience” in your repositories (it’s available in the apt repositories in Ubuntu, and Arch Linux has it available in AUR). It’s my suggestion to connect your iPod to your computer over USB as that will keep the WiFi connection from turning off when your iPod goes to sleep. After installing the scripts, edit /etc/defaults/ipod-convenience so that it holds the IP address of your iPod, then run ipod-touch-mount. It’ll ask for your password (twice) and try to mount your iPod’s filesystem at /media/ipod (make sure it exists and is writable by your user).

From there, just fire up Amarok 1.4 and set up your iPod like normal. File transfer rates depend on your card’s speed and the traffic around the local access point.

If you’re OCD like me, you like having lyrics on each of your tracks so that when you tap the music application it displays lyrics. Unfortunately Amarok does not handle this well (actually, at all).  To get it working requires recompiling Amarok. If you’re into that, then keep reading. If you’re not, then you can stop right here and either a) use gtkpod which handles lyrics and artwork (but I didn’t like how it handles audiobooks (I’m a huge Doctor Who fan and listen to Big Finish audios in my free time)), or b) forget about lyrics support.

Amarok just does not handle lyrics tags well at all. From what I can make out, it saves lyrics to its own database, not the USLT portion of the ID3v2 tag. Thus when you save the lyrics to a music file using an external program, Amarok doesn’t see it and vice-versa. You can install scripts that read and write to the ID3 tags, but even then lyrics don’t show up on your iPod.

What’s happening is that a song in a database has a lyrics flag that must be set. iTunes does this by looking at the file in question at transfer time, seeing if it has lyrics in its tag, and sets that bit in the database. Unfortunately, stock Amarok 1.4.10 does not have this capability. I’ve found a patch here for Amarok 1.4.4 that I applied manually to Amarok 1.4.10

That still didn’t quite work for me. It compiled fine, but something’s changed since Amarok 1.4.4 in the way that it checks the ID3v2 tags. The original function was looking for the lyrics themselves and returning the lyrics as a string. The way that the patch works, it doesn’t actually care what the lyrics are — it just wants to know if there are lyrics. After analyzing the changes made, I changed the method QString MetaBundle::lyrics() in metabundle.cpp to just do the following (excuse the sloppy tabbing, WordPress doesn’t handle HTML):

QString MetaBundle::lyrics() const
{
TagLib::FileRef fileref = TagLib::FileRef( QFile::encodeName( url().path() ), true );
if ( TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File *>( fileref.file() ) )
{
if ( file->ID3v2Tag() )
{
if ( !file->ID3v2Tag()->frameListMap()["USLT"].isEmpty());
return QString("there's something here...");
}
return QString("");
}

After recompiling and transferring a few songs, it worked! It’s not the most elegant solution, but at least you’ll get your lyrical goodness so that you can sing along to all those songs which you have no idea what they’re saying (Boom Shackalak, anyone?)

This patch only works for MP3 files, which brings me to my next (and final) point. As previously mentioned, I listen to audiobooks and I like the built-in audiobook format that iTunes uses (M4B) because it bookmarks your files. Amarok immediately recognized my M4B files as such and uploaded them to properly use the bookmarks. However, I also like to put the “cover blurb” on the lyrics tag so that when I start a new one I have a faint idea of what’s happening. Because the lyrics patch only works for MP3 files and not M4A (I tried getting it to work, but ran into an issue with Arch’s libmp4v2), you can’t have this capability. Thankfully, in looking over the iTunesDB code for Amarok, I found that if you set the genre to “audiobook” it’ll set the audiobook flag on the iPod — regardless of whether or not it’s an M4B file. What that means is that you can use regular old MP3 files as audiobooks (which gets me even further away from Apple’s proprietary junk!)

Hopefully this was a helpful post. It’s taken me a few days to get Amarok working to my tastes, but it finally is and I thought I’d share my research.

Advertisements

6 Comments »

  1. I like the new look!

    Comment by nate — May 2, 2009 @ 9:37 pm

  2. Great intell, hope it works once 3.0 comes out.

    Comment by zcecc22 — June 10, 2009 @ 11:13 am

  3. Dear Kevin,

    I tried to follow your guide to get the lyrics loaded on the iPod…but I couldn’t manage to do it!
    In my metabundle.cpp there is no such method as QString MetaBundle::lyrics() const, and if I try adding it I only get errors…(I also see there is a missing curly bracket in your code)..please help me! I’m getting crazy about this damnd lyrics!!

    Thanks in advice,
    Antonello

    Comment by Antonello — June 16, 2009 @ 7:28 pm

  4. Thanks SO much on this, i was stuck with that f*cking itunes in a virtualbox (it’s amazing how much it sucks that piece of sh*t)…

    BTW, if you use a priv/pub gpg key for mounting umounting with no ssh password, you can have the ipod-touch-mount and ipod-touch-umount to be executed by amarok when connecting disconecting 😀

    $ ssh-keygen -t rsa
    $ ssh-copy-id -i ~/.ssh/id_rsa.pub root@

    Comment by ipoder — July 11, 2009 @ 3:45 pm

  5. Hi Antonelle,

    Sorry about the massive delay. Have you applied the patch file that I listed in the post?

    Comment by Kevin — September 29, 2009 @ 5:56 pm

  6. Amazing, thanks for the info. I have a 2g touch as well, and greatly prefer amarok over iTunes or any other music player. This surely helps 🙂

    Comment by Susie — March 12, 2010 @ 7:58 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: