Ejemplo n.º 1
0
        public ArtistWithAlbums GetWithAlbums(long id)
        {
            var artist = artistService.FindById(id);
            var albums = albumService.FindByArtistId(id);

            return(new ArtistWithAlbums(artist, albums));
        }
Ejemplo n.º 2
0
        public Artist GetArtistFromTag(string file)
        {
            var parsedTrackInfo = Parser.ParseMusicPath(file);

            var artist = new Artist();

            if (parsedTrackInfo.ArtistMBId.IsNotNullOrWhiteSpace())
            {
                artist = _artistService.FindById(parsedTrackInfo.ArtistMBId);

                if (artist != null)
                {
                    return(artist);
                }
            }

            if (parsedTrackInfo == null || parsedTrackInfo.ArtistTitle.IsNullOrWhiteSpace())
            {
                return(null);
            }

            artist = _artistService.FindByName(parsedTrackInfo.ArtistTitle);

            if (artist == null)
            {
                _logger.Debug("Trying inexact artist match for {0}", parsedTrackInfo.ArtistTitle);
                artist = _artistService.FindByNameInexact(parsedTrackInfo.ArtistTitle);
            }

            return(artist);
        }
Ejemplo n.º 3
0
        protected override void EnsureNewParent(Album local, Album remote)
        {
            // Make sure the appropriate artist exists (it could be that an album changes parent)
            // The artistMetadata entry will be in the db but make sure a corresponding artist is too
            // so that the album doesn't just disappear.

            // TODO filter by metadata id before hitting database
            _logger.Trace($"Ensuring parent artist exists [{remote.ArtistMetadata.Value.ForeignArtistId}]");

            var newArtist = _artistService.FindById(remote.ArtistMetadata.Value.ForeignArtistId);

            if (newArtist == null)
            {
                var oldArtist = local.Artist.Value;
                var addArtist = new Artist {
                    Metadata          = remote.ArtistMetadata.Value,
                    MetadataProfileId = oldArtist.MetadataProfileId,
                    QualityProfileId  = oldArtist.QualityProfileId,
                    RootFolderPath    = oldArtist.RootFolderPath,
                    Monitored         = oldArtist.Monitored,
                    AlbumFolder       = oldArtist.AlbumFolder,
                    Tags = oldArtist.Tags
                };
                _logger.Debug($"Adding missing parent artist {addArtist}");
                _addArtistService.AddArtist(addArtist);
            }
        }
Ejemplo n.º 4
0
        private List <CandidateAlbumRelease> GetDbCandidates(LocalAlbumRelease localAlbumRelease, bool includeExisting)
        {
            // most general version, nothing has been specified.
            // get all plausible artists, then all plausible albums, then get releases for each of these.
            var candidateReleases = new List <CandidateAlbumRelease>();

            // check if it looks like VA.
            if (TrackGroupingService.IsVariousArtists(localAlbumRelease.LocalTracks))
            {
                var va = _artistService.FindById(DistanceCalculator.VariousArtistIds[0]);
                if (va != null)
                {
                    candidateReleases.AddRange(GetDbCandidatesByArtist(localAlbumRelease, va, includeExisting));
                }
            }

            var artistTag = localAlbumRelease.LocalTracks.MostCommon(x => x.FileTrackInfo.ArtistTitle) ?? "";

            if (artistTag.IsNotNullOrWhiteSpace())
            {
                var possibleArtists = _artistService.GetCandidates(artistTag);
                foreach (var artist in possibleArtists)
                {
                    candidateReleases.AddRange(GetDbCandidatesByArtist(localAlbumRelease, artist, includeExisting));
                }
            }

            return(candidateReleases);
        }
Ejemplo n.º 5
0
        private Artist EnsureArtistAdded(List <ImportDecision <LocalTrack> > decisions, List <Artist> addedArtists)
        {
            var artist = decisions.First().Item.Artist;

            if (artist.Id == 0)
            {
                var dbArtist = _artistService.FindById(artist.ForeignArtistId);

                if (dbArtist == null)
                {
                    _logger.Debug($"Adding remote artist {artist}");
                    var rootFolder = _rootFolderService.GetBestRootFolder(decisions.First().Item.Path);

                    artist.RootFolderPath    = rootFolder.Path;
                    artist.MetadataProfileId = rootFolder.DefaultMetadataProfileId;
                    artist.QualityProfileId  = rootFolder.DefaultQualityProfileId;
                    artist.Monitored         = rootFolder.DefaultMonitorOption != MonitorTypes.None;
                    artist.Tags       = rootFolder.DefaultTags;
                    artist.AddOptions = new AddArtistOptions
                    {
                        SearchForMissingAlbums = false,
                        Monitored = artist.Monitored,
                        Monitor   = rootFolder.DefaultMonitorOption
                    };

                    try
                    {
                        dbArtist = _addArtistService.AddArtist(artist, false);
                        addedArtists.Add(dbArtist);
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "Failed to add artist {0}", artist);
                        foreach (var decision in decisions)
                        {
                            decision.Reject(new Rejection("Failed to add missing artist", RejectionType.Temporary));
                        }

                        return(null);
                    }
                }

                // Put in the newly loaded artist
                foreach (var decision in decisions)
                {
                    decision.Item.Artist                 = dbArtist;
                    decision.Item.Album.Artist           = dbArtist;
                    decision.Item.Album.ArtistMetadataId = dbArtist.ArtistMetadataId;
                }

                artist = dbArtist;
            }

            return(artist);
        }
Ejemplo n.º 6
0
        private void ProcessArtistReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Artist> artistsToAdd)
        {
            if (report.ArtistMusicBrainzId == null)
            {
                return;
            }

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

            if (existingArtist != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Artist Exists in DB", report.ArtistMusicBrainzId, report.Artist);
                return;
            }

            // 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);
                return;
            }

            // Append Artist if not already in DB or already on add list
            if (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,
                    AddOptions = new AddArtistOptions
                    {
                        SearchForMissingAlbums = monitored,
                        Monitored = monitored,
                        Monitor   = monitored ? MonitorTypes.All : MonitorTypes.None
                    }
                });
            }
        }
Ejemplo n.º 7
0
        private List <ArtistResource> AllArtists()
        {
            var mbId             = Request.GetGuidQueryParameter("mbId");
            var artistStats      = _artistStatisticsService.ArtistStatistics();
            var artistsResources = new List <ArtistResource>();

            if (mbId != Guid.Empty)
            {
                artistsResources.AddIfNotNull(_artistService.FindById(mbId.ToString()).ToResource());
            }
            else
            {
                artistsResources.AddRange(_artistService.GetAllArtists().ToResource());
            }

            MapCoversToLocal(artistsResources.ToArray());
            LinkNextPreviousAlbums(artistsResources.ToArray());
            LinkArtistStatistics(artistsResources, artistStats);
            artistsResources.ForEach(LinkRootFolderPath);

            //PopulateAlternateTitles(seriesResources);
            return(artistsResources);
        }
Ejemplo n.º 8
0
        public Album AddAlbum(Album album, bool doRefresh = true)
        {
            _logger.Debug($"Adding album {album}");

            album = AddSkyhookData(album);

            // Remove any import list exclusions preventing addition
            _importListExclusionService.Delete(album.ForeignAlbumId);
            _importListExclusionService.Delete(album.ArtistMetadata.Value.ForeignArtistId);

            // Note it's a manual addition so it's not deleted on next refresh
            album.AddOptions.AddType = AlbumAddType.Manual;

            // Add the artist if necessary
            var dbArtist = _artistService.FindById(album.ArtistMetadata.Value.ForeignArtistId);

            if (dbArtist == null)
            {
                var artist = album.Artist.Value;

                artist.Metadata.Value.ForeignArtistId = album.ArtistMetadata.Value.ForeignArtistId;

                // if adding and searching for artist, don't trigger album specific search
                if (artist.AddOptions?.SearchForMissingAlbums ?? false)
                {
                    album.AddOptions.SearchForNewAlbum = false;
                }

                dbArtist = _addArtistService.AddArtist(artist, false);
            }

            album.ArtistMetadataId = dbArtist.ArtistMetadataId;
            album.Artist           = dbArtist;
            _albumService.AddAlbum(album, doRefresh);

            return(album);
        }
Ejemplo n.º 9
0
 public Artist GetArtistById(long id)
 {
     return(this.WrapInUnitOfWork(() => artistService.FindById(id)));
 }
Ejemplo n.º 10
0
        public List <Artist> SearchForNewArtist(string title)
        {
            try
            {
                var lowerTitle = title.ToLowerInvariant();

                if (lowerTitle.StartsWith("gamearr:") || lowerTitle.StartsWith("gamearrid:") || lowerTitle.StartsWith("mbid:"))
                {
                    var slug = lowerTitle.Split(':')[1].Trim();

                    Guid searchGuid;

                    bool isValid = Guid.TryParse(slug, out searchGuid);

                    if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || isValid == false)
                    {
                        return(new List <Artist>());
                    }

                    try
                    {
                        var existingArtist = _artistService.FindById(searchGuid.ToString());
                        if (existingArtist != null)
                        {
                            return(new List <Artist> {
                                existingArtist
                            });
                        }

                        var metadataProfile = _metadataProfileService.All().First().Id; //Change this to Use last Used profile?

                        return(new List <Artist> {
                            GetArtistInfo(searchGuid.ToString(), metadataProfile)
                        });
                    }
                    catch (ArtistNotFoundException)
                    {
                        return(new List <Artist>());
                    }
                }

                var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                                  .SetSegment("route", "search")
                                  .AddQueryParam("type", "artist")
                                  .AddQueryParam("query", title.ToLower().Trim())
                                  .Build();



                var httpResponse = _httpClient.Get <List <ArtistResource> >(httpRequest);

                return(httpResponse.Resource.SelectList(MapSearchResult));
            }
            catch (HttpException)
            {
                throw new SkyHookException("Search for '{0}' failed. Unable to communicate with GamearrAPI.", title);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, ex.Message);
                throw new SkyHookException("Search for '{0}' failed. Invalid response received from GamearrAPI.", title);
            }
        }
Ejemplo n.º 11
0
 protected override Artist GetEntityByForeignId(Artist local)
 {
     return(_artistService.FindById(local.ForeignArtistId));
 }
Ejemplo n.º 12
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);
        }