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

            if (!importOnly) //Only during import
            {
                return(false);
            }

            MovieInfo movieInfo = new MovieInfo();

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

            MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>();

            if (collectionInfo.CollectionName.IsEmpty || collectionInfo.HasExternalId)
            {
                return(false);
            }

            extractedLinkedAspects = new List <RelationshipItem>();

            IDictionary <Guid, IList <MediaItemAspect> > collectionAspects = new Dictionary <Guid, IList <MediaItemAspect> >();

            //Create custom collection
            collectionInfo.AssignNameId();
            collectionInfo.SetMetadata(collectionAspects);

            bool movieVirtual = true;

            if (MediaItemAspect.TryGetAttribute(aspects, MediaAspect.ATTR_ISVIRTUAL, false, out movieVirtual))
            {
                MediaItemAspect.SetAttribute(collectionAspects, MediaAspect.ATTR_ISVIRTUAL, movieVirtual);
            }

            if (collectionAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
            {
                extractedLinkedAspects.Add(new RelationshipItem(collectionAspects, Guid.Empty));
            }

            return(extractedLinkedAspects.Count > 0);
        }
Exemplo n.º 2
0
        public async Task <bool> TryExtractRelationshipsAsync(IResourceAccessor mediaItemAccessor, IDictionary <Guid, IList <MediaItemAspect> > aspects, IList <IDictionary <Guid, IList <MediaItemAspect> > > extractedLinkedAspects)
        {
            MovieInfo movieInfo = new MovieInfo();

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

            MovieCollectionInfo collectionInfo = RelationshipExtractorUtils.TryCreateInfoFromLinkedAspects(extractedLinkedAspects, out List <MovieCollectionInfo> collection) ?
                                                 collection[0] : movieInfo.CloneBasicInstance <MovieCollectionInfo>();

            if (!MovieMetadataExtractor.SkipOnlineSearches && collectionInfo.HasExternalId)
            {
                await OnlineMatcherService.Instance.UpdateCollectionAsync(collectionInfo, false).ConfigureAwait(false);
            }

            IDictionary <Guid, IList <MediaItemAspect> > collectionAspects = collectionInfo.LinkedAspects != null ?
                                                                             collectionInfo.LinkedAspects : new Dictionary <Guid, IList <MediaItemAspect> >();

            collectionInfo.SetMetadata(collectionAspects);

            bool movieVirtual = true;

            if (MediaItemAspect.TryGetAttribute(aspects, MediaAspect.ATTR_ISVIRTUAL, false, out movieVirtual))
            {
                MediaItemAspect.SetAttribute(collectionAspects, MediaAspect.ATTR_ISVIRTUAL, movieVirtual);
            }

            if (!collectionAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
            {
                return(false);
            }

            if (collectionInfo.LinkedAspects == null)
            {
                extractedLinkedAspects.Add(collectionAspects);
            }
            return(extractedLinkedAspects.Count > 0);
        }
        public bool TryExtractRelationships(IDictionary <Guid, IList <MediaItemAspect> > aspects, bool importOnly, out IList <RelationshipItem> extractedLinkedAspects)
        {
            extractedLinkedAspects = null;

            MovieInfo movieInfo = new MovieInfo();

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

            MovieCollectionInfo cachedCollection;
            Guid collectionId;
            MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>();

            if (TryGetInfoFromCache(collectionInfo, out cachedCollection, out collectionId))
            {
                collectionInfo = cachedCollection;
            }
            else if (!MovieMetadataExtractor.SkipOnlineSearches && collectionInfo.HasExternalId)
            {
                OnlineMatcherService.Instance.UpdateCollection(collectionInfo, false, false);
            }

            bool hasId = false;

            if (!MovieMetadataExtractor.SkipOnlineSearches)
            {
                hasId = collectionInfo.HasExternalId || !string.IsNullOrEmpty(movieInfo.CollectionNameId);
            }
            else
            {
                hasId = !string.IsNullOrEmpty(movieInfo.CollectionNameId);
            }

            if (!BaseInfo.HasRelationship(aspects, LinkedRole) && hasId)
            {
                collectionInfo.HasChanged = true; //Force save if no relationship exists
            }
            if (!collectionInfo.HasChanged && !importOnly)
            {
                return(false);
            }

            extractedLinkedAspects = new List <RelationshipItem>();

            IDictionary <Guid, IList <MediaItemAspect> > collectionAspects = new Dictionary <Guid, IList <MediaItemAspect> >();

            if (collectionId != Guid.Empty)
            {
                collectionInfo.SetMetadata(collectionAspects);

                bool movieVirtual = true;
                if (MediaItemAspect.TryGetAttribute(aspects, MediaAspect.ATTR_ISVIRTUAL, false, out movieVirtual))
                {
                    MediaItemAspect.SetAttribute(collectionAspects, MediaAspect.ATTR_ISVIRTUAL, movieVirtual);
                }

                if (collectionAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    extractedLinkedAspects.Add(new RelationshipItem(collectionAspects, collectionId));
                }
            }
            else
            {
                //Create custom collection
                if (!string.IsNullOrEmpty(movieInfo.CollectionNameId) && !collectionInfo.HasExternalId)
                {
                    collectionInfo            = movieInfo.CloneBasicInstance <MovieCollectionInfo>();
                    collectionInfo.HasChanged = true;
                }
                collectionInfo.SetMetadata(collectionAspects);

                bool movieVirtual = true;
                if (MediaItemAspect.TryGetAttribute(aspects, MediaAspect.ATTR_ISVIRTUAL, false, out movieVirtual))
                {
                    MediaItemAspect.SetAttribute(collectionAspects, MediaAspect.ATTR_ISVIRTUAL, movieVirtual);
                }

                if (collectionAspects.ContainsKey(ExternalIdentifierAspect.ASPECT_ID))
                {
                    extractedLinkedAspects.Add(new RelationshipItem(collectionAspects, Guid.Empty));
                }
            }

            return(extractedLinkedAspects.Count > 0);
        }