Ejemplo n.º 1
0
        public virtual async Task <bool> UpdateCollectionAsync(MovieCollectionInfo movieCollectionInfo, bool updateMovieList)
        {
            try
            {
                // Try online lookup
                if (!await InitAsync().ConfigureAwait(false))
                {
                    return(false);
                }

                TLang language = FindBestMatchingLanguage(movieCollectionInfo.Languages);
                bool  updated  = false;
                MovieCollectionInfo movieCollectionMatch = movieCollectionInfo.Clone();
                movieCollectionMatch.Movies.Clear();
                //Try updating from cache
                if (!await _wrapper.UpdateFromOnlineMovieCollectionAsync(movieCollectionMatch, language, true).ConfigureAwait(false))
                {
                    Logger.Debug(_id + ": Search for collection {0} online", movieCollectionInfo.ToString());

                    //Try to update movie collection information from online source
                    if (await _wrapper.UpdateFromOnlineMovieCollectionAsync(movieCollectionMatch, language, false).ConfigureAwait(false))
                    {
                        updated = true;
                    }
                }
                else
                {
                    Logger.Debug(_id + ": Found collection {0} in cache", movieCollectionInfo.ToString());
                    updated = true;
                }

                if (updated)
                {
                    movieCollectionInfo.MergeWith(movieCollectionMatch, true, updateMovieList);

                    if (updateMovieList)
                    {
                        foreach (MovieInfo movie in movieCollectionMatch.Movies)
                        {
                            IGenreConverter converter = ServiceRegistration.Get <IGenreConverter>();
                            foreach (var genre in movie.Genres)
                            {
                                if (!genre.Id.HasValue && converter.GetGenreId(genre.Name, GenreCategory.Movie, null, out int genreId))
                                {
                                    genre.Id = genreId;
                                }
                            }
                        }
                    }
                }

                return(updated);
            }
            catch (Exception ex)
            {
                Logger.Debug(_id + ": Exception while processing collection {0}", ex, movieCollectionInfo.ToString());
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void ExtractFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects, Guid?collectionMediaItemId, IDictionary <Guid, string> actorMediaItems)
        {
            if (aspects.ContainsKey(MovieAspect.ASPECT_ID))
            {
                if (BaseInfo.IsVirtualResource(aspects))
                {
                    return;
                }

                MovieInfo movieInfo = new MovieInfo();
                movieInfo.FromMetadata(aspects);
                bool forceFanart = !movieInfo.IsRefreshed;
                MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>();
                ExtractLocalImages(aspects, mediaItemId, collectionMediaItemId, movieInfo.ToString(), collectionInfo.ToString(), actorMediaItems);
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, movieInfo, forceFanart);
                }

                //Take advantage of the movie language being known and download collection too
                if (collectionMediaItemId.HasValue && !_checkCache.Contains(collectionMediaItemId.Value))
                {
                    if (!MovieMetadataExtractor.SkipFanArtDownload)
                    {
                        OnlineMatcherService.Instance.DownloadMovieFanArt(collectionMediaItemId.Value, collectionInfo, forceFanart);
                    }
                    _checkCache.Add(collectionMediaItemId.Value);
                }
            }
            else if (aspects.ContainsKey(PersonAspect.ASPECT_ID))
            {
                PersonInfo personInfo = new PersonInfo();
                personInfo.FromMetadata(aspects);
                if (personInfo.Occupation == PersonAspect.OCCUPATION_ACTOR || personInfo.Occupation == PersonAspect.OCCUPATION_DIRECTOR ||
                    personInfo.Occupation == PersonAspect.OCCUPATION_WRITER)
                {
                    if (!MovieMetadataExtractor.SkipFanArtDownload)
                    {
                        OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, personInfo, !personInfo.IsRefreshed);
                    }
                }
            }
            else if (aspects.ContainsKey(CharacterAspect.ASPECT_ID))
            {
                CharacterInfo characterInfo = new CharacterInfo();
                characterInfo.FromMetadata(aspects);
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, characterInfo, !characterInfo.IsRefreshed);
                }
            }
            else if (aspects.ContainsKey(CompanyAspect.ASPECT_ID))
            {
                CompanyInfo companyInfo = new CompanyInfo();
                companyInfo.FromMetadata(aspects);
                if (companyInfo.Type == CompanyAspect.COMPANY_PRODUCTION)
                {
                    if (!MovieMetadataExtractor.SkipFanArtDownload)
                    {
                        OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, companyInfo, !companyInfo.IsRefreshed);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected async Task ExtractMovieFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects)
        {
            bool             shouldCacheLocal = false;
            IResourceLocator mediaItemLocator = null;

            if (!BaseInfo.IsVirtualResource(aspects))
            {
                mediaItemLocator = GetResourceLocator(aspects);
                if (mediaItemLocator == null)
                {
                    return;
                }

                //Whether local fanart should be stored in the fanart cache
                shouldCacheLocal = ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath,
                                                          MovieMetadataExtractor.CacheLocalFanArt, MovieMetadataExtractor.CacheOfflineFanArt);
            }

            if (!shouldCacheLocal && MovieMetadataExtractor.SkipFanArtDownload)
            {
                return; //Nothing to do
            }
            MovieInfo movieInfo = new MovieInfo();

            movieInfo.FromMetadata(aspects);

            //Movie fanart
            if (AddToCache(mediaItemId))
            {
                //Actor fanart may be stored in the movie directory, so get the actors now
                IList <Tuple <Guid, string> > actors = null;
                if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out SingleMediaItemAspect videoAspect))
                {
                    var actorNames = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS);
                    if (actorNames != null)
                    {
                        RelationshipExtractorUtils.TryGetMappedLinkedIds(PersonAspect.ROLE_ACTOR, aspects, actorNames.ToList(), out actors);
                    }
                }
                if (shouldCacheLocal)
                {
                    await ExtractMovieFolderFanArt(mediaItemLocator, mediaItemId, movieInfo.ToString(), actors).ConfigureAwait(false);
                }
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(mediaItemId, movieInfo).ConfigureAwait(false);
                }
            }

            //Collection fanart
            if (RelationshipExtractorUtils.TryGetLinkedId(MovieCollectionAspect.ROLE_MOVIE_COLLECTION, aspects, out Guid collectionMediaItemId) &&
                AddToCache(collectionMediaItemId))
            {
                MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>();
                if (shouldCacheLocal)
                {
                    await ExtractCollectionFolderFanArt(mediaItemLocator, collectionMediaItemId, collectionInfo.ToString()).ConfigureAwait(false);
                }
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(collectionMediaItemId, collectionInfo).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 4
0
        protected async Task ExtractMovieFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects)
        {
            bool             shouldCacheLocal = false;
            IResourceLocator mediaItemLocator = null;

            if (!BaseInfo.IsVirtualResource(aspects))
            {
                mediaItemLocator = GetResourceLocator(aspects);

                //Whether local fanart should be stored in the fanart cache
                shouldCacheLocal = ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath,
                                                          MovieMetadataExtractor.CacheLocalFanArt, MovieMetadataExtractor.CacheOfflineFanArt);
            }

            if (mediaItemLocator == null)
            {
                return;
            }

            if (!shouldCacheLocal && MovieMetadataExtractor.SkipFanArtDownload)
            {
                return; //Nothing to do
            }
            MovieInfo movieInfo = new MovieInfo();

            movieInfo.FromMetadata(aspects);

            //Movie fanart
            if (AddToCache(mediaItemId))
            {
                //Actor fanart may be stored in the movie directory, so get the actors now
                IList <Tuple <Guid, string> > actors = null;
                if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out SingleMediaItemAspect videoAspect))
                {
                    var actorNames = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS);
                    if (actorNames != null)
                    {
                        RelationshipExtractorUtils.TryGetMappedLinkedIds(PersonAspect.ROLE_ACTOR, aspects, actorNames.ToList(), out actors);
                    }
                }
                if (shouldCacheLocal)
                {
                    await ExtractMovieFolderFanArt(mediaItemLocator, mediaItemId, movieInfo.ToString(), actors).ConfigureAwait(false);
                }
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(mediaItemId, movieInfo).ConfigureAwait(false);
                }

                //Find central actor information folder
                var          seriesDirectory        = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../");
                ResourcePath centralActorFolderPath = LocalFanartHelper.GetCentralPersonFolder(seriesDirectory, CentralPersonFolderType.MovieActors);
                if (shouldCacheLocal && centralActorFolderPath != null && actors != null)
                {
                    foreach (var actor in actors)
                    {
                        // Check if we already processed this actor
                        if (!AddToCache(actor.Item1))
                        {
                            continue;
                        }

                        // First get the ResourcePath of the central directory
                        var artistFolderPath = ResourcePathHelper.Combine(centralActorFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(actor.Item2)}/");
                        using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, artistFolderPath).CreateAccessor())
                        {
                            if (accessor is IFileSystemResourceAccessor directoryAccessor)
                            {
                                FanArtPathCollection paths = new FanArtPathCollection();
                                List <ResourcePath>  potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryAccessor);
                                ExtractAllFanArtImages(potentialFanArtFiles, paths);
                                await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, actor.Item1, actor.Item2).ConfigureAwait(false);
                            }
                        }
                    }
                }
            }

            //Collection fanart
            if (RelationshipExtractorUtils.TryGetLinkedId(MovieCollectionAspect.ROLE_MOVIE_COLLECTION, aspects, out Guid collectionMediaItemId) &&
                AddToCache(collectionMediaItemId))
            {
                MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>();
                if (shouldCacheLocal)
                {
                    await ExtractCollectionFolderFanArt(mediaItemLocator, collectionMediaItemId, collectionInfo.ToString()).ConfigureAwait(false);
                }
                if (!MovieMetadataExtractor.SkipFanArtDownload)
                {
                    await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(collectionMediaItemId, collectionInfo).ConfigureAwait(false);
                }
            }
        }