예제 #1
0
        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));
        }
        /// <summary>
        /// Asynchronously tries to extract series actors for the given <param name="mediaItemAccessor"></param>
        /// </summary>
        /// <param name="mediaItemAccessor">Points to the resource for which we try to extract metadata</param>
        /// <param name="extractedAspects">List of MediaItemAspect dictionaries to update with metadata</param>
        /// <returns><c>true</c> if metadata was found and stored into the <paramref name="extractedAspects"/>, else <c>false</c></returns>
        protected async Task <bool> TryExtractAlbumArtistMetadataAsync(IResourceAccessor mediaItemAccessor, IList <IDictionary <Guid, IList <MediaItemAspect> > > extractedAspects)
        {
            NfoArtistReader artistReader = await TryGetNfoArtistReaderAsync(mediaItemAccessor).ConfigureAwait(false);

            if (artistReader != null)
            {
                IDictionary <Guid, IList <MediaItemAspect> > aspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                if (artistReader.TryWriteMetadata(aspects))
                {
                    extractedAspects.Add(aspects);
                    return(true);
                }
            }

            NfoAlbumReader albumNfoReader = await TryGetNfoAlbumReaderAsync(mediaItemAccessor).ConfigureAwait(false);

            if (albumNfoReader != null)
            {
                return(albumNfoReader.TryWriteArtistMetadata(extractedAspects));
            }
            return(false);
        }