Menu

Home

Timothy Miles

PandoraCapture was written to record streaming audio from Pandora and later was extended to include LastFm. It uses FiddlerCore as a proxy server to capture all traffic and then watches for Pandora's audio metadata XML file. This file is broken into segments and stored in memory in a dictionary keyed to the URL of each audio file.

One of the caveats is that the URL Pandora lists in the XML is not quite the same URL that is actually used to retrieve the audio. The URL contains a base64 encoded token of some sort, and the last few bytes differ. So I take the incoming audio URLs, strip about 50 characters from the end, and then compare my list of URLs to the remaining characters, stripping each one down to the same length.

Once I have determined that a particular audio stream belongs to a particular fragment of the XML, I save the file as an M4A file and save the XML fragment alongside it. If FFmpeg is installed, I then start another thread that uses FFmpeg to convert the M4A file to an MP3 file. That thread uses the XML to set the appropriate tags in the MP3 file, including a comment tag that includes the full XML fragment, just in case I ever need it again. It then deletes the M4A file.

LastFm works the same way, except that they send MP3 files, so I don't have to convert them.

For both Pandora and LastFm, UltraId3Lib is used to set the tags. This project (currently) only supports up to Id3v2.3 tags, so the ffmpeg command line for Pandora has to have a switch set to force it to use v2.3 tags.

Project Members: