Ejemplo n.º 1
0
        private object Import()
        {
            var resource   = Request.Body.FromJson <List <ArtistResource> >();
            var newArtists = resource.ToModel();

            return(_addArtistService.AddArtists(newArtists).ToResource());
        }
Ejemplo n.º 2
0
        private List <Album> ProcessReports(List <ImportListItemInfo> reports)
        {
            var processed    = new List <Album>();
            var artistsToAdd = new List <Artist>();
            var albumsToAdd  = new List <Album>();

            _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);

                if (report.Album.IsNotNullOrWhiteSpace() || report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace())
                {
                    if (report.AlbumMusicBrainzId.IsNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNullOrWhiteSpace())
                    {
                        MapAlbumReport(report);
                    }

                    ProcessAlbumReport(importList, report, listExclusions, albumsToAdd);
                }
                else if (report.Artist.IsNotNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNotNullOrWhiteSpace())
                {
                    if (report.ArtistMusicBrainzId.IsNullOrWhiteSpace())
                    {
                        MapArtistReport(report);
                    }

                    ProcessArtistReport(importList, report, listExclusions, artistsToAdd);
                }
            }

            var addedArtists = _addArtistService.AddArtists(artistsToAdd, false, true);
            var addedAlbums  = _addAlbumService.AddAlbums(albumsToAdd, false, true);

            var message = string.Format($"Import List Sync Completed. Items found: {reports.Count}, Artists added: {addedArtists.Count}, Albums added: {addedAlbums.Count}");

            _logger.ProgressInfo(message);

            var toRefresh = addedArtists.Select(x => x.Id).Concat(addedAlbums.Select(x => x.Artist.Value.Id)).Distinct().ToList();

            if (toRefresh.Any())
            {
                _commandQueueManager.Push(new BulkRefreshArtistCommand(toRefresh, true));
            }

            return(processed);
        }
Ejemplo n.º 3
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);
        }