How to stream MP3 audio from Rdio

Recently, I was working on a personal project for which I wanted to stream audio from my Rdio (which, incidentally, is a great service) account. Unfortunately, the documented Rdio APIs don’t provide a way to do this, instead providing streaming through a Flash player for web apps or compiled libraries for iOS and Android. I spent a bit of time reverse-engineering pieces of the Rdio ecosystem to figure out how to do this and thought I’d post the resulting recipe for how to do this in Python in case anyone is interested.

First of all, apply for an Rdio API key.

Next, you’ll need to install a bit of software:

  • rdio-python package, which gives us access to the official Rdio REST API
  • PyAMF, which we use to make calls to the the un-documented Flash API
  • rtmpdump, which we use to stream the FLV content from the RTMP server. Note that versions after 2.1d don’t work, as they refuse to talk to the server which they deem to be not genuine Adobe
  • ffmpeg, which we will use to transcode the FLV audio into MP3

Once you’ve got all that installed, the process is relatively straight-forward: use the Rdio API to search for a track you want to download and grab a playback token for it; use the (un-documented) Flash API to retrieve parameters for constructing arguments to rtmpdump; run rtmpdump and pipe the output to ffmpeg to trans-code the FLV to MP3.

Here’s a proof-of-concept script that implements that process:

To use use, invoke it with your API key, API secret and the query you wish to use for searching for songs. It will perform the search and spit out shell commands for fetching and trans-coding the song.

I’ve wrapped this behavior up in a simple Python library and dumped it up on Github as pyrdiostream.

This entry was posted in Python. Bookmark the permalink.

One Response to How to stream MP3 audio from Rdio

  1. I think mplayer is best than ffmpeg to do the streamdumping because ffmpeg reencodes the stream, laying to possible audio loss on reencoding. Ive used sucessfully with you script mplayer with “mplayer -dumpaudio -“. It will create the stream.dump file with raw data inside the audio track. This way you can extract untouched mp3 stream from flv. So may be better use mplayer to just dump the raw audio stream than ffmpeg to reencoding the file.

Comments are closed.