Esempio n. 1
0
        private void MapAlbumReport(ImportListItemInfo report)
        {
            var albumQuery  = report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() ? $"lidarr:{report.AlbumMusicBrainzId}" : report.Album;
            var mappedAlbum = _albumSearchService.SearchForNewAlbum(albumQuery, report.Artist)
                              .FirstOrDefault();

            // Break if we are looking for an album and cant find it. This will avoid us from adding the artist and possibly getting it wrong.
            if (mappedAlbum == null)
            {
                return;
            }

            report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId;
            report.Album  = mappedAlbum.Title;
            report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name;
            report.ArtistMusicBrainzId = mappedAlbum.ArtistMetadata?.Value?.ForeignArtistId;
        }
Esempio n. 2
0
        private Response Search()
        {
            var searchResults = _searchProxy.SearchForNewAlbum((string)Request.Query.term, null);

            return(MapToResource(searchResults).ToList().AsResponse());
        }
Esempio n. 3
0
        public List <CandidateAlbumRelease> GetRemoteCandidates(LocalAlbumRelease localAlbumRelease)
        {
            // Gets candidate album releases from the metadata server.
            // Will eventually need adding locally if we find a match
            var watch = System.Diagnostics.Stopwatch.StartNew();

            List <Album> remoteAlbums;
            var          candidates = new List <CandidateAlbumRelease>();

            var albumIds     = localAlbumRelease.LocalTracks.Select(x => x.FileTrackInfo.AlbumMBId).Distinct().ToList();
            var recordingIds = localAlbumRelease.LocalTracks.Where(x => x.AcoustIdResults != null).SelectMany(x => x.AcoustIdResults).Distinct().ToList();

            try
            {
                if (albumIds.Count == 1 && albumIds[0].IsNotNullOrWhiteSpace())
                {
                    // Use mbids in tags if set
                    remoteAlbums = _albumSearchService.SearchForNewAlbum($"mbid:{albumIds[0]}", null);
                }
                else if (recordingIds.Any())
                {
                    // If fingerprints present use those
                    remoteAlbums = _albumSearchService.SearchForNewAlbumByRecordingIds(recordingIds);
                }
                else
                {
                    // fall back to artist / album name search
                    string artistTag;

                    if (TrackGroupingService.IsVariousArtists(localAlbumRelease.LocalTracks))
                    {
                        artistTag = "Various Artists";
                    }
                    else
                    {
                        artistTag = localAlbumRelease.LocalTracks.MostCommon(x => x.FileTrackInfo.ArtistTitle) ?? "";
                    }

                    var albumTag = localAlbumRelease.LocalTracks.MostCommon(x => x.FileTrackInfo.AlbumTitle) ?? "";

                    if (artistTag.IsNullOrWhiteSpace() || albumTag.IsNullOrWhiteSpace())
                    {
                        return(candidates);
                    }

                    remoteAlbums = _albumSearchService.SearchForNewAlbum(albumTag, artistTag);
                }
            }
            catch (SkyHookException e)
            {
                _logger.Info(e, "Skipping album due to SkyHook error");
                remoteAlbums = new List <Album>();
            }

            foreach (var album in remoteAlbums)
            {
                // We have to make sure various bits and pieces are populated that are normally handled
                // by a database lazy load
                foreach (var release in album.AlbumReleases.Value)
                {
                    release.Album = album;
                    candidates.Add(new CandidateAlbumRelease
                    {
                        AlbumRelease   = release,
                        ExistingTracks = new List <TrackFile>()
                    });
                }
            }

            watch.Stop();
            _logger.Debug($"Getting {candidates.Count} remote candidates from tags for {localAlbumRelease.LocalTracks.Count} tracks took {watch.ElapsedMilliseconds}ms");

            return(candidates);
        }
Esempio n. 4
0
        private List <Album> ProcessReports(List <ImportListItemInfo> reports)
        {
            var processed    = new List <Album>();
            var artistsToAdd = new List <Artist>();

            _logger.ProgressInfo("Processing {0} list items", reports.Count);

            var reportNumber = 1;

            var listExclusions = _importListExclusionService.All();

            foreach (var report in reports)
            {
                _logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, reports.Count);

                reportNumber++;

                var importList = _importListFactory.Get(report.ImportListId);

                // Map MBid if we only have an album title
                if (report.AlbumMusicBrainzId.IsNullOrWhiteSpace() && report.Album.IsNotNullOrWhiteSpace())
                {
                    var mappedAlbum = _albumSearchService.SearchForNewAlbum(report.Album, report.Artist)
                                      .FirstOrDefault();

                    if (mappedAlbum == null)
                    {
                        continue;                      // Break if we are looking for an album and cant find it. This will avoid us from adding the artist and possibly getting it wrong.
                    }
                    report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId;
                    report.Album  = mappedAlbum.Title;
                    report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name;
                    report.ArtistMusicBrainzId = mappedAlbum?.ArtistMetadata?.Value?.ForeignArtistId;
                }

                // Map MBid if we only have a artist name
                if (report.ArtistMusicBrainzId.IsNullOrWhiteSpace() && report.Artist.IsNotNullOrWhiteSpace())
                {
                    var mappedArtist = _artistSearchService.SearchForNewArtist(report.Artist)
                                       .FirstOrDefault();
                    report.ArtistMusicBrainzId = mappedArtist?.Metadata.Value?.ForeignArtistId;
                    report.Artist = mappedArtist?.Metadata.Value?.Name;
                }

                // Check to see if artist in DB
                var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId);

                // Check to see if artist excluded
                var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault();

                if (excludedArtist != null)
                {
                    _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist);
                }

                // Append Artist if not already in DB or already on add list
                if (existingArtist == null && excludedArtist == null && artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
                {
                    var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
                    artistsToAdd.Add(new Artist
                    {
                        Metadata = new ArtistMetadata {
                            ForeignArtistId = report.ArtistMusicBrainzId,
                            Name            = report.Artist
                        },
                        Monitored         = monitored,
                        RootFolderPath    = importList.RootFolderPath,
                        QualityProfileId  = importList.ProfileId,
                        MetadataProfileId = importList.MetadataProfileId,
                        Tags        = importList.Tags,
                        AlbumFolder = true,
                        AddOptions  = new AddArtistOptions {
                            SearchForMissingAlbums = monitored,
                            Monitored = monitored,
                            Monitor   = monitored ? MonitorTypes.All : MonitorTypes.None
                        }
                    });
                }

                // Add Album so we know what to monitor
                if (report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() && artistsToAdd.Any(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId) && importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum)
                {
                    artistsToAdd.Find(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId).AddOptions.AlbumsToMonitor.Add(report.AlbumMusicBrainzId);
                }
            }

            _addArtistService.AddArtists(artistsToAdd);

            var message = string.Format("Import List Sync Completed. Reports found: {0}, Reports grabbed: {1}", reports.Count, processed.Count);

            _logger.ProgressInfo(message);

            return(processed);
        }