public void TestNfoArtistReaderWriteMetadata() { ArtistStub artistStub = CreateTestArtistStub(); IDictionary <Guid, IList <MediaItemAspect> > aspects = new Dictionary <Guid, IList <MediaItemAspect> >(); NfoArtistReader reader = new NfoArtistReader(new ConsoleLogger(LogLevel.All, true), 1, false, null, new NfoAudioMetadataExtractorSettings(), false); reader.GetArtistStubs().Add(artistStub); reader.TryWriteMetadata(aspects); MediaItemAspect mediaAspect = MediaItemAspect.GetAspect(aspects, MediaAspect.Metadata); Assert.NotNull(mediaAspect); Assert.AreEqual(artistStub.Name, mediaAspect.GetAttributeValue <string>(MediaAspect.ATTR_TITLE)); MediaItemAspect personAspect = MediaItemAspect.GetAspect(aspects, PersonAspect.Metadata); Assert.NotNull(personAspect); Assert.AreEqual(artistStub.Name, personAspect.GetAttributeValue <string>(PersonAspect.ATTR_PERSON_NAME)); Assert.AreEqual(PersonAspect.OCCUPATION_ARTIST, personAspect.GetAttributeValue <string>(PersonAspect.ATTR_OCCUPATION)); Assert.AreEqual(artistStub.Biography, personAspect.GetAttributeValue <string>(PersonAspect.ATTR_BIOGRAPHY)); Assert.AreEqual(artistStub.Birthdate, personAspect.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFBIRTH)); Assert.AreEqual(artistStub.Deathdate, personAspect.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFDEATH)); Assert.IsFalse(personAspect.GetAttributeValue <bool>(PersonAspect.ATTR_GROUP)); IList <MediaItemAspect> externalIdentifiers; Assert.IsTrue(aspects.TryGetValue(ExternalIdentifierAspect.ASPECT_ID, out externalIdentifiers)); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_AUDIODB, ExternalIdentifierAspect.TYPE_PERSON, artistStub.AudioDbId.ToString())); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_MUSICBRAINZ, ExternalIdentifierAspect.TYPE_PERSON, artistStub.MusicBrainzArtistId)); //Thumbnail aspect no longer used. FanArt cache used instead because of expanded FanArt support //MediaItemAspect thumbnailAspect = MediaItemAspect.GetAspect(aspects, ThumbnailLargeAspect.Metadata); //Assert.NotNull(thumbnailAspect); //CollectionAssert.AreEqual(artistStub.Thumb, thumbnailAspect.GetAttributeValue<byte[]>(ThumbnailLargeAspect.ATTR_THUMBNAIL)); //Test Group aspects.Clear(); artistStub.Birthdate = null; artistStub.Deathdate = null; reader = new NfoArtistReader(new ConsoleLogger(LogLevel.All, true), 1, false, null, new NfoAudioMetadataExtractorSettings(), false); reader.GetArtistStubs().Add(artistStub); reader.TryWriteMetadata(aspects); personAspect = MediaItemAspect.GetAspect(aspects, PersonAspect.Metadata); Assert.NotNull(personAspect); Assert.AreEqual(artistStub.Formeddate, personAspect.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFBIRTH)); Assert.AreEqual(artistStub.Disbandeddate, personAspect.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFDEATH)); Assert.IsTrue(personAspect.GetAttributeValue <bool>(PersonAspect.ATTR_GROUP)); }
public override async Task CollectFanArtAsync(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { IResourceLocator mediaItemLocator = null; if (!BaseInfo.IsVirtualResource(aspects)) { mediaItemLocator = GetResourceLocator(aspects); } if (!aspects.ContainsKey(AudioAspect.ASPECT_ID) || mediaItemLocator == null) { return; } IFanArtCache fanArtCache = ServiceRegistration.Get <IFanArtCache>(); using (IResourceAccessor mediaItemAccessor = mediaItemLocator.CreateAccessor()) { //Album fanart if (RelationshipExtractorUtils.TryGetLinkedId(AudioAlbumAspect.ROLE_ALBUM, aspects, out Guid albumMediaItemId) && AddToCache(albumMediaItemId)) { var existingCovers = fanArtCache.GetFanArtFiles(albumMediaItemId, FanArtTypes.Cover); if (!existingCovers.Any()) //Only get album cover if needed for better performance { NfoAlbumReader albumNfoReader = await AUDIO_EXTRACTOR.TryGetNfoAlbumReaderAsync(mediaItemAccessor, true).ConfigureAwait(false); if (albumNfoReader != null) { var stubs = albumNfoReader.GetAlbumStubs(); var mainStub = stubs?.FirstOrDefault(); if (mainStub?.Thumb != null) { await fanArtCache.TrySaveFanArt(albumMediaItemId, mainStub.Title, FanArtTypes.Cover, p => TrySaveFileImage(mainStub.Thumb, p, "Thumb", "Nfo.")).ConfigureAwait(false); } } } } //Artist fanart IList <Tuple <Guid, string> > artists = GetArtists(aspects); if (artists?.Count > 0) { foreach (var artist in artists) { var existingThumbs = fanArtCache.GetFanArtFiles(artist.Item1, FanArtTypes.Thumbnail); if (!existingThumbs.Any() && AddToCache(artist.Item1)) //Only get artist thumbnail if needed for better performance { NfoArtistReader artistReader = await AUDIO_EXTRACTOR.TryGetNfoArtistReaderAsync(mediaItemAccessor, artist.Item2, true).ConfigureAwait(false); if (artistReader != null) { var stubs = artistReader.GetArtistStubs(); var mainStub = stubs?.FirstOrDefault(); if (string.Equals(mainStub?.Name, artist.Item2, StringComparison.InvariantCultureIgnoreCase)) { if (mainStub?.Thumb != null) { await fanArtCache.TrySaveFanArt(artist.Item1, artist.Item2, FanArtTypes.Thumbnail, p => TrySaveFileImage(mainStub.Thumb, p, "Thumb", "Nfo.")).ConfigureAwait(false); } } } } } } } }