Example #1
0
        public async Task InternalSaveAsync(Track track, byte[] albumData, byte[] artistData)
        {
            using (_insightsService.TrackTimeEvent("SongSaved",
                                                   new Dictionary <string, string>
            {
                { "Track type", track.Type.ToString() },
                { "Title", track.Title },
                { "Artists", track.Artists },
                { "Album", track.AlbumTitle },
                { "Album artist", track.AlbumArtist }
            }))
            {
                var isMatching = track.AudioWebUri == null && track.AudioLocalUri == null;
                track.Status = isMatching ? TrackStatus.Matching : TrackStatus.None;

                // Download artwork
                await DownloadAlbumArtworkAsync(track, albumData);
                await DownloadArtistArtworkAsync(track, artistData);

                await _libraryService.AddTrackAsync(track);

                // proccess it
                if (isMatching)
                {
                    _matchingService.Queue(track);
                }
                else if (track.AudioLocalUri == null)
                {
                    await _downloadService.StartDownloadAsync(track);
                }
            }
        }
        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();
        }