예제 #1
0
        private async Task PrepareTrackAsync(Track track)
        {
            switch (track.Status)
            {
            case TrackStatus.Matching:
                throw new AppException("Track is still matching.");

            case TrackStatus.NoMatch:
                throw new AppException("No match found for track, try manual matching it.");

            case TrackStatus.NotAvailable:
                throw new AppException("The audio file is not available.");
            }

            if (track.Type == TrackType.Stream &&
                track.AudioWebUri == null)
            {
                using (var blocker = new UiBlocker())
                {
                    blocker.UpdateProgress("Matching...");
                    var uri = await _matchEngineService.GetLinkAsync(track.Title, track.DisplayArtist);

                    if (uri == null)
                    {
                        throw new AppException("Problem matching the song, try saving and manual matching it.");
                    }
                    track.AudioWebUri = uri.ToString();
                }
            }
        }
예제 #2
0
        private async Task CreateTaskAsync(Track track)
        {
            await _semaphoreSlim.WaitAsync();

            using (var timer = _insightsService.TrackTimeEvent("SongMatched", new Dictionary <string, string>
            {
                { "Title", track.Title },
                { "Artists", track.Artists },
                { "Album", track.AlbumTitle },
                { "Album artist", track.AlbumArtist }
            }))
                try
                {
                    var uri = await _matchEngineService.GetLinkAsync(track.Title, track.DisplayArtist);

                    if (uri != null)
                    {
                        timer.AddProperty("Status", "Found match");
                        track.AudioWebUri = uri.ToString();
                        track.Status      = TrackStatus.None;
                        await _downloadService.StartDownloadAsync(track);
                    }
                    else
                    {
                        timer.AddProperty("Status", "No match");
                        track.Status = TrackStatus.NoMatch;
                    }
                    await _libraryService.UpdateTrackAsync(track);
                }
                catch
                {
                    timer.AddProperty("Status", "Error");
                }

            _semaphoreSlim.Release();
        }