/// <summary> /// Update now playing track on Last.FM /// </summary> /// <param name="Artist"></param> /// <param name="Title"></param> /// <param name="seconds"></param> public void NowPlaying(string Artist, string Title, int seconds) { if (!IsLoged) { return; } try { if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title) && seconds > 0) { RequestParameters nowPlayingParameters = new RequestParameters(); nowPlayingParameters["track"] = Title; nowPlayingParameters["artist"] = Artist; nowPlayingParameters["duration"] = seconds.ToString(); Request nowplaying = new Request("track.updateNowPlaying", Session, nowPlayingParameters); XmlDocument doc = nowplaying.execute(); // Check the status XmlNode n = doc.GetElementsByTagName("lfm")[0]; string status = n.Attributes[0].InnerText; logger.Debug("Call to track.updateNowPlaying : " + status); trackStartTime = DateTime.Now; } } catch (Exception exception) { logger.DebugException("Error with Nowplayin", exception); } }
/// <summary> /// Complete the web authentication. /// </summary> public void AuthenticateViaWeb() { RequestParameters p = new RequestParameters(); p["token"] = token; Request r = new Request("auth.getSession", this, p); r.signIt(); XmlDocument doc = r.execute(); SessionKey = doc.GetElementsByTagName("key")[0].InnerText; }
/// <summary> /// Authenticate this session using a username and a md5 hash of the password. /// </summary> /// <param name="username"> /// A <see cref="System.String"/> /// </param> /// <param name="md5Password"> /// A <see cref="System.String"/> /// </param> public void Authenticate(string username, string md5Password) { RequestParameters p = new RequestParameters(); p["username"] = username; p["authToken"] = LastFMScrobble.MD5(username + md5Password); Request request = new Request("auth.getMobileSession", this, p); request.signIt(); XmlDocument doc = request.execute(); SessionKey = doc.GetElementsByTagName("key")[0].InnerText; }
/// <summary> /// Submit track to Last.FM Library /// </summary> /// <param name="Artist"></param> /// <param name="Title"></param> public void Submit(string Artist, string Title, int Seconds) { // Check how much of track was played if less than 50% do not submit TimeSpan playTime = DateTime.Now - trackStartTime; logger.Debug("Last.FM Submit: {0} {1}", playTime.Seconds.ToString(), (Seconds / 2).ToString()); if (playTime.Seconds < (Seconds / 2)) { return; } if (!IsLoged) { return; } try { if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title)) { RequestParameters submitParameters = new RequestParameters(); submitParameters["artist"] = Artist; submitParameters["track"] = Title; submitParameters["timestamp"] = calculateSeconds(trackStartTime).ToString(); Request nowplaying = new Request("track.scrobble", Session, submitParameters); XmlDocument doc = nowplaying.execute(); // Check the Status XmlNode n = doc.GetElementsByTagName("lfm")[0]; string status = n.Attributes[0].InnerText; logger.Debug("Call to track.scrobble : " + status); } } catch (Exception exception) { logger.DebugException("Error in Submit", exception); } }
/// <summary> /// Submit track to Last.FM Library /// </summary> /// <param name="Artist"></param> /// <param name="Title"></param> public void Submit(string Artist, string Title, int Seconds) { // Check how much of track was played if less than 50% do not submit TimeSpan playTime = DateTime.Now - trackStartTime; logger.Debug("Last.FM Submit: {0} {1}", playTime.Seconds.ToString(), (Seconds / 2).ToString()); if (playTime.Seconds < (Seconds / 2)) return; if (!IsLoged) return; try { if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title)) { RequestParameters submitParameters = new RequestParameters(); submitParameters["artist"] = Artist; submitParameters["track"] = Title; submitParameters["timestamp"] = calculateSeconds(trackStartTime).ToString(); Request nowplaying = new Request("track.scrobble", Session, submitParameters); XmlDocument doc = nowplaying.execute(); // Check the Status XmlNode n = doc.GetElementsByTagName("lfm")[0]; string status = n.Attributes[0].InnerText; logger.Debug("Call to track.scrobble : " + status); } } catch (Exception exception) { logger.DebugException("Error in Submit",exception); } }
/// <summary> /// Update now playing track on Last.FM /// </summary> /// <param name="Artist"></param> /// <param name="Title"></param> /// <param name="seconds"></param> public void NowPlaying(string Artist, string Title, int seconds) { if (!IsLoged) return; try { if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title) && seconds > 0) { RequestParameters nowPlayingParameters = new RequestParameters(); nowPlayingParameters["track"] = Title; nowPlayingParameters["artist"] = Artist; nowPlayingParameters["duration"] = seconds.ToString(); Request nowplaying = new Request("track.updateNowPlaying", Session, nowPlayingParameters); XmlDocument doc = nowplaying.execute(); // Check the status XmlNode n = doc.GetElementsByTagName("lfm")[0]; string status = n.Attributes[0].InnerText; logger.Debug("Call to track.updateNowPlaying : " + status); trackStartTime = DateTime.Now; } } catch (Exception exception) { logger.DebugException("Error with Nowplayin", exception); } }