Skip to content

Instantly share code, notes, and snippets.

@TedTschopp
Created October 3, 2023 17:45
Show Gist options
  • Save TedTschopp/43e73fa49d77484d457d4d352a84289a to your computer and use it in GitHub Desktop.
Save TedTschopp/43e73fa49d77484d457d4d352a84289a to your computer and use it in GitHub Desktop.
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
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment