A hack a day keeps the doldrums at bay

Here's a fun Mac OS X/last.fm hack I came up with a couple of days ago.

I'm sure that many here are, like myself, users of last.fm If not,
you should check it out. What I find best about it is its ability to
introduce me to new music that I've never heard of before but is,
according to some funky algorithm, of a similar ilk as the music I
prefer. But the big bummer is that I can only hear it on last.fm and
at random intervals. I can't think, "Oh, I'd like to listen to that
again." or "I'm in the mood to listen to that song right now." Of
course, I could buy the CD but we all know how old-fashioned that is.
Remember the old days of taping from radio. Those were fun. But the
stuff that I like to listen to is already obscure enough so that
things I'm being introduced to via last.fm are even more obscure.
This stuff isn't being played anywhere on the radio. The other day, I
even went to my local humongous music store and they didn't have
anything by the band I was looking for. So, that's my dilemma. I'm
hearing good music on last.fm and I want to be able to listen to it
whenever. I want it on my iPod so I can listen to it as I bike around
town. So, where do we start? Well, we know the last.fm client is
communicating via the network and we can safely assume that it's
playing mp3's. That's all we need to know.

This is a bit complex, but if you don't already know how all this
stuff works, then think of it as a learning experience.

First, you're going to need two things; time, and a few tools (you
need the time to install the tools. After everything is installed,
everything is simple). First thing to install is X11 (that is if you
don't already have it). You can get this from http://www.apple.com/
downloads/macosx/apple/x11formacosx.html or your OS X cd. Next,
install DarwinPorts, a nice tool for installing *nix tools on OS X:
http://darwinports.opendarwin.org/getdp/

Now use darwinports to install "ethereal". It's a handy GUI-style
network packet sniffer and logger. After that, use darwinports to
install wget, a network file-fetcher.

When you've got these installed you're ready to begin. Open X11
(you'll find it in /Applications/Utilities). Now, darwinports should
have created a new folder on your system called /opt programs are
found in /opt/local/bin You'll have to run ethereal as root for it to
have access to your network interfaces. So, in the X11 window type
"sudo /opt/local/bin/ethereal", hit enter, it asks for a password,
type in your password and hit enter again. ethereal opens up with a
complicated looking GUI. Towards the top of the window is a row of
weird looking buttons. Click the second one (if you let the pointer
hover over it for a second, it says "Show the capture options…") A
new window opens. The only thing you have to do is select the
interface. At the top, where it says "interface", select "en0" if
you're using ethernet or "en1" if you're using airport.

Now leave ethereal for a little while. Open your last.fm client, type
in what you want to listen to (for instance, select "Search by
Artist" and type "Nucleus") and hit enter. Then click the green play
button. Now last.fm knows what you're looking for. After it begins
playing the first song, hit the stop button. Go back to ethereal and
hit the "stop" button on the little window in front of the big GUI.
Then go to "file" and hover over "export" and from the side menu,
select 'as "Plain Text" file'. Give it a name, like netcapture.txt
and make sure you're saving it to a place where you can find it again
and save it. Next, open the netcapture.txt file in TextEdit (standard
on all OS X). Select "Edit - Find - Find…" and type ".mp3" in the
text box and hit enter. It should jump to a part of the file that
looks something like this:


No. Time Source Destination
Protocol Info
244 27.284989 192.168.0.100 83.142.226.82
HTTP GET /last.mp3?Session