unofficial python uploader

tl;dr audiobox-uploader-0.01.tar.gzgit repository

Some time ago I was being frustrated by my inability to access the music stored on my personal fileserver while at work — something about Apple having locked iTunes sharing to the local subnet, the lack of decent DAAP clients for Mac, and so on and so forth. Moving all the many gigabytes of music I have to my work laptop over work’s network connection is slow and anti-social, and at any rate then I have two places in which I need to manage my music and propagate new albums I buy. (Yes, if this were a Twitter post it would get the #firstworldproblems hashtag.) “Wouldn’t it be great, in this much-ballyhooed age of Cloud Computing,” says I to myself, “if my music could live in the cloud.”

Some friends of mine have a startup, MixApp, which lets me (legally!) publish the music on my fileserver and listen to it and chat about it with friends online, which was sort of like what I wanted. It’s actually a really neat service, and I like it and use it a decent bit, but I don’t always want to listen to music with other people, and the interface is tuned to the social music listening model and not so much to being like iTunes. Additionally, at the time they were having server problems (since resolved!) so that avenue wasn’t available to me.

I started looking around online, and the first service I ran across that seemed to fit the bill was For a mere $10 a month, they’ll host up to 151GB of music, and they’ve got a nice Flash-based, iTunes-like player, scrobble support, decent library management capability, and most of the other features I expect out of modern music player software. They’ve got support for a bunch of formats besides MP3 (FLAC, OGG, and M4A being the ones I care most about), though all the music gets transcoded to MP3 for streaming, so I’ve been mostly converting to MP3 locally before I upload, since there’s no sense taking up the storage space for FLAC if I don’t get any benefit from it. Since it’s all my music, I can also get it back any time I want, so it’s a convenient backup of my music collection.

The only problem was getting all my music into the service. There’s currently a fairly nice Flash uploader, but it only takes 999 tracks at once and only MP3s, and there’s now also a Java WebStart-based uploader (which there wasn’t when I started), but most of my music lives on my Linux fileserver, not any of the client computers I use, so neither of those was going to do it. There’s also a nice RESTful API, and so I set out to write a Linux upload script.

Along the way, I discovered that none of Python’s built-in HTTP libraries deal with submitting multipart forms. I ended up stealing the multipart processing logic from Gabriel Falcao’s bolacha library, of which portions were in turn borrowed from Django’s test client, but I was disappointed that the support wasn’t built into something more comprehensive. Claudio Poli at AudioBox pointed me towards bolacha, and has been excellent to work with on this script — I’m pleased with AudioBox’s attentiveness to developers. (Careful observers will note that AudioBox offers both an OAuth authentication API for web services and HTTP Basic authentication for desktop applications, and Claudio promises that they aren’t going to pull a Twitter on desktop and open-source application developers.)

None of Python’s built-in or commonly-used HTTP libraries support bandwidth throttling, either, which turns out to be important when you’re uploading tens of gigabytes of music. I thought about building native support into the upload script, but I wanted to get a release out, and the trickle utility turns out to work marvellously on Python to limit its upload bandwidth use, so I punted on that. Seriously, if you don’t know about trickle already, you should make a note of it — I can’t remember the number of times I’ve wanted to throttle a program that didn’t provide the option, so its existence falls into the “I wish I’d known about this years ago” category.

At any rate, the result of my labors is audiobox-uploader-0.01.tar.gz, released here for the first time. Source can be found on Github, and users should please feel free to contact me with any questions, comments, or patches you might have. 🙂