GSoC Report Week 4

June 24th, 2008  |  Published in Code, Technology

Project: MP3tunes + Amarok Integration

Total Commits: 84 Weekly Commits: 36

Past 7 Days

Starting these posts with “It was another busy week..” is starting to get boring; I’ll cook up something more exciting for next week.

In case you missed it, in the past seven days history has been made. I’ll let that stand in as the bulk of my weekly report, but a few worthwhile things have occurred since then that deserve a mention.

Remote Track Upload – You can now sideload tracks to your MP3tunes collection from remote sources in Amarok. What the heck is sideload and what remote sources you ask? Sideload is a feature of the MP3tunes API that allows for server-to-server transfers. This means you can give your Locker a URL to a track, and it will automatically be downloaded into your Locker. Currently Amarok sports three services with remote collections that are sideloadable to MP3tunes: Ampache, Magnatune, and Jamendo. This method of transferring is generally very fast, because the transfer bypasses your slow internet connection.

Upload Progress Bar – When you upload (or sideload) tracks to MP3tunes there is now a simple status bar to let you know how far along in the process you are.

Non-Supported Track Filtering – This one is simple: If you try and upload a file-type that MP3tunes doesn’t support, Amarok will tell you and stop that track from being transferred.

Upcoming 7 Days

  • Work on allowing MP3tunes tracks to persist after a restart.
  • Flesh out the synchronization system: what it’s going to do, and how it’s going to do it.
  • Design any UI widgets needed for the syncing system

The first one will be simple, in fact I plan to code it up after writing this report. These second and third tasks, however, signify that I’m moving into the last stage of the project. According to my original proposal I am ahead by a week, so I’ll be using this week as extra time to plan and get a jump-start on the synchronization framework.

One small step for Amarok…

June 20th, 2008  |  Published in Code, Technology

I’m very excited to announce that the first Amarok->Cloud transfer has taken place. Just moments ago, for the first time ever (as far as I’m aware), a track was sent up into the Cloud from a desktop media player, escaping the local collection prison. This track shed the chains of limited accessibility, and is no longer doomed to obscurity, lost in an sql database in my home directory.

This lucky track happened to be Making Me Nervous by Brad Sucks available over at the great indie music label Magnatune.

Early this morning I committed the last bit of code that allows you to upload tracks to your MP3tunes Locker from Amarok. Amarok is the first client, besides the official client, to allow you to do such a thing. One of the great things about this feature is it’s seamless integration in the UI.

Click for the full view
Amarok 2: Copy to Mp3tunes

After a short upload I go check the MP3tunes Web Player
Listening to Brad Sucks via MP3tunes

From this point I can listen to the track on my phone, on my squeezebox, or any other MP3tunes supported devices.

Of course there are some caveats, but I aim to fix these over the next several days:

  • No upload progress information.
  • No error handling when you attempt to upload a filetype mp3tunes doesn’t support.
  • It’s not possible to upload non-local content (say from magnatune or ampache)

Don’t start thinking that things are winding down; uploading and downloading are only one small part of the show. The end goal is fully automated bi-directional syncing between Amarok and MP3tunes with 100% support for the MP3tunes API.

What exactly does this entail?

  1. I foresee a “keep in sync with MP3tunes” checkbox for each playlist in the Amarok playlist browser, so you can add/remove tracks from your favorite playlists and thoughtlessly have access to them on any MP3tunes enabled device.
  2. Imagine clicking “Purchase” at an online music store (like eclassical) and having the tracks instantly available in Amarok and anywhere else you have access to your locker.
  3. Your friend beams you a track from his Android phone to your Android phone while you are out on the town, and when you get home the track is all ready in your local Amarok collection, added to your smart playlists ready to jam.
  4. You subscribe to an awesome podcast using Amarok’s built in podcast directory, and seconds after a new episode is released it’s available on your wifi enabled portable player (or phone)

And it all started today.

GSoC Report Week 3: Tanstaafl

June 17th, 2008  |  Published in Code, Technology

Project: MP3tunes + Amarok Integration

Total Commits: 51 Weekly Commits: 12

Past 7 Days

It was another productive week in #amarok with over 150 commits! In the 12 of those that were mine I managed to do several things.

  • Added elegant session handling to the MP3tunes service
  • Fixed the collection search box, so you can filter your MP3tunes Locker.
  • Enabled Copy To Collection functionality, so you can now copy (read: download) mp3tunes tracks to some other collection!

Of course, implementing those items wasn’t as simple as it sounds, but the features are essential and basic.

The search box (filtering) could use some improvement as currently it only filters via the artist field, but that is a limitation of the MP3tunes API. When I say it
“only filters via the artist field” I mean that it only matches against artists, so searching for a particular track name will not work. To fully support the filtering feature the MP3tunes API would need to allow you to do something like get a list of artists based on a partial track name in a single request. That is just one example, and yes, I could workaround it by doing multiple queries, however that would slow the entire operation significantly. Users expect the search fields in Amarok to be snappy, not take ~5 seconds per. token they supply. It is certainly not a showstopper, and it functions well enough for now, but hopefully MP3tunes will be open to expanding their API later on down the rode. To be fair I have never come across a web API that supported that sort of complex searching. The Ampache service in Amarok suffers from the same lack of functionality.

Interjection: Major props to my GSoC mentor, Nikolaj, for attempting to explain various parts of Amarok’s innards to me, not only once, but the several times it took to get the concepts through my thick skull. Also, he’s helped me track down several childish mistakes I’ve made when I was at my wits end trying to locate them. I can’t thank him enough. Hands down he’s the best GSoC mentor.

With the addition of “Copy to Collection” Amarok has taken a large step towards being fully integrated with MP3tunes. Up till this week all you could do was browse and stream your MP3tunes Locker. That is fine and dandy, but you could do that from the MP3tunes web player, their mobile player, your PS3, or any other number of their supported devices. However, none of those options allow you to seamlessly download and organize your stored music into your local music collection at the click of a button.

There is one shortcoming that needs to be addressed at some point before I’m satisfied: there is no progress indicator of any kind when you download tracks. The only way to see if tracks are being downloaded after you press Go is to watch the destination directory for changes. Thankfully this affects all collections you can “copy to/from”, not just MP3tunes, so perhaps someone else will feel inclined to whip up a progress indicator. There’s no such thing as a free lunch.

Upcoming 7 Days:

I have one big goal this week:

  • Add MP3tunes Upload features

By Monday next week, you will be able to do Copy tracks from your local collection, Ampache collection, and the Magnatune database, to your MP3tunes locker.

Copy to Collection

There is quite a bit of work to be done before this can happen, but I will spare you the gritty implementation details until next week after I’ve committed the code where my mouth is (?).

Of course my weekly predictions wouldn’t be complete without a task to fall back on if I happen to complete the aforementioned task in a Ballmer-Fueled rage. After upload is in place there is only one major item left: Syncing. I need to break “Syncing” into manageable actionables (quite a term, eh?) and then lay out some mid-level designs for the process. Later on during the week I will dedicate an entire post to this topic.

GSoC Report Week 2: libmp3tunes goodness

June 10th, 2008  |  Published in Code

Project: MP3tunes + Amarok Integration

Total Commits: 35 Weekly Commits: 15

Past 7 Days

This was a busy week. I migrated the existing MP3tunes service in Amarok 2 from making REST calls and parsing XML manually to use libmp3tunes. I created an object oriented encapsulation framework in C++ for libmp3tunes, which is written entirely in c. This means instead of mucking about crafting http queries and worrying about parsing data from XML one can manipulate the Locker in an OO fasion. Here’s a little snippet of how libmp3tunes saves work.

Without libmp3tunes if you wanted to fetch a list of artists this is what it would look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    QString urlString = "http://ws.mp3tunes.com/api/v1/lockerData?sid=<SESSION_ID>&partner_token=<PARTNER_TOKEN>&output=xml&type=artist";
 
    urlString = "http://ws.mp3tunes.com/api/v1/lockerSearch?output=xml&sid=<SESSION_ID>&partner_token=<PARTNER_TOKEN>&type=artist&s=" + m_artistFilter;
 
    urlString.replace( "<SESSION_ID>", m_sessionId);
    urlString.replace( "<PARTNER_TOKEN>", CENSORED);
 
    debug() << "url: " << urlString;
 
    m_storedTransferJob =  KIO::storedGet(  KUrl( urlString ), KIO::NoReload, KIO::HideProgressInfo );
        connect( m_storedTransferJob, SIGNAL( result( KJob * ) )
            , this, SLOT( artistDownloadComplete( KJob *) ) );
 
    ArtistList artists;
 
     //so lets figure out what we got here:
    QDomDocument doc( "reply" );
    doc.setContent( m_storedTransferJob->data() );
    QDomElement root = doc.firstChildElement( "mp3tunes" );
    root = root.firstChildElement( "artistList" );
 
    QDomNode n = root.firstChild();
    while( !n.isNull() )
    {
        QDomElement e = n.toElement(); // try to convert the node to an element.
 
        QDomElement element = n.firstChildElement("artistName");
        ServiceArtist * artist = new ServiceArtist( element.text() );
 
        element = n.firstChildElement("artistId");
        artist->setId( element.text().toInt() );
 
        ArtistPtr artistPtr( artist );
 
        artists.push_back( artistPtr );
 
        m_collection->acquireWriteLock();
        m_collection->addArtist( artistPtr );
        m_collection->releaseLock();
 
        n = n.nextSibling();
    }

With libmp3tunes it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    Mp3tunesArtistFetcher * artistFetcher = new Mp3tunesArtistFetcher( m_locker );
    connect( artistFetcher, SIGNAL( artistsFetched( QList<Mp3tunesLockerArtist> ) ), this, SLOT( artistDownloadComplete( QList<Mp3tunesLockerArtist> ) ) );
 
    ThreadWeaver::Weaver::instance()->enqueue( artistFetcher );
 
    ArtistList artists;
 
    foreach(Mp3tunesLockerArtist artist, artistList) {
        ServiceArtist * serviceArtist = new ServiceArtist( artist.artistName() );
 
        serviceArtist->setId( artist.artistId() );
 
        ArtistPtr artistPtr( serviceArtist );
 
        artists.push_back( artistPtr );
 
        m_collection->acquireWriteLock();
        m_collection->addArtist( artistPtr );
        m_collection->releaseLock();
 
    }

Both of those code samples produce this:

MP3tunes Collection Browser

Notice that instead of looping through XML and ripping out data, I was able to call getter methods to retrieve the same data. Of course the XML parsing has only been moved to libmp3tunes, but by hiding the MP3tunes API implementation from Amarok it creates more maintainable code.

If none of that made much sense, no worries, the important bit to grasp is that libmp3tunes does these important things:

  • Encapsulates the MP3tunes API so it is separate from the rest of Amarok.
  • Provides an Object Oriented interface to the mp3tunes API. Creating a new session is as easy as Mp3TunesLocker locker = new Mp3tunesLocker();
  • Ensures Amarok is officially supported by mp3tunes as long as they support libmp3tunes.

Upcoming 7 Days:

There are a few libmp3tunes shortcomings. One is the lack of a means to detect when a session has expired. Each MP3tunes API request requires a valid session (except of course the initial session-establishing request), and each session times out eventually. When using MP3tunes in Amarok it will be important to elegantly handle session timeouts, for the user does not care about sessions or timeouts. When the user clicks play on an artist they expect it to play, while currently, if the session has timed out Amarok doesn’t do anything. This week I will patch libmp3tunes to support detection of timed out sessions.

Another goal for this week is to fix the search box, so it actually searches.

MP3tunes Collection Search

Also, if you right click on an artist in the MP3tunes collection browser you get a “Copy to Collection” option. At the moment it doesn’t do anything. After this week is over, hopefully, selecting the “Copy to Collection” option will let you do just that.

Copy to Collection

Foreseeable Roadblocks:

Last week’s roadblock still stands. In the next few weeks I’ll be getting closer to the time when I will need to implement that syncing part of libmp3tunes into Amarok. The licensing issue won’t stop me from developing it on my own workstation of course, but it will have to be resolved before I can commit that part of library or code that implements it.

GSoC Report – Week 1

June 2nd, 2008  |  Published in Code

Project: MP3tunes + Amarok Integration

Prescriptum: These weekly reports will likely contain a bit of technical information that only other Amarok developers will understand. I do not like that idea, as I want these reports to be grokable by all, but since I haven’t yet decided on a format to present the info in a manner I like this will have to do for this first week.

Past 7 Days:

I started coding for GSoC last Tuesday (May 27th) beginning with a simplification of the ServiceCollection hierarchy by combining ServiceDynamicCollection and ServiceCollection into one class. I also started creating the ServiceCollectionLocation’s. It is not implemented anywhere yet, and won’t need to be for awhile, but I started it as at the time I was waiting on mp3tunes to deliver their c sdk.

Leeo kindly created mp3tunes icons, which I committed on Saturday.
mp3tunes icon and Mp3tune icon

During the week I kept nudging the mp3tunes developers to send me the c sdk, and Saturday the nudging paid off as I received a pre-release version of libmp3tunes. Even though it is a pre-release it is complete enough to match the current mp3tunes feature set in Amarok2. On Sunday I added libmp3tunes to the src tree, including the dependency detection. libmp3tunes is dependent on curl and libxml2, and if someone does not have them mp3tunes will be excluded from the build thanks to cmake.

Finally, today, I committed a ~750 line c++ wrapper for libmp3tunes to compartmentalize the unsightly c code.

You can see all my commits here:
http://kollide.net:8060/changelog/~author=link/Amarok

Upcoming 7 Days:

There are still a few functions left TODO in the c++ wrapper for libmp3tunes, so I’ll complete those this week. Then I plan to start migrating the existing service to use the library functions. I expect this will take all week, so my goal for the next report is to have the migration complete and a working Mp3tunes service utilizing the library. If my time estimation ends up being too long, and I finish the migration early, I’ll work on the Mp3tunesCollectionLocation functionality so you can copy tracks from Mp3tunes to the local collection in a manner similar to the Magantune service.


Forseeable Roadblocks:


The syncing part of libmp3tunes is not licensed and not complete. However, the MP3tunes developers have been particularly responsive the past several weeks, so I am optimistic they will pull through.

Reflections:

I am amazed at how much I learned this week. To keep this brief here is a list of some things I’ve learned:

  • How to do basic cmake things like define optional deps and exclude portions of an app if they aren’t met.
  • Before this week I had never even seen object oriented c before.
  • Also I learned how to combine c and c++ code in the same program (extern!).
  • KDE4 is a beast and breaking it is bad news.