Eric Lawrence’s Fiddler has many uses. I use it every day for debugging our client/server interaction, caching behavior, etc. What many don’t realize is that Fiddler is also an excellent platform for scripting, enabling you to modify requests and responses as they go out and come back. I made a quick script to automatically download streamed MP3 files as they were played, naming them automatically from the ID3 information contained in them.
Before we get started, head on over and download the FiddlerScript Editor.
Parsing ID3 tags
As I’m lazy, and most likely you are too, we’ll use the excellent TagLib Sharp library for parsing the ID3 information in the downloaded MP3 files. You can get the latest version (184.108.40.206 as of this writing) from here.
To gain access to the TagLib Sharp library from Fiddler, add a reference to it in the Fiddler Options dialog:
Setting up the script
Now go to to Rules menu and click “Customize Rules…” to open the CustomRules.js file in the FiddlerScript Editor that we installed before.
Go to the OnBeforeResponse function and add the following bit of code to the end:
The first line identifies the requests that are for MP3 files. Depending on where you’re streaming from, you’ll obviously need to change this line to match your specific requirements.
Once an MP3 response has been detected, we save the file using a GUID as the name. If TagLib Sharp detects a song title, the file is renamed in the “AlbumArtists – Title.mp3” form. If no title is present, we just let the file stay with the GUID name for manual renaming later on.
Save the CustomRules.js file and Fiddler will automatically pick up on the changes and start saving those precious MP3s!
Obviously the above code should only be used to save MP3 files from streams to which you own the rights.