Пример #1
0
        public async Task ScrobblesMultiple()
        {
            var scrobbles = GenerateScrobbles(4);

            var countingHandler = new CountingHttpClientHandler();
            var httpClient      = new HttpClient(countingHandler);
            var scrobbler       = new MemoryScrobbler(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);
        }
Пример #2
0
        public async Task <bool> Sync(LastTrack[] scrobbles)
        {
            var progress = new ProgressAlert("Syncing scrobbles", "Please wait...", Context);

            progress.Show();
            if (!client.Auth.Authenticated)
            {
                progress.Hide();
                return(false);
            }
            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 MemoryScrobbler(client.Auth);
            var res       = await scrobbler.ScrobbleAsync(list);

            progress.Hide();
            await Reload();

            Toast.MakeText(Context, $"Synced {list.Count} scrobbles!", ToastLength.Long).Show();
            return(true);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="auth">Last.fm authentication object.</param>
 /// <param name="httpClient">HttpClient to use for connections.</param>
 public AuthScrobbler(ILastAuth auth, HttpClient httpClient = null)
 {
     _scrobbler = new MemoryScrobbler(auth, httpClient);
 }