Esempio n. 1
0
        /// <summary>
        /// Scrobbles the selected tracks.
        /// </summary>
        public override async Task Scrobble()
        {
            EnableControls = false;

            try
            {
                OnStatusUpdated("Trying to scrobble selected tracks...");

                var response = await Scrobbler.ScrobbleAsync(CreateScrobbles());

                if (response.Success)
                {
                    OnStatusUpdated("Successfully scrobbled!");
                }
                else
                {
                    OnStatusUpdated("Error while scrobbling!");
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated("An error occurred while trying to scrobble the selected tracks. Error: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
        /// <summary>
        /// Scrobbles the track with the given info.
        /// </summary>
        public override async Task Scrobble()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated(string.Format("Trying to scrobble '{0}'...", Track));

                var scrobble = CreateScrobbles().First();
                var response = await Scrobbler.ScrobbleAsync(scrobble);

                if (response.Success && response.Status == LastResponseStatus.Successful)
                {
                    OnStatusUpdated(string.Format("Successfully scrobbled '{0}'", scrobble.Track));
                }
                else
                {
                    OnStatusUpdated(string.Format("Error while scrobbling '{0}': {1}", scrobble.Track, response.Status));
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated("Fatal error while trying to scrobble: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Scrobbles the selected tracks.
        /// </summary>
        public override async Task Scrobble()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated("Trying to scrobble selected tracks...");

                var response = await Scrobbler.ScrobbleAsync(CreateScrobbles());

                if (response.Success && response.Status == LastResponseStatus.Successful)
                {
                    OnStatusUpdated("Successfully scrobbled selected tracks");
                }
                else
                {
                    OnStatusUpdated(string.Format("Error while scrobbling selected tracks: {0}", response.Status));
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated(string.Format("Fatal error while trying to scrobble selected tracks: {0}", ex.Message));
            }
            finally
            {
                EnableControls = true;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Scrobbles the track with the given info.
        /// </summary>
        public override async Task Scrobble()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated($"Trying to scrobble '{Track}'...");

                var scrobble = CreateScrobbles().First();
                var response = await Scrobbler.ScrobbleAsync(scrobble);

                if (response.Success && response.Status == LastResponseStatus.Successful)
                {
                    OnStatusUpdated($"Successfully scrobbled '{scrobble.Track}'");
                }
                else
                {
                    OnStatusUpdated($"Error while scrobbling '{scrobble.Track}': {response.Status}");
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated($"Fatal error while trying to scrobble: {ex.Message}");
            }
            finally
            {
                EnableControls = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Scrobbles the track with the given info.
        /// </summary>
        public override async Task Scrobble()
        {
            try
            {
                EnableControls = false;
                OnStatusUpdated("Trying to scrobble...");

                Scrobble s = new Scrobble(Artist, Album, Track, Time)
                {
                    AlbumArtist = AlbumArtist, Duration = Duration
                };
                var response = await Scrobbler.ScrobbleAsync(s);

                if (response.Success && response.Status == LastResponseStatus.Successful)
                {
                    OnStatusUpdated(string.Format("Successfully scrobbled '{0}'", s.Track));
                }
                else
                {
                    OnStatusUpdated(string.Format("Error while scrobbling '{0}': {1}", s.Track, response.Status));
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated("Fatal error while trying to scrobble: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
        /// <summary>
        /// Scrobbles the track with the given info.
        /// </summary>
        public override async Task Scrobble()
        {
            EnableControls = false;

            try
            {
                OnStatusUpdated("Trying to scrobble...");

                Scrobble s = new Scrobble(Artist, Album, Track, Time)
                {
                    AlbumArtist = AlbumArtist, Duration = Duration
                };
                var response = await Scrobbler.ScrobbleAsync(s);

                if (response.Success)
                {
                    OnStatusUpdated("Successfully scrobbled!");
                }
                else
                {
                    OnStatusUpdated("Error while scrobbling!");
                }
            }
            catch (Exception ex)
            {
                OnStatusUpdated("Fatal error while trying to scrobble: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
        /// <summary>
        /// Scrobbles the current song.
        /// </summary>
        /// <returns>Task.</returns>
        public override async Task Scrobble()
        {
            if (EnableControls && CanScrobble)
            {
                EnableControls = false;
                Scrobble s = null;
                try
                {
                    OnStatusUpdated(string.Format("Trying to scrobble '{0}'...", CurrentTrackName));

                    // lock while acquiring current data
                    lock (_lockAnchor)
                    {
                        // try to get AlbumArtist
                        string albumArtist = string.Empty;
                        try
                        {
                            albumArtist = (ITunesApp.CurrentTrack as dynamic).AlbumArtist;
                        }
                        catch (RuntimeBinderException)
                        {
                            // swallow, AlbumArtist doesn't exist for some reason.
                        }

                        s = new Scrobble(CurrentArtistName, CurrentAlbumName, CurrentTrackName, DateTime.Now)
                        {
                            Duration    = TimeSpan.FromSeconds(CurrentTrackLength),
                            AlbumArtist = albumArtist
                        };
                    }

                    var response = await Scrobbler.ScrobbleAsync(s, true);

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        OnStatusUpdated(string.Format("Successfully scrobbled '{0}'", s.Track));
                    }
                    else if (response.Status == LastResponseStatus.Cached)
                    {
                        OnStatusUpdated(string.Format("Scrobbling '{0}' failed. Scrobble has been cached", s.Track));
                    }
                    else
                    {
                        OnStatusUpdated(string.Format("Error while scrobbling '{0}': {1}", s.Track, response.Status));
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated(string.Format("Fatal error while trying to scrobble '{0}': {1}", s?.Track, ex.Message));
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Scrobbles the current song.
        /// </summary>
        /// <returns>Task.</returns>
        public override async Task Scrobble()
        {
            if (EnableControls && CanScrobble)
            {
                EnableControls = false;

                try
                {
                    OnStatusUpdated("Trying to scrobble currently playing track...");

                    // try to get AlbumArtist
                    string albumArtist = string.Empty;
                    try
                    {
                        albumArtist = (ITunesApp.CurrentTrack as dynamic).AlbumArtist;
                    }
                    catch (RuntimeBinderException)
                    {
                        // swallow, AlbumArtist doesn't exist for some reason.
                    }

                    Scrobble s = new Scrobble(CurrentArtistName, CurrentAlbumName, CurrentTrackName, DateTime.Now)
                    {
                        Duration    = TimeSpan.FromSeconds(CurrentTrackLength),
                        AlbumArtist = albumArtist
                    };
                    var response = await Scrobbler.ScrobbleAsync(s);

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        OnStatusUpdated(string.Format("Successfully scrobbled {0}!", CurrentTrackName));
                    }
                    else if (response.Status == LastResponseStatus.Cached)
                    {
                        OnStatusUpdated(string.Format("Scrobbling of track {0} failed. Scrobble has been cached", CurrentTrackName));
                    }
                    else
                    {
                        OnStatusUpdated("Error while scrobbling: " + response.Status);
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated("Fatal error while trying to scrobble currently playing track. Error: " + ex.Message);
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
Esempio n. 9
0
        public async Task ScrobblesMultiple()
        {
            var scrobbles = GenerateScrobbles(4);

            var countingHandler = new CountingHttpClientHandler();
            var httpClient      = new HttpClient(countingHandler);
            var scrobbler       = new Scrobbler(Lastfm.Auth, httpClient)
            {
                MaxBatchSize = 2
            };
            var response = await scrobbler.ScrobbleAsync(scrobbles);

            Assert.AreEqual(2, countingHandler.Count);
            Assert.AreEqual(LastResponseStatus.Successful, response.Status);
            Assert.IsTrue(response.Success);
        }
Esempio n. 10
0
        /// <summary>
        /// Scrobbles the track entered in the textBoxes.
        /// </summary>
        private async void btnScrobble_Click(object sender, EventArgs e)
        {
            UpdateTimes(sender, e);
            lblScrobbleStatusInfo.Text = "Trying to scrobble.";
            dateTimePicker1.Value      = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, dateTimePicker2.Value.Second);
            Scrobble s        = new Scrobble(textBoxArtist.Text, textBoxAlbum.Text, textBoxTrack.Text, dateTimePicker1.Value);
            var      response = await _scrobbler.ScrobbleAsync(s);

            if (response.Success)
            {
                lblScrobbleStatusInfo.Text = "Successfully scrobbled.";
            }
            else
            {
                lblScrobbleStatusInfo.Text = "Failed to scrobble.";
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Scrobbles the selected scrobbles.
        /// </summary>
        /// <returns>Task.</returns>
        public override async Task Scrobble()
        {
            EnableControls = false;
            OnStatusUpdated("Trying to scrobble selected tracks...");

            var response = await Scrobbler.ScrobbleAsync(CreateScrobbles());

            if (response.Success)
            {
                OnStatusUpdated("Successfully scrobbled!");
            }
            else
            {
                OnStatusUpdated("Error while scrobbling!");
            }

            EnableControls = true;
        }
Esempio n. 12
0
        public async void ScrobbleTrack(string artist, string album, string track)
        {
            var        trackApi = new TrackApi(_auth);
            var        scrobble = new Scrobble(artist, album, track, DateTimeOffset.Now);
            IScrobbler _scrobbler;

            _scrobbler = new Scrobbler(_auth);
            var response = await _scrobbler.ScrobbleAsync(scrobble);

            if (response.Success)
            {
                Debug.WriteLine("Scrobble success!");
            }
            else
            {
                Debug.WriteLine("Scrobble failed!");
            }
        }
        /// <summary>
        /// Scrobbles the currently playing track.
        /// </summary>
        /// <returns>Task.</returns>
        public override async Task Scrobble()
        {
            if (CanScrobble && !_currentResponse.Track.IsAd())
            {
                EnableControls = false;

                Scrobble s = null;
                try
                {
                    OnStatusUpdated($"Trying to scrobble '{CurrentTrackName}'...");
                    // lock while acquiring current data
                    lock (_lockAnchor)
                    {
                        s = new Scrobble(CurrentArtistName, CurrentAlbumName, CurrentTrackName, DateTime.Now)
                        {
                            Duration = TimeSpan.FromSeconds(CurrentTrackLength),
                        };
                    }

                    var response = await Scrobbler.ScrobbleAsync(s, true);

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        OnStatusUpdated($"Successfully scrobbled '{s.Track}'");
                    }
                    else if (response.Status == LastResponseStatus.Cached)
                    {
                        OnStatusUpdated($"Scrobbling '{s.Track}' failed. Scrobble has been cached");
                    }
                    else
                    {
                        OnStatusUpdated($"Error while scrobbling '{s.Track}': {response.Status}");
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated($"Fatal error while trying to scrobble '{s.Track}: {ex.Message}");
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
Esempio n. 14
0
        private async void SyncScrobblesClick(object sender, RoutedEventArgs e)
        {
            var progress = await this.ShowProgressAsync("Syncing...", "Scrobbling selected tracks...");

            var scrobbles    = leftListView.SelectedItems.Cast <LastTrack>().ToList();
            var newScrobbles = scrobbles.Where(o => o.TimePlayed != null && !GinaScrobbles.Any(p => p.TimePlayed == o.TimePlayed));
            var list         = newScrobbles.Select(o => new Scrobble(o.ArtistName, o.AlbumName, o.Name, o.TimePlayed.Value)
            {
                ChosenByUser = true, Duration = o.Duration
            }).ToList();
            var scrobbler = new Scrobbler(client.Auth);
            var res       = await scrobbler.ScrobbleAsync(list);

            await progress.CloseAsync();

            await this.ShowMessageAsync("Syncing finished!", $"Synced {list.Count} scrobbles.");

            ReloadScrobbles();
        }
Esempio n. 15
0
        /// <summary>
        /// Scrobbles the currently playing track.
        /// </summary>
        /// <returns>Task.</returns>
        public override async Task Scrobble()
        {
            if (CanScrobble && !_currentResponse.Track.IsAd())
            {
                EnableControls = false;

                try
                {
                    OnStatusUpdated("Trying to scrobble currently playing track...");

                    Scrobble s = new Scrobble(CurrentArtistName, CurrentAlbumName, CurrentTrackName, DateTime.Now)
                    {
                        Duration = TimeSpan.FromSeconds(CurrentTrackLength),
                    };

                    var response = await Scrobbler.ScrobbleAsync(s);

                    if (response.Success && response.Status == LastResponseStatus.Successful)
                    {
                        OnStatusUpdated(string.Format("Successfully scrobbled {0}!", CurrentTrackName));
                    }
                    else if (response.Status == LastResponseStatus.Cached)
                    {
                        OnStatusUpdated(string.Format("Scrobbling of track {0} failed. Scrobble has been cached", CurrentTrackName));
                    }
                    else
                    {
                        OnStatusUpdated("Error while scrobbling: " + response.Status);
                    }
                }
                catch (Exception ex)
                {
                    OnStatusUpdated("Fatal error while trying to scrobble currently playing track. Error: " + ex.Message);
                }
                finally
                {
                    EnableControls = true;
                }
            }
        }
Esempio n. 16
0
        protected async Task <ScrobbleResponse> ExecuteTestInternal(IEnumerable <Scrobble> testScrobbles, HttpResponseMessage responseMessage, HttpRequestMessage expectedRequestMessage = null)
        {
            FakeResponseHandler.Enqueue(responseMessage);

            var scrobbleResponse = await Scrobbler.ScrobbleAsync(testScrobbles);

            if (expectedRequestMessage != null)
            {
                var actualRequestMessage = FakeResponseHandler.Sent.First();
                TestHelper.AssertSerialiseEqual(expectedRequestMessage.Headers, actualRequestMessage.Item1.Headers);
                TestHelper.AssertSerialiseEqual(expectedRequestMessage.RequestUri, actualRequestMessage.Item1.RequestUri);

                var expectedRequestBody = await expectedRequestMessage.Content.ReadAsStringAsync();

                var actualRequestBody = actualRequestMessage.Item2;
                TestHelper.AssertSerialiseEqual(expectedRequestBody, actualRequestBody);
            }

            FakeResponseHandler.Sent.Clear();

            return(scrobbleResponse);
        }
Esempio n. 17
0
 public Task <ScrobbleResponse> ScrobbleAsync(Scrobble scrobble)
 {
     return(_scrobbler.ScrobbleAsync(scrobble));
 }