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); } }
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); }
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); }
private int AddArtist(ArtistResource artistResource) { var artist = _addArtistService.AddArtist(artistResource.ToModel()); return(artist.Id); }