Archive

Posts Tagged ‘utility’

Pulling metadata out of enhanced podcasts (.m4a) and into XML

August 13th, 2009 pj4533 2 comments

puzzle_pieces300x199

For my radio show iPhone application project, I wanted to use the metadata contained in my enhanced podcast files. Including:

  • chapter information (artist/song)
  • chapter start time
  • chapter image

Once I had this information I wanted to store it in XML on my server so I could access it whenever I wanted (from the iPhone application).

Read more…

Say Goodnight Software: ceeFrenzy v1.0

July 22nd, 2009 pj4533 No comments

Submitted my first iPhone application to the app store for approval last night! Hopefully it will be approved soon! Its fairly simple, but functional…but for a very very targeted audience. Contact me if you have any problems or comments!

Description:

ceeFrenzy is a dedicated iPhone/iPod touch version of the website CollectorsFrenzy.com, developed jointly by Collectors Frenzy and Say Goodnight Software.

From the website:

Collectors Frenzy is a record price guide for collectors and dealers to get a general idea of how much an LP is worth. The price of LPs are constantly fluctuating due to supply and demand, so as buyers and sellers it can be difficult to determine whether you are over paying or under selling your records. Collectors Frenzy is a record price guide to help you obtain fair market value for your LPs.

How does Collectors Frenzy work? It gathers completed auction data off of E-Bay on a regular basis giving you the most accurate and up to date prices on LPs.

To retrieve this data simply type in an artist name, album title, etc into the search bar. To sort the data simply click on one of the search type buttons and select the method of sorting you prefer (ascending or descending).

Using bit.ly URL Shortening From ASP.NET (REST/JSON)

May 7th, 2009 pj4533 No comments

As part of my ‘learning ASP.NET’ series of posts, I thought I would discuss using the bit.ly url shortening API. I will add auto shortening to my SpiniTweet application. SpiniTweet simply takes the last song played on WMFO from Spinitron, and creates a nicely formatted tweetable string. You click, ‘Tweet This’, and then you don’t have to re-type your tracks as you are djing on air to let people know what you are playing. I like to include a link to listen to ‘MFO live via the web, in case someone wants to tune in. This is the link I want to shorten.

First off, apparently bit.ly doesn’t reuse links, so in my case I really don’t need to do this programmatically. But where is the fun in that?!?! Plus, I want to eventually add the ability for any link to be shortened in SpiniTweet, not just the WMFO listener link.

After you sign up for bit.ly, you get your API key in your profile. This is needed because they limit the total number of connects at one time. Next, check out the documentation wiki! bit.ly uses a REST api. If you really want details you can go read that linked wiki page. The bit.ly REST api is simple. We will be most interested in the ’shorten’ command, but there are others for doing things like expanding links and getting stats.

Our goal will be to send a url similar to this:
Read more…

From Windows Forms to Web Forms: Enough The Same To Be Frustrating

May 1st, 2009 pj4533 No comments

In my previous entry I created an application using C# in .NET, using windows forms. While very basic, it performs its task well. Has a ‘tweet length’ that updates when text is entered, and uses a timer to update the text of the tweet to reflect the latest song being played from your Spinitron playlist. Unfortunately, the radio station’s computers use OpenSUSE, so even my target audience (while a small one), can’t really use it without bringing in a windows machine.

All the cool kids are always talking about ASP.NET so I figured I’d take a look. I have a background in C/C++. My day job has kept me busy in a very legacy codebase for the past 10+ years. I have broadened my skill set over the years to include things like Cocoa,MFC, and .NET (windows forms). I am no Vostokov but I can hold my own in a .DMP file, and Windbg is DEFINITELY my favorite debugger. Bottom line is, I feel prepared. However, I wouldn’t know a postback from a style sheet. But, how hard can it be? :)

I decided to start by just making a web application of SpiniTweet, the radio station twitter application from my previous post. This way people at the station could use it anywhere, and it would also give me a good intro to ASP.NET. One of the books I owned had a chapter on web forms, so I decided to start there.

Turns out, it seemed one of the principals in designing web forms was to make them similar to windows forms. In fact, I was delighted to find out I could reuse my windows form code! So I quickly just banged out a simple web application version.

Launched VS2008, and SpiniTweet4Web was born! Before I touched the code, I went into the designer and quickly made a similar form. It seemed clunky, after using web forms for so long, but I noticed that it was making the html page as I added controls, so I figured it felt that way cause it was following all the rules of how a web page is arranged. I got the basics done, leaving out the countdown timer, and the tweet length for now:

Ok, so its not pretty, but whatever, I am just learning, and I can deal with that later. After getting that arranged, I took a look in the code. It seemed to make sense. Page_Load() is the same as the Form1() constructor. So I just added my initialization code there. Double-clicking the button allowed me to have a _click() handler. Fantastic! It all makes sense!

First problem I ran across is understanding the postback functionality. For example, in Page_Load(), I called ‘UpdateFromSpinitron()’ which goes and grabs the latest song played on WMFO, and formats a nice string to be tweeted. If I modify the text and click ‘Tweet This’, you’d think it would just tweet whatever was in the text box, since I query the tweetMsg text box in the button handler here:

System.Net.ServicePointManager.Expect100Continue = false;HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(TwitterJsonUrl);

string post = string.Empty;using (TextWriter writer = new StringWriter()){   String tweetMsgStr = tweetMsg.Text;

   writer.Write("status={0}", HttpUtility.UrlEncode(tweetMsgStr));   post = writer.ToString();   Console.WriteLine("Post: {0}", post);}

Not so! Each time it does a postback, it calls Page_Load() again, which calls ‘UpdateFromSpinitron’ overwriting whatever I had changed in the textbox. This was the first, of many, similar but different experiences with ASP.NET. Further, this postback reinititalizing the page seems to be a common theme throughout various controls. Seems like a common issue. You get around it by only initializing if it isn’t a postback like so:

protected void Page_Load(object sender, EventArgs e){   if (!this.IsPostBack)   {         UpdateFromSpinitron();   }   AddCharCount();}

Easy enough. Now, how do I make a twitterish tweet length counter? This is where stuff started to get difficult. Getting the feedback on a per keyup seems to be very difficult on the server side. You can do ‘Autopostbacks’, which automatically send a postback anytime the control is updated, but only when you de-focus the control is it updated, and thus posted back to the server. Further, I came to the conclusion that you really don’t WANT it to be posting back after every keyup. So what else?

Enter AJAX. What the who? Oh yeah, I think I heard about that. Google, right? Talk about behind the curve. This is what living in a legacy codebase for 10 years will do to you.

So I picked up a couple of the biggest books on ASP.NET 3.5 I could find, both had chapters on AJAX. That taught me the basics of how the implementation works. But I wasn’t able to really get my length counter working until I found this webpage. It is a fantastic tutorial talking about exactly what I needed. Apparently you can’t get away from learning javascript!

So there you have it…my first attempt at ASP.NET. You can see the complete code for my website at codeplex. And even check it out running here: www.pj4533.com/spinitweet

Just a comment, I was hoping that ASP.NET would allow an identical workflow as working with windows forms. It does look like they are pushing in that direction, but they just aren’t quite there yet. This has been exciting to learn, and I plan to write many more web apps now! I also plan to add features to SpiniTweet such as a more sexy look (CSS pages), facebook integration, and URL shortening. I’ll post up some blog entries when I do so!

Categories: Techniques Tags: , , ,

Writing a twitter client in C#

April 28th, 2009 pj4533 No comments

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!