public Scrobble(string trackData) { List<string> trackDataList = trackData.Split('-').ToList(); if (trackDataList.Count > 0) { string artist = trackDataList[0]; string title = string.Empty; for (int i = 1; i < trackDataList.Count; i++) { title += trackDataList[i]; } Scrobbler scrobbler = new Scrobbler("0a5674077da2782718075412eab00800", "56668ad9e4293be48def8f5ab1a6c658"); Track track = new Track {ArtistName = artist, TrackName = title}; ScrobbleResponse response = scrobbler.Scrobble(track); ErrorMessage = response.Exception.Message + " " + response.ErrorCode.ToString(); } else { ErrorMessage = trackDataList.Count.ToString(); } }
public void Scrobble(ScrobbleMe scrobbleMe) { if (CheckForSession()) { try { var scrobTrack = new Track { TrackName = scrobbleMe.ZuneTrack.Title, ArtistName = scrobbleMe.ZuneTrack.Artist, WhenStartedPlaying = scrobbleMe.TimeStarted, Duration = TimeSpan.FromSeconds(scrobbleMe.ZuneTrack.Length) }; var resp = _scrobbler.Scrobble(scrobTrack); Debug.WriteLine("successfully scrobbled: " + resp.Track.TrackName); Logger.Send(LogLevel.Info, "Successfully scrobbled: " + resp.Track.TrackName); } catch (LastFmApiException exception) { if (exception.ErrorCode == 9) // re-authenticate { Reauthenticate(); return; } Logger.Send(LogLevel.Error, "Scrobble was unsuccessful", exception); } catch (InvalidOperationException exception) { //occurs when the scrobble has been sent before it should have been Logger.Send(LogLevel.Error, "Scrobble was unsuccessful", exception); } } }
/// <summary> /// Enqueues a UnLove request but does not send it. Call <see cref="Process"/> to send /// </summary> /// <param name="track">The <see cref="Track"/> that has played</param> /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed.</remarks> public void UnLove(Track track) { RatingQueue.Enqueue(new RatingObject() { Track = track, RatingType = Rating.unlove }); }
/// <summary> /// Enqueues a UnBan request but does not send it. Call <see cref="Process"/> to send /// </summary> /// <param name="track">The <see cref="Track"/> that has played</param> /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed.</remarks> public void UnBan(Track track) { RatingQueue.Enqueue(new RatingObject() { Track = track, RatingType = Rating.unban }); }
/// <summary> /// Enqueues a Srobble request but does not send it. Call <see cref="Process"/> to send /// </summary> /// <param name="track">The <see cref="Track"/> that has played</param> /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed. You should validate the Track before calling Scrobble</remarks> public void Scrobble(Track track) { ScrobbleQueue.Enqueue(track); }
/// <summary> /// Enqueues a NowPlaying request but does not send it. Call <see cref="Process"/> to send /// </summary> /// <param name="track">The <see cref="Track"/> that is now playing</param> /// <remarks>This method is thread-safe. Will not check for invalid tracks until Processed. You should validate the Track before calling NowPlaying</remarks> public void NowPlaying(Track track) { NowPlayingQueue.Enqueue(track); }
private Track QuerySongToTrack(QuerySong song) { var track = new Track { TrackName = song.Title, AlbumName = song.Album, ArtistName = song.Artist, }; return track; }
private Track QueryProgressToTrack(QueryProgress prog) { var track = new Track { TrackName = prog.Song.Title, AlbumName = prog.Song.Album, ArtistName = prog.Song.Artist, Duration = prog.Progress.TotalTime, WhenStartedPlaying = DateTime.Now.Subtract(prog.Progress.ElapsedTime), }; return track; }
/// <summary> /// Submits a Track Ban request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="RatingResponse"/></returns> /// <remarks>The <see cref="Track"/> passed in must be a "Corrected Track" as /// returned in <see cref="ScrobbleResponse"/> or <see cref="NowPlayingResponse"/> public RatingResponse Ban(Track track) { var result = TrackApi.Ban(track, Authentication); result.Track = track; return result; }
/// <summary> /// Submits a Track Scrobble request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="ScrobbleResponse"/></returns> /// <remarks>A track should only be scrobbled when the following conditions have been met: The track must be longer than 30 seconds. /// And the track has been played for at least half its duration, or for 4 minutes (whichever occurs earlier). See http://www.last.fm/api/scrobbling </remarks> /// <exception cref="InvalidOperationException"/> public ScrobbleResponse Scrobble(Track track) { if (track.Duration.TotalSeconds < MinimumScrobbleTrackLengthInSeconds) { throw new InvalidOperationException(string.Format("Duration is too short. Tracks shorter than {0} seconds in duration must not be scrobbled", MinimumScrobbleTrackLengthInSeconds)); } if (!track.WhenStartedPlaying.HasValue) throw new ArgumentException("A Track must have a WhenStartedPlaying value when Scrobbling"); int minimumPlayingTime = (int) track.Duration.TotalSeconds/2; if (minimumPlayingTime > (4*60)) minimumPlayingTime = (4*60); if (track.WhenStartedPlaying > DateTime.Now.AddSeconds(-minimumPlayingTime)) { throw new InvalidOperationException( "Track has not been playing long enough. A scrobbled track must have been played for at least half its duration, or for 4 minutes (whichever occurs earlier)"); } return TrackApi.Scrobble(track, Authentication); }
/// <summary> /// Submits a Track Update Now Playing request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="NowPlayingResponse"/></returns> public NowPlayingResponse NowPlaying(Track track) { return TrackApi.UpdateNowPlaying(track, Authentication); }
public void SubmitNowPlaying(ZuneTrack track) { if (CheckForSession()) { try { var scrobTrack = new Track { TrackName = track.Title, ArtistName = track.Artist, Duration = TimeSpan.FromSeconds(track.Length) }; var resp = _scrobbler.NowPlaying(scrobTrack); Debug.WriteLine("successfully sent now playing: " + resp.Track.TrackName); } catch (LastFmApiException exception) { if (exception.ErrorCode == 9) // re-authenticate { Reauthenticate(); return; } //log unsuccessfull now playing Logger.Send(LogLevel.Error, "Submit now playing was unsuccessful", exception); } } }
private static Track WmpMediaToTrack(IWMPMedia media) { // Get meta data from media as track using TagLib sharp File fileTag = File.Create(media.sourceURL); var track = new Track { TrackName = fileTag.Tag.Title, AlbumName = fileTag.Tag.Album, ArtistName = fileTag.Tag.JoinedPerformers, TrackNumber = (int) fileTag.Tag.Track, Duration = new TimeSpan(0, 0, 0, (int) media.duration) }; return track; }
private void WindowsMediaPlayer_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e) { try { var doProcessScrobbles = new ProcessScrobblesDelegate(ProcessScrobbles); switch (WindowsMediaPlayer.playState) { case WMPPlayState.wmppsPlaying: // Convert the media player media info to a Track. Store the track in a property so that is can be scrobbled // when media ended. At that time WindowsMediaPlayer.currentMedia will be null. This is not fool-proof and // is demo code only CurrentTrack = WmpMediaToTrack(WindowsMediaPlayer.currentMedia); CurrentTrack.WhenStartedPlaying = DateTime.Now; // we are using the Queuing scrobbler here so that we don't block the form while the scrobble request is being sent // to the Last.fm web service. The request will be sent when the Process() method is invoked _scrobbler.NowPlaying(CurrentTrack); // Begin invoke with no callback fires and forgets the scrobbler process. Processing runs asynchronously while // the form thread continues doProcessScrobbles.BeginInvoke(null, null); break; case WMPPlayState.wmppsMediaEnded: // Scrobble the track that just finished _scrobbler.Scrobble(CurrentTrack); doProcessScrobbles.BeginInvoke(null, null); break; } } catch (Exception exception) { MessageBox.Show(exception.Message); } }