Ejemplo n.º 1
0
        public override Task <bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
        {
            var album = (MusicAlbum)item;

            BaseProviderInfo data;

            if (!item.ProviderData.TryGetValue(Id, out data))
            {
                data = new BaseProviderInfo();
                item.ProviderData[Id] = data;
            }

            var songs = album.RecursiveChildren.OfType <Audio>().ToList();

            if (!item.LockedFields.Contains(MetadataFields.Name))
            {
                var name = songs.Select(i => i.Album).FirstOrDefault(i => !string.IsNullOrEmpty(i));

                if (!string.IsNullOrEmpty(name))
                {
                    album.Name = name;
                }
            }

            var date = songs.Select(i => i.PremiereDate).FirstOrDefault(i => i.HasValue);

            if (date != null)
            {
                album.PremiereDate   = date.Value;
                album.ProductionYear = date.Value.Year;
            }
            else
            {
                var year = songs.Select(i => i.ProductionYear ?? 1800).FirstOrDefault(i => i != 1800);

                if (year != 1800)
                {
                    album.ProductionYear = year;
                }
            }

            if (!item.LockedFields.Contains(MetadataFields.Studios))
            {
                album.Studios = songs.SelectMany(i => i.Studios)
                                .Distinct(StringComparer.OrdinalIgnoreCase)
                                .ToList();
            }

            if (!item.LockedFields.Contains(MetadataFields.Genres))
            {
                album.Genres = songs.SelectMany(i => i.Genres)
                               .Distinct(StringComparer.OrdinalIgnoreCase)
                               .ToList();
            }

            data.FileStamp = GetComparisonData(songs);

            SetLastRefreshed(item, DateTime.UtcNow);
            return(TrueTaskResult);
        }
Ejemplo n.º 2
0
        public override Task <bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
        {
            var artist = (MusicArtist)item;

            BaseProviderInfo data;

            if (!item.ProviderData.TryGetValue(Id, out data))
            {
                data = new BaseProviderInfo();
                item.ProviderData[Id] = data;
            }

            var songs = artist.RecursiveChildren.OfType <Audio>().ToList();

            if (!item.LockedFields.Contains(MetadataFields.Genres))
            {
                artist.Genres = songs.SelectMany(i => i.Genres)
                                .Distinct(StringComparer.OrdinalIgnoreCase)
                                .ToList();
            }

            data.FileStamp = GetComparisonData(songs);

            SetLastRefreshed(item, DateTime.UtcNow);
            return(TrueTaskResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="force"></param>
        /// <param name="providerInfo"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
        {
            await Fetch(item, providerInfo, cancellationToken).ConfigureAwait(false);

            SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
            {
                return(false);
            }

            if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
                !ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
                !ConfigurationManager.Configuration.DownloadMovieImages.Disc &&
                !ConfigurationManager.Configuration.DownloadMovieImages.Backdrops &&
                !ConfigurationManager.Configuration.DownloadMovieImages.Banner &&
                !ConfigurationManager.Configuration.DownloadMovieImages.Thumb)
            {
                return(false);
            }

            if (item.HasImage(ImageType.Art) &&
                item.HasImage(ImageType.Logo) &&
                item.HasImage(ImageType.Disc) &&
                item.HasImage(ImageType.Banner) &&
                item.HasImage(ImageType.Thumb) &&
                item.BackdropImagePaths.Count > 0)
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 5
0
        protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
        {
            var seriesId = item.GetProviderId(MetadataProviders.Tvdb);

            if (!string.IsNullOrEmpty(seriesId))
            {
                // Process images
                var path = GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId);

                try
                {
                    var files = new DirectoryInfo(path)
                                .EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly)
                                .Select(i => _fileSystem.GetLastWriteTimeUtc(i))
                                .ToList();

                    if (files.Count > 0)
                    {
                        return(files.Max() > providerInfo.LastRefreshed);
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    // Don't blow up
                    return(true);
                }
            }

            return(base.NeedsRefreshBasedOnCompareDate(item, providerInfo));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{System.Boolean}.</returns>
        public override async Task <bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            BaseProviderInfo data;

            if (!item.ProviderData.TryGetValue(Id, out data))
            {
                data = new BaseProviderInfo();
                item.ProviderData[Id] = data;
            }

            var movieId = item.GetProviderId(MetadataProviders.Tmdb);

            var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, movieId);
            var xmlPath       = Path.Combine(movieDataPath, "fanart.xml");

            // Only download the xml if it doesn't already exist. The prescan task will take care of getting updates
            if (!File.Exists(xmlPath))
            {
                await DownloadMovieXml(movieDataPath, movieId, cancellationToken).ConfigureAwait(false);
            }

            if (File.Exists(xmlPath))
            {
                await FetchFromXml(item, xmlPath, cancellationToken).ConfigureAwait(false);
            }

            SetLastRefreshed(item, DateTime.UtcNow);
            return(true);
        }
        /// <summary>
        /// Fetches the async internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{System.Boolean}.</returns>
        private async Task FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
        {
            BaseProviderInfo data;

            if (!item.ProviderData.TryGetValue(Id, out data))
            {
                data = new BaseProviderInfo();
                item.ProviderData[Id] = data;
            }

            var imdbId = item.GetProviderId(MetadataProviders.Imdb);

            if (string.IsNullOrEmpty(imdbId))
            {
                data.LastRefreshStatus = ProviderRefreshStatus.Success;
                return;
            }

            var apiKey = GetApiKey();

            if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.RottenTomatoes)))
            {
                await FetchRottenTomatoesId(item, apiKey, cancellationToken).ConfigureAwait(false);
            }

            // If still empty we can't continue
            if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.RottenTomatoes)))
            {
                data.LastRefreshStatus = ProviderRefreshStatus.Success;
                return;
            }

            RequestHistory.Add(DateTime.UtcNow);

            using (var stream = await HttpClient.Get(new HttpRequestOptions
            {
                Url = GetMovieReviewsUrl(item.GetProviderId(MetadataProviders.RottenTomatoes), apiKey),
                ResourcePool = _rottenTomatoesResourcePool,
                CancellationToken = cancellationToken
            }).ConfigureAwait(false))
            {
                var result = JsonSerializer.DeserializeFromStream <RTReviewList>(stream);

                var criticReviews = result.reviews.Select(rtReview => new ItemReview
                {
                    ReviewerName = rtReview.critic,
                    Publisher    = rtReview.publication,
                    Date         = DateTime.Parse(rtReview.date).ToUniversalTime(),
                    Caption      = rtReview.quote,
                    Url          = rtReview.links.review,
                    Likes        = string.Equals(rtReview.freshness, "fresh", StringComparison.OrdinalIgnoreCase)
                }).ToList();

                await _itemRepo.SaveCriticReviews(item.Id, criticReviews).ConfigureAwait(false);
            }

            data.LastRefreshStatus = ProviderRefreshStatus.Success;
            SetLastRefreshed(item, DateTime.UtcNow);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="providerInfo"></param>
        /// <returns></returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            //if (string.IsNullOrEmpty(item.GetProviderId("GoogleBooks")))
            //    return false;

            //return base.NeedsRefreshInternal(item, providerInfo);
            return(false);
        }
Ejemplo n.º 9
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            //if (HasLocalMeta(item))
            //    return false;

            //return base.NeedsRefreshInternal(item, providerInfo);
            return(false);
        }
Ejemplo n.º 10
0
 protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
 {
     if (item.HasImage(ImageType.Primary) && item.HasImage(ImageType.Banner) && item.BackdropImagePaths.Count > 0)
     {
         return(false);
     }
     return(base.NeedsRefreshInternal(item, providerInfo));
 }
Ejemplo n.º 11
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (HasAltMeta(item) && !ConfigurationManager.Configuration.EnableTmdbUpdates)
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
        // Need to re-override to jump over intermediate implementation
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (!item.ResolveArgs.ContainsMetaFileByName(MetaFileName))
            {
                return(false);
            }

            return(CompareDate(item) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb)))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (item.HasImage(ImageType.Primary))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 15
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (HasAltMeta(item))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (!item.ResolveArgs.ContainsMetaFileByName(LastfmHelper.LocalArtistMetaFileName))
            {
                return false; // nothing to read
            }

            // Need to re-override to jump over intermediate implementation
            return CompareDate(item) > providerInfo.LastRefreshed;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // Force a refresh if the IBN path changed
            if (providerInfo.FileStamp != ConfigurationManager.ApplicationPaths.ItemsByNamePath.GetMD5())
            {
                return(true);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // These values are now saved in movie.xml, so don't refresh if they're present
            if (MovieDbProvider.HasAltMeta(item) && item.CriticRating.HasValue && !string.IsNullOrEmpty(item.CriticRatingSummary))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // Don't proceed if there's local metadata
            if (HasLocalMeta(item) && !ConfigurationManager.Configuration.EnableTvDbUpdates)
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 20
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (!item.ResolveArgs.ContainsMetaFileByName(LastfmHelper.LocalArtistMetaFileName))
            {
                return(false); // nothing to read
            }

            // Need to re-override to jump over intermediate implementation
            return(CompareDate(item) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // Don't proceed if there's local metadata
            if (HasLocalMeta(item))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 22
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // If song metadata has changed
            if (GetComparisonData((MusicAlbum)item) != providerInfo.FileStamp)
            {
                return(true);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            var video = (Video)item;

            if (!QualifiesForExtraction(video))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 24
0
        protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
        {
            var xml = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, XmlFileName));

            if (xml == null)
            {
                return(false);
            }

            return(_fileSystem.GetLastWriteTimeUtc(xml) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            // If the last run wasn't successful, try again when there's a new version of ffmpeg
            if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
            {
                if (!string.Equals(ProviderVersion, providerInfo.ProviderVersion))
                {
                    return(true);
                }
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 26
0
        protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
        {
            var savePath = MovieXmlSaver.GetMovieSavePath(item);

            var xml = item.ResolveArgs.GetMetaFileByPath(savePath) ?? new FileInfo(savePath);

            if (!xml.Exists)
            {
                return(false);
            }

            return(_fileSystem.GetLastWriteTimeUtc(xml) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Needses the refresh based on compare date.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
        {
            var metadataFile = Path.Combine(item.MetaLocation, Path.ChangeExtension(Path.GetFileName(item.Path), ".xml"));

            var file = item.ResolveArgs.Parent.ResolveArgs.GetMetaFileByPath(metadataFile);

            if (file == null)
            {
                return(false);
            }

            return(_fileSystem.GetLastWriteTimeUtc(file) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (item.HasImage(ImageType.Primary))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(GetImageUrl(item)))
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
            {
                return(false);
            }

            // Don't refresh if we already have both poster and backdrop and we're not refreshing images
            if (item.HasImage(ImageType.Primary) && item.BackdropImagePaths.Count > 0)
            {
                return(false);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Needses the refresh internal.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="providerInfo">The provider info.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME))
            {
                return(false); // don't read our file if 3rd party data exists
            }

            if (!item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME))
            {
                return(false); // nothing to read
            }

            // Need to re-override to jump over intermediate implementation
            return(CompareDate(item) > providerInfo.LastRefreshed);
        }
Ejemplo n.º 31
0
        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
        {
            if (HasAltMeta(item))
            {
                return(false);
            }

            // Boxsets require two passes because we need the children to be refreshed
            if (item is BoxSet && string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.TmdbCollection)))
            {
                return(true);
            }

            return(base.NeedsRefreshInternal(item, providerInfo));
        }