public void TestNfoMovieReaderWriteActorMetadata() { //Arrange IList <PersonStub> actors = CreateTestActors(); MovieStub movieStub = CreateTestMovieStub(actors); NfoMovieReader reader = new NfoMovieReader(new ConsoleLogger(LogLevel.All, true), 1, true, false, false, null, new NfoMovieMetadataExtractorSettings()); reader.GetMovieStubs().Add(movieStub); //Act IList <IDictionary <Guid, IList <MediaItemAspect> > > aspects = new List <IDictionary <Guid, IList <MediaItemAspect> > >(); reader.TryWriteActorMetadata(aspects); //Assert Assert.AreEqual(2, aspects.Count); MediaItemAspect personAspect0 = MediaItemAspect.GetAspect(aspects[0], PersonAspect.Metadata); Assert.NotNull(personAspect0); Assert.AreEqual(actors[0].Name, personAspect0.GetAttributeValue <string>(PersonAspect.ATTR_PERSON_NAME)); Assert.AreEqual(actors[0].Biography, personAspect0.GetAttributeValue <string>(PersonAspect.ATTR_BIOGRAPHY)); Assert.AreEqual(actors[0].Birthdate, personAspect0.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFBIRTH)); Assert.AreEqual(actors[0].Deathdate, personAspect0.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFDEATH)); Assert.AreEqual(PersonAspect.OCCUPATION_ACTOR, personAspect0.GetAttributeValue <string>(PersonAspect.ATTR_OCCUPATION)); IList <MediaItemAspect> externalIdentifiers0; Assert.IsTrue(aspects[0].TryGetValue(ExternalIdentifierAspect.ASPECT_ID, out externalIdentifiers0)); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers0, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_PERSON, actors[0].ImdbId)); MediaItemAspect personAspect1 = MediaItemAspect.GetAspect(aspects[1], PersonAspect.Metadata); Assert.NotNull(personAspect1); Assert.AreEqual(actors[1].Name, personAspect1.GetAttributeValue <string>(PersonAspect.ATTR_PERSON_NAME)); Assert.AreEqual(actors[1].Biography, personAspect1.GetAttributeValue <string>(PersonAspect.ATTR_BIOGRAPHY)); Assert.AreEqual(actors[1].Birthdate, personAspect1.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFBIRTH)); Assert.AreEqual(actors[1].Deathdate, personAspect1.GetAttributeValue <DateTime?>(PersonAspect.ATTR_DATEOFDEATH)); Assert.AreEqual(PersonAspect.OCCUPATION_ACTOR, personAspect1.GetAttributeValue <string>(PersonAspect.ATTR_OCCUPATION)); IList <MediaItemAspect> externalIdentifiers1; Assert.IsTrue(aspects[1].TryGetValue(ExternalIdentifierAspect.ASPECT_ID, out externalIdentifiers1)); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers1, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_PERSON, actors[1].ImdbId)); }
public void TestNfoMovieReaderWriteMetadata() { //Arrange MovieStub movieStub = CreateTestMovieStub(CreateTestActors()); NfoMovieReader readerVideoOnly = new NfoMovieReader(new ConsoleLogger(LogLevel.All, true), 1, true, false, false, null, new NfoMovieMetadataExtractorSettings()); readerVideoOnly.GetMovieStubs().Add(movieStub); NfoMovieReader readerMovieOnly = new NfoMovieReader(new ConsoleLogger(LogLevel.All, true), 1, false, false, false, null, new NfoMovieMetadataExtractorSettings()); readerMovieOnly.GetMovieStubs().Add(movieStub); //Act IDictionary <Guid, IList <MediaItemAspect> > aspectsVideoOnly = new Dictionary <Guid, IList <MediaItemAspect> >(); readerVideoOnly.TryWriteMetadata(aspectsVideoOnly); IDictionary <Guid, IList <MediaItemAspect> > aspectsMovieOnly = new Dictionary <Guid, IList <MediaItemAspect> >(); readerMovieOnly.TryWriteMetadata(aspectsMovieOnly); //Assert //Video aspects only MediaItemAspect mediaAspect = MediaItemAspect.GetAspect(aspectsVideoOnly, MediaAspect.Metadata); Assert.NotNull(mediaAspect); Assert.AreEqual(movieStub.Title, mediaAspect.GetAttributeValue <string>(MediaAspect.ATTR_TITLE)); Assert.AreEqual(movieStub.SortTitle, mediaAspect.GetAttributeValue <string>(MediaAspect.ATTR_SORT_TITLE)); Assert.AreEqual(movieStub.Premiered, mediaAspect.GetAttributeValue <DateTime?>(MediaAspect.ATTR_RECORDINGTIME)); Assert.AreEqual(movieStub.PlayCount, mediaAspect.GetAttributeValue <int?>(MediaAspect.ATTR_PLAYCOUNT)); Assert.AreEqual(movieStub.LastPlayed, mediaAspect.GetAttributeValue <DateTime?>(MediaAspect.ATTR_LASTPLAYED)); MediaItemAspect videoAspect = MediaItemAspect.GetAspect(aspectsVideoOnly, VideoAspect.Metadata); Assert.NotNull(videoAspect); Assert.AreEqual(movieStub.Plot, videoAspect.GetAttributeValue <string>(VideoAspect.ATTR_STORYPLOT)); CollectionAssert.AreEqual(movieStub.Actors.OrderBy(p => p.Order).Select(p => p.Name), videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS)); Assert.AreEqual(movieStub.Director, videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_DIRECTORS).First()); CollectionAssert.AreEqual(movieStub.Credits, videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_WRITERS)); //ToDo: Rework Genre Mapper to make it testable, currently depends on IPathManager/language files! //IList<MediaItemAspect> genreAspects; //Assert.IsTrue(aspects.TryGetValue(GenreAspect.ASPECT_ID, out genreAspects)); //CollectionAssert.AreEqual(movieStub.Genres, genreAspects.Select(g => g.GetAttributeValue<string>(GenreAspect.ATTR_GENRE))); MediaItemAspect thumbnailAspect = MediaItemAspect.GetAspect(aspectsVideoOnly, ThumbnailLargeAspect.Metadata); Assert.NotNull(thumbnailAspect); CollectionAssert.AreEqual(movieStub.Thumb, thumbnailAspect.GetAttributeValue <byte[]>(ThumbnailLargeAspect.ATTR_THUMBNAIL)); //Movie aspects only MediaItemAspect movieAspect = MediaItemAspect.GetAspect(aspectsMovieOnly, MovieAspect.Metadata); Assert.NotNull(movieAspect); CollectionAssert.AreEqual(movieStub.Companies, movieAspect.GetCollectionAttribute <string>(MovieAspect.ATTR_COMPANIES)); Assert.AreEqual(movieStub.Title, movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_MOVIE_NAME)); Assert.AreEqual(movieStub.OriginalTitle, movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_ORIG_MOVIE_NAME)); Assert.AreEqual(movieStub.Sets.OrderBy(set => set.Order).First().Name, movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_COLLECTION_NAME)); Assert.AreEqual((int)movieStub.Runtime.Value.TotalMinutes, movieAspect.GetAttributeValue <int?>(MovieAspect.ATTR_RUNTIME_M)); Assert.AreEqual("US_PG", movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_CERTIFICATION)); Assert.AreEqual(movieStub.Tagline, movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_TAGLINE)); Assert.AreEqual((double)movieStub.Rating, movieAspect.GetAttributeValue <double?>(MovieAspect.ATTR_TOTAL_RATING)); Assert.AreEqual(movieStub.Votes, movieAspect.GetAttributeValue <int?>(MovieAspect.ATTR_RATING_COUNT)); IList <MediaItemAspect> externalIdentifiers; Assert.IsTrue(aspectsMovieOnly.TryGetValue(ExternalIdentifierAspect.ASPECT_ID, out externalIdentifiers)); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_MOVIE, movieStub.TmdbId.ToString())); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_COLLECTION, movieStub.TmdbCollectionId.ToString())); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_MOVIE, movieStub.Id)); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_ALLOCINE, ExternalIdentifierAspect.TYPE_MOVIE, movieStub.Allocine.ToString())); Assert.IsTrue(TestUtils.HasExternalId(externalIdentifiers, ExternalIdentifierAspect.SOURCE_CINEPASSION, ExternalIdentifierAspect.TYPE_MOVIE, movieStub.Cinepassion.ToString())); }
private async Task <bool> TryExtractStubItemsAsync(IResourceAccessor mediaItemAccessor, ICollection <IDictionary <Guid, IList <MediaItemAspect> > > extractedStubAspectData) { // Get a unique number for this call to TryExtractMetadataAsync. We use this to make reading the debug log easier. // This MetadataExtractor is called in parallel for multiple MediaItems so that the respective debug log entries // for one call are not contained one after another in debug log. We therefore prepend this number before every log entry. var miNumber = Interlocked.Increment(ref _lastMediaItemNumber); try { _debugLogger.Info("[#{0}]: Start extracting stubs for resource '{1}'", miNumber, mediaItemAccessor); if (!IsStubResource(mediaItemAccessor)) { _debugLogger.Info("[#{0}]: Cannot extract stubs; file does not have a supported extension", miNumber); return(false); } // This MetadataExtractor only works for MediaItems accessible by an IFileSystemResourceAccessor. // Otherwise it is not possible to find a stub-file in the MediaItem's directory. if (!(mediaItemAccessor is IFileSystemResourceAccessor)) { _debugLogger.Info("[#{0}]: Cannot extract stubs; mediaItemAccessor is not an IFileSystemResourceAccessor", miNumber); return(false); } var fsra = mediaItemAccessor as IFileSystemResourceAccessor; var movieStubReader = new StubMovieReader(_debugLogger, miNumber, true, _settings); if (fsra != null && await movieStubReader.TryReadMetadataAsync(fsra).ConfigureAwait(false)) { MovieStub movie = movieStubReader.GetMovieStubs().FirstOrDefault(); if (movie != null) { Dictionary <Guid, IList <MediaItemAspect> > extractedAspectData = new Dictionary <Guid, IList <MediaItemAspect> >(); MultipleMediaItemAspect providerResourceAspect = MediaItemAspect.CreateAspect(extractedAspectData, ProviderResourceAspect.Metadata); providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_INDEX, 0); providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_TYPE, ProviderResourceAspect.TYPE_STUB); providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, fsra.CanonicalLocalResourcePath.Serialize()); if (IsVhs(mediaItemAccessor)) { providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/unknown"); MultipleMediaItemAspect videoStreamAspects = MediaItemAspect.CreateAspect(extractedAspectData, VideoStreamAspect.Metadata); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, VideoStreamAspect.TYPE_SD); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, Convert.ToSingle(4.0 / 3.0)); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_FPS, 25F); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_WIDTH, 720); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, 576); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, 1); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, 1); MultipleMediaItemAspect audioAspect = MediaItemAspect.CreateAspect(extractedAspectData, VideoAudioStreamAspect.Metadata); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, 0); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, 1); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, 2); } else if (IsTv(mediaItemAccessor)) { providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/unknown"); MultipleMediaItemAspect videoStreamAspects = MediaItemAspect.CreateAspect(extractedAspectData, VideoStreamAspect.Metadata); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, VideoStreamAspect.TYPE_HD); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, Convert.ToSingle(16.0 / 9.0)); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_FPS, 25F); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_WIDTH, 1920); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, 1080); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, 1); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, 1); MultipleMediaItemAspect audioAspect = MediaItemAspect.CreateAspect(extractedAspectData, VideoAudioStreamAspect.Metadata); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, 0); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, 1); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, 2); } else if (IsDvd(mediaItemAccessor)) { providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/mp2t"); MultipleMediaItemAspect videoStreamAspects = MediaItemAspect.CreateAspect(extractedAspectData, VideoStreamAspect.Metadata); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, VideoStreamAspect.TYPE_SD); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, Convert.ToSingle(16.0 / 9.0)); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_FPS, 25F); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_WIDTH, 720); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, 576); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEOENCODING, "MPEG-2 Video"); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, 1); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, 1); MultipleMediaItemAspect audioAspect = MediaItemAspect.CreateAspect(extractedAspectData, VideoAudioStreamAspect.Metadata); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, 0); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, 1); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOENCODING, "AC3"); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, 6); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOSAMPLERATE, 48000L); } else if (IsBluray(mediaItemAccessor)) { providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/mp4"); MultipleMediaItemAspect videoStreamAspects = MediaItemAspect.CreateAspect(extractedAspectData, VideoStreamAspect.Metadata); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, VideoStreamAspect.TYPE_HD); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, Convert.ToSingle(16.0 / 9.0)); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_FPS, 24F); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_WIDTH, 1920); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, 1080); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEOENCODING, "AVC"); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, 1); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, 1); MultipleMediaItemAspect audioAspect = MediaItemAspect.CreateAspect(extractedAspectData, VideoAudioStreamAspect.Metadata); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, 0); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, 1); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOENCODING, "AC3"); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, 6); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOSAMPLERATE, 48000L); } else if (IsHdDvd(mediaItemAccessor)) { providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/wvc1"); MultipleMediaItemAspect videoStreamAspects = MediaItemAspect.CreateAspect(extractedAspectData, VideoStreamAspect.Metadata); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, 0); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, VideoStreamAspect.TYPE_HD); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, Convert.ToSingle(16.0 / 9.0)); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_FPS, 24F); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_WIDTH, 1920); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, 1080); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEOENCODING, "VC1"); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, 1); videoStreamAspects.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, 1); MultipleMediaItemAspect audioAspect = MediaItemAspect.CreateAspect(extractedAspectData, VideoAudioStreamAspect.Metadata); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, 0); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, 1); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOENCODING, "AC3"); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, 6); audioAspect.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOSAMPLERATE, 48000L); } SingleMediaItemAspect videoAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, VideoAspect.Metadata); videoAspect.SetAttribute(VideoAspect.ATTR_ISDVD, true); SingleMediaItemAspect movieAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MovieAspect.Metadata); movieAspect.SetAttribute(MovieAspect.ATTR_MOVIE_NAME, movie.Title); SingleMediaItemAspect stubAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, StubAspect.Metadata); stubAspect.SetAttribute(StubAspect.ATTR_DISC_NAME, movie.DiscName); stubAspect.SetAttribute(StubAspect.ATTR_MESSAGE, movie.Message); MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, movie.Title); MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_SORT_TITLE, BaseInfo.GetSortTitle(movie.Title)); MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_ISVIRTUAL, false); MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_ISSTUB, true); MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_RECORDINGTIME, fsra.LastChanged); extractedStubAspectData.Add(extractedAspectData); } } else { _debugLogger.Warn("[#{0}]: No valid metadata found in movie stub file", miNumber); } _debugLogger.Info("[#{0}]: Successfully finished extracting stubs", miNumber); return(true); } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("StubMovieMetadataExtractor: Exception while extracting stubs for resource '{0}'; enable debug logging for more details.", mediaItemAccessor); _debugLogger.Error("[#{0}]: Exception while extracting stubs", e, miNumber); return(false); } }