Exemple #1
0
 public IFilter GetSearchFilter(IDictionary <Guid, IList <MediaItemAspect> > extractedAspects)
 {
     return(ISeriesRelationshipExtractor.GetEpisodeSearchFilter(extractedAspects));
 }
        protected bool ExtractSeriesData(ILocalFsResourceAccessor lfsra, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData, bool importOnly)
        {
            // VideoAspect must be present to be sure it is actually a video resource.
            if (!extractedAspectData.ContainsKey(VideoStreamAspect.ASPECT_ID) && !extractedAspectData.ContainsKey(SubtitleAspect.ASPECT_ID))
            {
                return(false);
            }

            if (extractedAspectData.ContainsKey(SubtitleAspect.ASPECT_ID) && !importOnly)
            {
                return(false); //Subtitles can only be imported not refreshed
            }
            bool refresh = false;

            if (extractedAspectData.ContainsKey(EpisodeAspect.ASPECT_ID))
            {
                refresh = true;
            }

            EpisodeInfo episodeInfo = new EpisodeInfo();

            if (refresh)
            {
                episodeInfo.FromMetadata(extractedAspectData);
            }
            ISeriesRelationshipExtractor.UpdateEpisodeSeries(extractedAspectData, episodeInfo);
            if (!episodeInfo.IsBaseInfoPresent)
            {
                string title = null;
                int    seasonNumber;
                SingleMediaItemAspect episodeAspect;
                MediaItemAspect.TryGetAspect(extractedAspectData, EpisodeAspect.Metadata, out episodeAspect);
                IEnumerable <int> episodeNumbers;
                if (MediaItemAspect.TryGetAttribute(extractedAspectData, EpisodeAspect.ATTR_SERIES_NAME, out title) &&
                    MediaItemAspect.TryGetAttribute(extractedAspectData, EpisodeAspect.ATTR_SEASON, out seasonNumber) &&
                    (episodeNumbers = episodeAspect.GetCollectionAttribute <int>(EpisodeAspect.ATTR_EPISODE)) != null)
                {
                    episodeInfo.SeriesName   = title;
                    episodeInfo.SeasonNumber = seasonNumber;
                    episodeInfo.EpisodeNumbers.Clear();
                    episodeNumbers.ToList().ForEach(n => episodeInfo.EpisodeNumbers.Add(n));
                }
            }

            // If there was no complete match, yet, try to get extended information out of matroska files)
            if (!episodeInfo.IsBaseInfoPresent || !episodeInfo.HasExternalId)
            {
                try
                {
                    MatroskaMatcher matroskaMatcher = new MatroskaMatcher();
                    if (matroskaMatcher.MatchSeries(lfsra, episodeInfo))
                    {
                        ServiceRegistration.Get <ILogger>().Debug("ExtractSeriesData: Found EpisodeInfo by MatroskaMatcher for {0}, IMDB {1}, TVDB {2}, TMDB {3}, AreReqiredFieldsFilled {4}",
                                                                  episodeInfo.SeriesName, episodeInfo.SeriesImdbId, episodeInfo.SeriesTvdbId, episodeInfo.SeriesMovieDbId, episodeInfo.IsBaseInfoPresent);
                    }
                }
                catch (Exception ex)
                {
                    ServiceRegistration.Get <ILogger>().Debug("ExtractSeriesData: Exception reading matroska tags for '{0}'", ex, lfsra.CanonicalLocalResourcePath);
                }
            }

            // If no information was found before, try name matching
            if (!episodeInfo.IsBaseInfoPresent)
            {
                // Try to match series from folder and file naming
                SeriesMatcher seriesMatcher = new SeriesMatcher();
                seriesMatcher.MatchSeries(lfsra, episodeInfo);
            }

            //Prepare online search improvements
            if (episodeInfo.SeriesFirstAired == null)
            {
                EpisodeInfo   tempEpisodeInfo = new EpisodeInfo();
                SeriesMatcher seriesMatcher   = new SeriesMatcher();
                seriesMatcher.MatchSeries(lfsra, tempEpisodeInfo);
                if (tempEpisodeInfo.SeriesFirstAired.HasValue)
                {
                    episodeInfo.SeriesFirstAired = tempEpisodeInfo.SeriesFirstAired;
                }
            }
            if (string.IsNullOrEmpty(episodeInfo.SeriesAlternateName))
            {
                var mediaItemPath = lfsra.CanonicalLocalResourcePath;
                var seriesMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../");
                episodeInfo.SeriesAlternateName = seriesMediaItemDirectoryPath.FileName;
            }

            if (episodeInfo.Languages.Count == 0)
            {
                IList <MultipleMediaItemAspect> audioAspects;
                if (MediaItemAspect.TryGetAspects(extractedAspectData, VideoAudioStreamAspect.Metadata, out audioAspects))
                {
                    foreach (MultipleMediaItemAspect aspect in audioAspects)
                    {
                        string language = (string)aspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE);
                        if (!string.IsNullOrEmpty(language) && !episodeInfo.Languages.Contains(language))
                        {
                            episodeInfo.Languages.Add(language);
                        }
                    }
                }
            }

            episodeInfo.AssignNameId();

            if (SkipOnlineSearches && !SkipFanArtDownload)
            {
                EpisodeInfo tempInfo = episodeInfo.Clone();
                OnlineMatcherService.Instance.FindAndUpdateEpisode(tempInfo, importOnly);
                episodeInfo.CopyIdsFrom(tempInfo);
                episodeInfo.HasChanged = tempInfo.HasChanged;
            }
            else if (!SkipOnlineSearches)
            {
                OnlineMatcherService.Instance.FindAndUpdateEpisode(episodeInfo, importOnly);
            }

            //Send it to the videos section
            if (!SkipOnlineSearches && !episodeInfo.HasExternalId)
            {
                return(false);
            }

            if (refresh)
            {
                if ((IncludeActorDetails && !BaseInfo.HasRelationship(extractedAspectData, PersonAspect.ROLE_ACTOR) && episodeInfo.Actors.Count > 0) ||
                    (IncludeCharacterDetails && !BaseInfo.HasRelationship(extractedAspectData, CharacterAspect.ROLE_CHARACTER) && episodeInfo.Characters.Count > 0) ||
                    (IncludeDirectorDetails && !BaseInfo.HasRelationship(extractedAspectData, PersonAspect.ROLE_DIRECTOR) && episodeInfo.Directors.Count > 0) ||
                    (IncludeWriterDetails && !BaseInfo.HasRelationship(extractedAspectData, PersonAspect.ROLE_WRITER) && episodeInfo.Writers.Count > 0) ||
                    (!BaseInfo.HasRelationship(extractedAspectData, SeriesAspect.ROLE_SERIES) && !episodeInfo.SeriesName.IsEmpty) ||
                    (!BaseInfo.HasRelationship(extractedAspectData, SeasonAspect.ROLE_SEASON) && episodeInfo.SeasonNumber.HasValue))
                {
                    episodeInfo.HasChanged = true;
                }
            }

            if (!episodeInfo.HasChanged && !importOnly)
            {
                return(false);
            }

            episodeInfo.SetMetadata(extractedAspectData);

            return(episodeInfo.IsBaseInfoPresent);
        }