I flew to Austin the other weekend for the Austin Music Hackathon and built a quick Chrome extension called “Pandora to Rdio“. (Lame name, I know.) It adds any track you “thumbs up” in Pandora to an Rdio playlist. Take the pain out of creating playlists by letting Pandora do the heavy lifting of finding music you like. Download the extension/grab its source code on my Github page.
Pandora is great at finding music I like, but it streams one track after another without any ability to repeat a song. Rdio is great at letting me pick and choose songs I want to listen to and repeat them as often as I like, but—despite its name—does a lousy job of finding me new music. I wanted to get a peanut butter chocolate situation going and combine the good parts of each service.
The latest version of the Pandora web player is in HTML, so hooking into it is straightforward. The Chrome Developer Tools came in handy, I simply right-clicked on the “thumbs up” button, hit “Inspect”, and had its CSS class name. I did the same for the song’s name and artist. With those, I used a few lines of jQuery to add an event listener to the “thumbs up” button and extract the values for song title and artist.
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". - chrome_ex_oauth.html:19
Here’s my updated chrome_ex_oauth.html and oauth_helper.js for reference.
Invisible Interfaces and Room for Improvement
When you install the extension, one of the things you’ll notice is that there isn’t anything to notice. Unlike most other extensions, Pandora to Rdio doesn’t add buttons or any other elements to the browser’s chrome. This was a conscious decision. The interface is Pandora itself. Like a song? Hit the thumbs up button in Pandora, the extension will silently take care of adding the song to your Rdio playlist. It’ll even create the special “Pandora Favorites” playlist automatically if it doesn’t exist. An ideal invisible interface only disturbs the user for errors the application couldn’t deal with on its own, so you won’t find any “successfully added track” type notifications. Success is the default, not something that needs to be called out every time. Unfortunately, Pandora to Rdio isn’t an ideal invisible interface and while it doesn’t disturb you with “successfully added track” type notifications, it also doesn’t call out errors properly. This is something I wanted to work on, but ended up running out of time.
Unfortunately, it’s also not packaged for distribution to non-technical users since each person needs to sign up for their own (free) Rdio Developer account and enter their Rdio API credentials in the background.js file. I wrote up step-by-step install instructions that should help make things easier.
Despite a few rough edges, I think the project is still a useful starting point for more elaborate hackathon projects. You can grab the source code on my Github page. If you end up using it to build something cool, let me know all about it, @rahims or email@example.com!
I’ve been eyeing the Sonos devices for some time now, but never found a chance to sit down and play with them. For the folks that have never heard of Sonos, they make high-quality wireless speakers that you can set up in your home to stream music through. The interesting thing about them is that they’re fairly easy to configure—just plug in power and connect to your home network—and they play well with each other. Adding multiple speakers is as easy as plugging them in and joining them to your home network. The devices automatically find each other, and from there you can easily arrange them however you like (have all the speakers play the same song, have two playing one song in one room and another playing a different song in another room, and so on). The downside is that they’re quite expensive (the cheapest speaker costs ~$300), which made it hard for me to justify getting one. However, that all changed recently. I was in Australia for Music Hack Day Sydney this past weekend and, as a sponsor of the event, Sonos was there with a bunch of Play:5 speakers!
Realizing that this was the perfect opportunity to finally tinker with the Sonos players, I started digging through their developer documentation. What I quickly found out though, was that while there were plenty of docs (and sample code) for creating applications that stream music through the speakers, there was no documentation on how one could control the speakers themselves. After a bit or reading, I learned that the Sonos devices communicate with each other over UPnP, so controlling the speakers would simply be a matter of working with that protocol. Unfortunately, that was easier said than done. Despite being an open protocol, UPnP is lacking in easy to understand documentation and easy to use libraries. To be fair, there seem to be good UPnP libraries in C, but I didn’t want to dust off my ancient C programming skills for a weekend hackathon. I was able to find two Python libraries, BRisa and sonospy, but neither worked when I gave them a go. It was time to get creative.
Peaking Under the Hood
I had a working Sonos controller on my computer, the official Sonos application, I just needed to figure out how it did its magic. Enter Wireshark, the revealer of secrets. After a few packet sniffing sessions, I had what I needed. Sonos devices can be controlled by sending them SOAP messages. For example, to pause the currently playing track, you would make the following HTTP POST request:
POST http://[Sonos speaker’s IP address]:1400/MediaRenderer/AVTransport/Control
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Pause></s:Body></s:Envelope>
Finding out the Sonos speaker’s IP address is done programmaticaly through the Simple Service Discovery Protocol (SSDP). I wasn’t able to write the code to do dynamic discovery over the weekend, so I took the easier route. If you have the official Sonos application installed, you can get a report of all the speakers’ IPs by clicking on “About My Sonos System” in the Sonos menu.
It’ll give you an output similar to the one below.
Associated ZP: 10.0.0.103
Serial Number: 00-0E-58-4F-87-AC:F
Version: 3.7 (build 17551200)
Hardware Version: 188.8.131.52-2
IP Address: 10.0.0.100
PLAY:5: HACK CHILL ROOM1
Serial Number: 00-0E-58-5D-15-32:E
Version: 3.7 (build 17551200e)
Hardware Version: 184.108.40.206-2
IP Address: 10.0.0.102
I was able to implement the other basic controller functionality, like play, stop, next track, previous track, and get information about the currently playing track, by sending similar SOAP messages. A few hours into the weekend, and I was able to control the hackathon’s Sonos speakers through my terminal! (This got pretty annoying for the other hackers at the event since those were the sames speakers that were playing the music for the weekend.)
Spicing Things Up
A terminal prompt makes for a lousy hackathon demo, so I decided to code up some simple applications on top of my base Sonos controller library. The first was a web app version of the Sonos controller. To spice things up, I used the Rovi API to bring in high-quality cover art and editorial album reviews. I also used the Rdio API to add in a “favorite” button. Push it and the currently playing track gets added to an Rdio playlist.
For my second example application, I used the Twilio API to let me control the Sonos speaker through SMS. This was particularly cool because the official Sonos application for the iPhone only works when you’re in your home network. With SMS, I could control the speakers even when I was out. Ran out of the house, but forgot to turn off your music? Just send your speaker a text message.
All three demos went over well with the audience at the hackathon during my presentation on Sunday night, and I ended up winning a Sonos Play:3 and bridge of my very own!
The Real Payoff
While winning some hardware of my own is awesome, the real win for me is the potential for great things in the near future. All of my code for the weekend and the sample applications is available on my Github page. With the basic groundwork laid, I hope developers at future hackdays will be able to create all kinds of interesting takes on controlling Sonos devices. Bring on the Kinect and OpenCV hacks! If you build something cool, please let me know about it through e-mail or twitter.
It was the day before Startup Festival and I was just a few hours away from hopping on a red eye to Montreal. I went to United’s website to check in when I was prompted to enter my passport number. I pull out my passport and take a look at the information, expires July 8th 2011. It was July 12th—shit. My passport expired four days ago and I had a flight to catch.
I call up United and, as I suspected, they inform me that I won’t be able to fly on an expired passport. My only option was to cancel the flight, scramble to renew my passport in a day, and book a new flight tomorrow. This is how I did it.
Disclaimer: I did this in Los Angeles. The process should be the same elsewhere in the nation, but your mileage may vary. Also, I cut this close; there’s no guarantee that you’ll be able to renew your passport the same day, but it’s worth a shot.
- Make an appointment. Call up the US Passport Office and use their automated phone system to make an appointment. When I called, they gave me a date late into next week. That wouldn’t work for me so I decided to hangup and show up the next day, sans appointment. Following the appointment process is the recommended way, but I was desperate.
- Get your photo taken. An expired passport means an outdated passport photo. In order to renew your passport, you’ll need new photos. Call around to the local CVS and Walgreens. I was able to find a nearby Walgreens that had a photo department that was open until 10 PM. I went over and had two photos made. It cost me around $10. If you can’t find anything, you can go to the photo place near the Federal Building’s cafeteria the next morning. They open at 7 AM and charge $14 for two photos. (Avoid this since it would cause you to lose your place in line.)
- Fill out the renewal form. Go to the US Passport Office’s website and download the DS-82 form. Print it out and complete it ahead of time so that you’re not scrambling last minute. Don’t staple your photos to it, they’ll take care of it at the office. When filling out the form, you’ll want the passport book, not the passport card. (I accidentally checked “both” and had to change it later.)
- Print out your itinerary. In order to renew your passport at the last minute, you need to be able to prove that it’s urgent. Print our your itinerary that shows that you’re flying soon. (I attempted to use my hotel reservation, but they wanted to see a flight itinerary.)
The next morning, bring with you:
- a copy of your itinerary
- your DS-82
- your expired passport
- your wallet
- Line up early. At the time of this writing, the Los Angeles US Passport Office opens at 7 AM. (Check the website for your location’s hours.) I woke up at 5 AM and was at the office by 5:30 AM. There were three people already lined up in front of me. Get there early. If you don’t have an appointment, you’ll need to line up at the “Will Call” windows. You should be able to see them when you arrive at the Federal Building. They’re labeled “Will Call A” and “Will Call B”. There will be two lines, one at will call for people that don’t have appointments, and one at the door to the passport office for those that do have appointments.
- Make your case. At around 7 AM the window will open and they’ll take people one at a time. Be polite, show your itinerary, and explain your situation. “My passport expired and I need to fly out tonight. I don’t have an appointment, is there anything you can do?” The person will give you a ticket with a number on it and tell you to go wait in the line with people that have appointments. That ticket is essentially your appointment.
- Wait. You’ll slowly make your way through the appointment line to security. The security check is just like the one you’d find at an airport. Turn off your cell phones (this is required) and leave as much as you can in your car (don’t bring a laptop or anything more than your paperwork and old passport). Once in the building you’ll head to the Passport office and stand in another line. Eventually you’ll get to the window where the clerk will look your paperwork over and give you another ticket. You’ll then sit in the waiting area and wait for your number to be called. Cell phones and laptops are not allowed, so chat up the people next to you or bring a book—the analog kind.
- Pay the fee. Eventually, your number will be called and you’ll go up to a window. (By now it was around 9 AM.) The clerk will look over your paperwork once more and you’ll pay $110 to renew the passport and $60 to expedite the process, so $170 total. (These prices were at the time of writing, they may increase. They accept credit cards.) If everything goes well, they’ll give you a receipt with a time to come back to pick up your passport. Typically, it’s between 1 PM and 3 PM that same day. If you got this far, there’s a very good chance you’ll be getting your passport.
- Wait some more. Go grab lunch at In-n-Out and come back to the Federal Building around 2 PM. (The receipt says to show up between 1 PM and 3 PM, but they never have it ready that early.) Stand in the will call line and give the clerk your receipt. They’ll either have your passport ready, or ask you to wait a bit longer. I ended up getting mine at 3 PM, right when the Passport office closes.
There you have it, a passport in nine hours. Now, never do this again. Be prudent and renew by mail well in advance next time. Happy travels.