I have a radio show at WMFO, at Tufts University. Its a community/college radio station, and completely freeform! For those interested, you can check my radio show website galacticfractures.com, for downloadable shows and whatnot.
At any rate, I wanted to be able to tweet songs as I played them, including a link to our online stream, so people could easily tune in. I did it by hand for a few weeks (on facebook), but it got to be a pain because we already type in songs into a website called Spinitron.com. Effectively I was typing in songs twice, while I was attempting to dj!
I did some digging around and Spinitron publishes a few RSS feeds for each station it supports. One of the feeds is based on the ‘current’ playlist, so it made it very easy to figure out the most recently entered song. See here:
private void UpdateFromSpinitron() { XmlDocument doc = new XmlDocument();
HttpWebRequest request = WebRequest.Create(SpinitronRSSUrl) as HttpWebRequest;
String currentPlaying = ""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); doc.Load(reader); XmlNodeList nodelist = doc.SelectNodes("/rss/channel/item"); XmlNode currentPlayingNode = nodelist[0].SelectSingleNode("title");
currentPlaying = currentPlayingNode.InnerText; currentPlaying = currentPlaying.Replace(":"," -"); currentPlaying = currentPlaying.Replace("'", ""); } tweetMsg.Text = "Now Playing: " + currentPlaying + " (Listen Live @ WMFO.org: http://bit.ly/lOAWA)"; }
Unfortunately, Spinitron’s XML feed is craaaaaaaaap. The “description” node contains ALL the information?!?! Why use XML at all then!? Spread them nodes out, man! Anyway, I was only interested in the artist and title (which are both in the “title” node, ugg).
From there, I just threw it on a 10 second timer to query the XML feed for the latest track. I didn’t want it to automatically tweet the song, however, cause I think that could get noisy and be rude to your followers. I instead put a button for tweeting of the song. Maybe you do only every few songs? Whatever…enough to keep people interested.
Lastly, I borrow some code for sending the tweet…but it was real simple. Basically just opening a connection to the twitter url and sending it on! They make it real simple to send tweets, I didn’t even have to mess with the twitter API or anything.
I put the project up on codeplex here: http://spinitweet.codeplex.com/
EDIT: It occured to me that I wasn’t quite clear on my comments regarding Spinitrons XML feeds. I think I understand why they didn’t break it up beyond Title/Description. Obviously they were fitting RSS. However, why even make XML for this? Noone would read a RSS feed of that in Google Reader, for example. It would make more sense to do a RSS feed of a given users shows, and have the description be the nicely formatted complete playlist. Spinitron even says:
“An RSS feed for an individual playlist isn’t really in the spirit of RSS
because, unless it happens to be the current playlist, it’s not likely to change
like news or blog feeds do. But it may be useful to someone using a script to
grab the playlist data and process it because RSS XML should be easier to parse
than HTML playlist pages.”
So if the point is to allow people to parse the playlists, don’t worry about RSS, and just give me a better broken down XML file!