Ejemplo n.º 1
0
		/// <summary>
		/// A handshake is performed at the beginning to retrieve the 
		/// SessionID, SubmissionURL and NowplayingURL and also everytime the server
		/// reports that the SessionID is invalid.
		/// </summary>
		private void doHandshake()
		{
			Request request = new Request(new Uri("http://post.audioscrobbler.com:80/"), handshakeParameters);
			
			string[] response = request.execute().Split('\n');
			
			SessionID = response[1];
			NowplayingURL = new Uri(response[2]);
			SubmissionURL = new Uri(response[3]);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// The internal scrobble function, scrobbles pure request parameters.
		/// Could be for more than one track, as specified by Last.fm, but they recommend that
		/// only one track should be submitted at a time.
		/// </summary>
		/// <param name="parameters">
		/// A <see cref="RequestParameters"/>
		/// </param>
		internal void Scrobble(RequestParameters parameters)
		{
			Initialize();
			
			parameters["s"] = SessionID;			
			Request request = new Request(this.SubmissionURL, parameters);

			// A BadSessionException occurs when another client has made a handshake
			// with this user's credentials, should redo a handshake and pass this 
			// exception quietly.
			try
			{
				request.execute();
			} catch (BadSessionException) {
				this.doHandshake();
				this.Scrobble(parameters);
			}
		}			
Ejemplo n.º 3
0
		/// <summary>
		/// Send the now playing notification.
		/// </summary>
		/// <param name="track">
		/// A <see cref="NowplayingTrack"/>
		/// </param>
		public void ReportNowplaying(NowplayingTrack track)
		{
			Initialize();
			
			RequestParameters p = new RequestParameters();
			p["s"] = SessionID;
			p["a"] = track.Artist;
			p["t"] = track.Title;
			p["b"] = track.Album;

			if (track.Duration.TotalSeconds == 0)
				p["l"] = "";
			else
				p["l"] = track.Duration.TotalSeconds.ToString();
			
			if (track.Number == 0)
				p["n"] = "";
			else
				p["n"] = track.Number.ToString();
			
			p["m"] = track.MBID;

			Request request = new Request(this.NowplayingURL, p);

			// A BadSessionException occurs when another client has made a handshake
			// with this user's credentials, should redo a handshake and pass this 
			// exception quietly.
			try
			{
				request.execute();
			} catch (BadSessionException) {
				this.doHandshake();
				this.ReportNowplaying(track);
			}
		}