public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            if (!SeriesMetadataExtractor.IncludeCharacterDetails)
            {
                return(false);
            }

            if (importOnly)
            {
                return(false);
            }

            SeriesInfo seriesInfo = new SeriesInfo();

            if (!seriesInfo.FromMetadata(aspects))
            {
                return(false);
            }

            if (CheckCacheContains(seriesInfo))
            {
                return(false);
            }

            int count = 0;

            if (!SeriesMetadataExtractor.SkipOnlineSearches)
            {
                OnlineMatcherService.Instance.UpdateSeriesCharacters(seriesInfo, importOnly);
                count = seriesInfo.Characters.Where(p => p.HasExternalId).Count();
                if (!seriesInfo.IsRefreshed)
                {
                    seriesInfo.HasChanged = true; //Force save to update external Ids for metadata found by other MDEs
                }
            }
            else
            {
                count = seriesInfo.Characters.Where(p => !string.IsNullOrEmpty(p.Name)).Count();
            }

            if (seriesInfo.Characters.Count == 0)
            {
                return(false);
            }

            if (BaseInfo.CountRelationships(aspects, LinkedRole) < count || (BaseInfo.CountRelationships(aspects, LinkedRole) == 0 && seriesInfo.Characters.Count > 0))
            {
                seriesInfo.HasChanged = true; //Force save if no relationship exists
            }
            if (!seriesInfo.HasChanged)
            {
                return(false);
            }

            AddToCheckCache(seriesInfo);

            extractedLinkedAspects = new List <RelationshipItem>();
            foreach (CharacterInfo character in seriesInfo.Characters)
            {
                character.AssignNameId();
                character.HasChanged = seriesInfo.HasChanged;
                IDictionary <Guid, IList <MediaItemAspect> > characterAspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                character.SetMetadata(characterAspects);

                if (characterAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    Guid existingId;
                    if (TryGetIdFromCache(character, out existingId))
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(characterAspects, existingId));
                    }
                    else
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(characterAspects, Guid.Empty));
                    }
                }
            }
            return(extractedLinkedAspects.Count > 0);
        }
        public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            if (!MovieMetadataExtractor.IncludeWriterDetails)
            {
                return(false);
            }

            if (importOnly)
            {
                return(false);
            }

            if (BaseInfo.IsVirtualResource(aspects))
            {
                return(false);
            }

            MovieInfo movieInfo = new MovieInfo();

            if (!movieInfo.FromMetadata(aspects))
            {
                return(false);
            }

            if (CheckCacheContains(movieInfo))
            {
                return(false);
            }

            int count = 0;

            if (!MovieMetadataExtractor.SkipOnlineSearches)
            {
                OnlineMatcherService.Instance.UpdatePersons(movieInfo, PersonAspect.OCCUPATION_WRITER, importOnly);
                count = movieInfo.Writers.Where(p => p.HasExternalId).Count();
                if (!movieInfo.IsRefreshed)
                {
                    movieInfo.HasChanged = true; //Force save to update external Ids for metadata found by other MDEs
                }
            }
            else
            {
                count = movieInfo.Writers.Where(p => !string.IsNullOrEmpty(p.Name)).Count();
            }

            if (movieInfo.Writers.Count == 0)
            {
                return(false);
            }

            if (BaseInfo.CountRelationships(aspects, LinkedRole) < count || (BaseInfo.CountRelationships(aspects, LinkedRole) == 0 && movieInfo.Writers.Count > 0))
            {
                movieInfo.HasChanged = true; //Force save if no relationship exists
            }
            if (!movieInfo.HasChanged)
            {
                return(false);
            }

            AddToCheckCache(movieInfo);

            extractedLinkedAspects = new List <RelationshipItem>();
            foreach (PersonInfo person in movieInfo.Writers)
            {
                person.AssignNameId();
                person.HasChanged = movieInfo.HasChanged;
                IDictionary <Guid, IList <MediaItemAspect> > personAspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                person.SetMetadata(personAspects);

                if (personAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    Guid existingId;
                    if (TryGetIdFromCache(person, out existingId))
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(personAspects, existingId));
                    }
                    else
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(personAspects, Guid.Empty));
                    }
                }
            }
            return(extractedLinkedAspects.Count > 0);
        }
        public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            if (importOnly)
            {
                return(false);
            }

            if (MovieMetadataExtractor.OnlyLocalMedia)
            {
                return(false);
            }

            MovieCollectionInfo collectionInfo = new MovieCollectionInfo();

            if (!collectionInfo.FromMetadata(aspects))
            {
                return(false);
            }

            if (CheckCacheContains(collectionInfo))
            {
                return(false);
            }

            if (!MovieMetadataExtractor.SkipOnlineSearches && collectionInfo.HasExternalId)
            {
                OnlineMatcherService.Instance.UpdateCollection(collectionInfo, true, importOnly);
            }

            if (collectionInfo.Movies.Count == 0)
            {
                return(false);
            }

            if (BaseInfo.CountRelationships(aspects, LinkedRole) < collectionInfo.Movies.Count)
            {
                collectionInfo.HasChanged = true; //Force save for new movies
            }
            else
            {
                return(false);
            }

            if (!collectionInfo.HasChanged)
            {
                return(false);
            }

            AddToCheckCache(collectionInfo);

            extractedLinkedAspects = new List <RelationshipItem>();
            for (int i = 0; i < collectionInfo.Movies.Count; i++)
            {
                MovieInfo movieInfo = collectionInfo.Movies[i];
                movieInfo.CollectionNameId = collectionInfo.NameId;

                IDictionary <Guid, IList <MediaItemAspect> > movieAspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                movieInfo.SetMetadata(movieAspects);
                MediaItemAspect.SetAttribute(movieAspects, MediaAspect.ATTR_ISVIRTUAL, true);

                if (movieAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    extractedLinkedAspects.Add(new RelationshipItem(movieAspects, Guid.Empty));
                }
            }
            return(extractedLinkedAspects.Count > 0);
        }
Пример #4
0
        public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            if (importOnly)
            {
                return(false);
            }

            if (SeriesMetadataExtractor.OnlyLocalMedia)
            {
                return(false);
            }

            SeriesInfo seriesInfo = new SeriesInfo();

            if (!seriesInfo.FromMetadata(aspects))
            {
                return(false);
            }

            if (CheckCacheContains(seriesInfo))
            {
                return(false);
            }

            if (!SeriesMetadataExtractor.SkipOnlineSearches)
            {
                OnlineMatcherService.Instance.UpdateSeries(seriesInfo, true, false);
            }

            if (seriesInfo.Episodes.Count == 0)
            {
                return(false);
            }

            if (BaseInfo.CountRelationships(aspects, LinkedRole) < seriesInfo.Episodes.Count)
            {
                seriesInfo.HasChanged = true; //Force save for new episodes
            }
            else
            {
                return(false);
            }

            if (!seriesInfo.HasChanged)
            {
                return(false);
            }

            AddToCheckCache(seriesInfo);

            extractedLinkedAspects = new List <RelationshipItem>();
            for (int i = 0; i < seriesInfo.Episodes.Count; i++)
            {
                EpisodeInfo episodeInfo = seriesInfo.Episodes[i];
                episodeInfo.SeriesNameId = seriesInfo.NameId;

                IDictionary <Guid, IList <MediaItemAspect> > episodeAspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                episodeInfo.SetMetadata(episodeAspects);
                MediaItemAspect.SetAttribute(episodeAspects, MediaAspect.ATTR_ISVIRTUAL, true);

                if (episodeAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    extractedLinkedAspects.Add(new RelationshipItem(episodeAspects, Guid.Empty));
                }
            }
            return(extractedLinkedAspects.Count > 0);
        }
        public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            if (!AudioMetadataExtractor.IncludeMusicLabelDetails)
            {
                return(false);
            }

            if (importOnly)
            {
                return(false);
            }

            AlbumInfo albumInfo = new AlbumInfo();

            if (!albumInfo.FromMetadata(aspects))
            {
                return(false);
            }

            if (CheckCacheContains(albumInfo))
            {
                return(false);
            }

            int count = 0;

            if (!AudioMetadataExtractor.SkipOnlineSearches)
            {
                OnlineMatcherService.Instance.UpdateAlbumCompanies(albumInfo, CompanyAspect.COMPANY_MUSIC_LABEL, importOnly);
                count = albumInfo.MusicLabels.Where(c => c.HasExternalId).Count();
                if (!albumInfo.IsRefreshed)
                {
                    albumInfo.HasChanged = true; //Force save to update external Ids for metadata found by other MDEs
                }
            }
            else
            {
                count = albumInfo.MusicLabels.Where(c => !string.IsNullOrEmpty(c.Name)).Count();
            }

            if (albumInfo.MusicLabels.Count == 0)
            {
                return(false);
            }

            if (BaseInfo.CountRelationships(aspects, LinkedRole) < count || (BaseInfo.CountRelationships(aspects, LinkedRole) == 0 && albumInfo.MusicLabels.Count > 0))
            {
                albumInfo.HasChanged = true; //Force save if no relationship exists
            }
            if (!albumInfo.HasChanged)
            {
                return(false);
            }

            AddToCheckCache(albumInfo);

            extractedLinkedAspects = new List <RelationshipItem>();
            foreach (CompanyInfo company in albumInfo.MusicLabels)
            {
                company.AssignNameId();
                company.HasChanged = albumInfo.HasChanged;
                IDictionary <Guid, IList <MediaItemAspect> > companyAspects = new Dictionary <Guid, IList <MediaItemAspect> >();
                company.SetMetadata(companyAspects);

                if (companyAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    Guid existingId;
                    if (TryGetIdFromCache(company, out existingId))
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(companyAspects, existingId));
                    }
                    else
                    {
                        extractedLinkedAspects.Add(new RelationshipItem(companyAspects, Guid.Empty));
                    }
                }
            }
            return(extractedLinkedAspects.Count > 0);
        }