Program: Currently Listening to now live

Ok, So I have iTunes running here at work, and I have Typepad running. So now the two of them are working together. This program below will update TypePad list of songs with the latest tunes you are listening to. You will need to instert your List ID, Username, and Password instead of the ************’s.

Enjoy.

using System;
using System.Text;
using System.Net;
using iTunesLib;
namespace tjtTypePad
{
class iTunesPlayedTracksUpdater
{
private static void handler_PlayEvent(object o)
{
// Get the track
IITTrack track = (IITTrack)o;
string linkTitle = track.TrackNumber + ". " + track.Name + " (" + track.Artist + ")";
Console.WriteLine("Updating most recent track: " + linkTitle);
int myRating = track.Rating / 20;
// create and fetch the url, which updates the links
string url = "https://www.typepad.com/t/app/lists?__mode=save_item&list_id=************&song=" + track.Name;
url = url +  "&artist=" + track.Artist + "&Album=" + track.Album + "&rating=" + myRating + "&username=************&password=************&remember=1";
// Console.WriteLine(url);
WebRequest wr = WebRequest.Create(url);
WebResponse r = wr.GetResponse();
// we don't care about the actual response, so close it.
r.Close();
}
[STAThread]
static void Main(string[] args)
{
// Create the object for interacting with iTunes
iTunesApp app = new iTunesAppClass();
// Binds our function to be called whenever a new track is played
app.OnPlayerPlayEvent += new iTunesLib._IiTunesEvents_OnPlayerPlayEventEventHandler(handler_PlayEvent);
while (true)
{  // loop endlessly
System.Threading.Thread.Sleep(1000); // sleep so we don't hog CPU
}
}
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s