public void ScrobbleToLastFM(DateTime whenStartedPlaying, Domain.Objects.Track info) { Console.WriteLine("Scrobble to last FM"); if (System.Diagnostics.Debugger.IsAttached) { return; } Task.Factory.StartNew(() => { lock (scrobbler) // make sure no requests are run at the same time { try { var track = GetLastFmTrackFromAudioInfo(info); track.WhenStartedPlaying = whenStartedPlaying; var response = scrobbler.Scrobble(track); if (response.ErrorCode > 0) { Console.Error.WriteLine("Unable to scrobble track " + info.Artists.FirstOrDefault() + " - " + info.Title + " to Last FM" + ": " + response.Exception.Message); } } catch (Exception ex) { Console.Error.WriteLine("Unable to scrobble track " + info.Artists.FirstOrDefault() + " - " + info.Title + " to Last FM" + ": " + ex.Message); } } }); }
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(); } }
private void SetupChannel() { var observablePlaylist = ((IObservablePlaylistProvider)_client.SubscribedChannelHandler.Playlist); playlist = (ListCollectionView)(CollectionViewSource.GetDefaultView(observablePlaylist.Songs)); playlist.CustomSort = new SongComparer(); _player.PlayingSongChanged_Toast = (songID, playing) => { var song = observablePlaylist.Songs.FirstOrDefault(x => x.SongID == songID); if (song == null) { return; } song.Playing = playing; if (!playing) { return; } if (_settings.SongToasts) { toast.NewSong(song.track); } }; _player.ScrobbleSong = (songID, playing) => { var song = observablePlaylist.Songs.FirstOrDefault(x => x.SongID == songID); if (song == null) { return; } if (_settings.Scrobbling) { _scrobbler.Scrobble(song, playing); } }; // TODO: Is this bad? Seems like it's a recipe for leaking - probably holds a ref to playlist.Songs and handler.Chats synchronization.Send((_) => { BindingOperations.EnableCollectionSynchronization(observablePlaylist.Songs, observablePlaylist.Songs); BindingOperations.EnableCollectionSynchronization(_client.SubscribedChannelHandler.Chats, _client.SubscribedChannelHandler.Chats); }, null); chatbox.ItemsSource = _client.SubscribedChannelHandler.Chats; observablePlaylist.PropertyChanged += OnObservablePlaylistOnPropertyChanged; BindToPlaylist(); }
public void RunAfterPlayCountUp(int rating) { if (_scrobbler == null) { return; } _scrobbler.Scrobble(CurrentTrack); if (rating == 9) { _scrobbler.Love(CurrentTrack); } else { _scrobbler.UnLove(CurrentTrack); } }
public void Scrobble_TestTrack_NoException() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret, SessionKey); var track = new Track { TrackName = "Spying Glass", AlbumArtist = "Massive Attack", ArtistName = "Massive Attack", AlbumName = "Protection", Duration = new TimeSpan(0, 0, 5, 21), TrackNumber = 5, }; track.WhenStartedPlaying = DateTime.Now.Subtract(track.Duration); // Act var response = scrobbler.Scrobble(track); }
/* * public static void SetRegistrySetting(string valueName, string value) { * if (string.IsNullOrEmpty(valueName)) throw new ArgumentException("valueName cannot be empty or null", "valueName"); * valueName = valueName.Trim(); * * Registry.SetValue(LpfmRegistryNameSpace, valueName, value); * }*/ public void Send(int type, string title, string artist, int duration) { try { if (type == 0) // NowPlaying // Send { CurrentTrack.TrackName = title; CurrentTrack.ArtistName = artist; CurrentTrack.WhenStartedPlaying = DateTime.Now; CurrentTrack.Duration = new TimeSpan(0, 0, duration); _scrobbler.NowPlaying(CurrentTrack); } else if (type == 1) // NowPlaying { _scrobbler.Scrobble(CurrentTrack); } } catch (Exception exception) { Console.WriteLine(exception.Message); } }
public void Scrobble_TestTrack_NoException() { // Arrange var scrobbler = new Scrobbler(ApiKey, ApiSecret, SessionKey); var track = new Track { TrackName = "Spying Glass", AlbumArtist = "Massive Attack", ArtistName = "Massive Attack", AlbumName = "Protection", Duration = new TimeSpan(0, 0, 5, 21), TrackNumber = 5, }; track.WhenStartedPlaying = DateTime.Now.Subtract(track.Duration); // Act var response = scrobbler.Scrobble(track); }