Пример #1
0
 public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization)
 {
     _jsonSerializer       = jsonSerializer;
     _httpClient           = httpClient;
     _fileSystem           = fileSystem;
     _configurationManager = configurationManager;
     _logger       = logger;
     _localization = localization;
     Current       = this;
 }
        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));
        }
Пример #3
0
        /// <summary>
        /// Runs the specified progress.
        /// </summary>
        /// <param name="progress">The progress.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task Run(IProgress <double> progress, CancellationToken cancellationToken)
        {
            if (!_config.Configuration.EnableTmdbUpdates)
            {
                progress.Report(100);
                return;
            }

            var path = MovieDbProvider.GetMoviesDataPath(_config.CommonApplicationPaths);

            Directory.CreateDirectory(path);

            var timestampFile = Path.Combine(path, "time.txt");

            var timestampFileInfo = new FileInfo(timestampFile);

            // Don't check for updates every single time
            if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 7)
            {
                return;
            }

            // Find out the last time we queried tvdb for updates
            var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;

            var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();

            if (!string.IsNullOrEmpty(lastUpdateTime))
            {
                long lastUpdateTicks;

                if (long.TryParse(lastUpdateTime, NumberStyles.Any, UsCulture, out lastUpdateTicks))
                {
                    var lastUpdateDate = new DateTime(lastUpdateTicks, DateTimeKind.Utc);

                    // They only allow up to 14 days of updates
                    if ((DateTime.UtcNow - lastUpdateDate).TotalDays > 13)
                    {
                        lastUpdateDate = DateTime.UtcNow.AddDays(-13);
                    }

                    var updatedIds = await GetIdsToUpdate(lastUpdateDate, 1, cancellationToken).ConfigureAwait(false);

                    var existingDictionary = existingDirectories.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

                    var idsToUpdate = updatedIds.Where(i => !string.IsNullOrWhiteSpace(i) && existingDictionary.ContainsKey(i));

                    await UpdateMovies(idsToUpdate, progress, cancellationToken).ConfigureAwait(false);
                }
            }

            File.WriteAllText(timestampFile, DateTime.UtcNow.Ticks.ToString(UsCulture), Encoding.UTF8);
            progress.Report(100);
        }
Пример #4
0
 public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IApplicationHost appHost)
 {
     _jsonSerializer       = jsonSerializer;
     _httpClient           = httpClient;
     _fileSystem           = fileSystem;
     _configurationManager = configurationManager;
     _logger         = logger;
     _localization   = localization;
     _libraryManager = libraryManager;
     _appHost        = appHost;
     Current         = this;
 }
        /// <summary>
        /// Gets the backdrops.
        /// </summary>
        /// <param name="images">The images.</param>
        /// <returns>IEnumerable{MovieDbProvider.Backdrop}.</returns>
        private IEnumerable<MovieDbProvider.Backdrop> GetBackdrops(MovieDbProvider.Images images)
        {
            var eligibleBackdrops = images.backdrops == null ? new List<MovieDbProvider.Backdrop>() :
                images.backdrops
                .ToList();

            return eligibleBackdrops.OrderByDescending(i => i.vote_average)
                .ThenByDescending(i => i.vote_count);
        }
 /// <summary>
 /// Gets the posters.
 /// </summary>
 /// <param name="images">The images.</param>
 /// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
 private IEnumerable<MovieDbProvider.Poster> GetPosters(MovieDbProvider.Images images)
 {
     return images.posters ?? new List<MovieDbProvider.Poster>();
 }
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(IHasImages item, CancellationToken cancellationToken)
        {
            var list = new List <RemoteImageInfo>();

            var language = item.GetPreferredMetadataLanguage();

            var results = await FetchImages((BaseItem)item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false);

            if (results == null)
            {
                return(list);
            }

            var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);

            var tmdbImageUrl = tmdbSettings.images.secure_base_url + "original";

            var supportedImages = GetSupportedImages(item).ToList();

            if (supportedImages.Contains(ImageType.Primary))
            {
                list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo
                {
                    Url             = tmdbImageUrl + i.file_path,
                    CommunityRating = i.vote_average,
                    VoteCount       = i.vote_count,
                    Width           = i.width,
                    Height          = i.height,
                    Language        = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
                    ProviderName    = Name,
                    Type            = ImageType.Primary,
                    RatingType      = RatingType.Score
                }));
            }

            if (supportedImages.Contains(ImageType.Backdrop))
            {
                list.AddRange(GetBackdrops(results).Select(i => new RemoteImageInfo
                {
                    Url             = tmdbImageUrl + i.file_path,
                    CommunityRating = i.vote_average,
                    VoteCount       = i.vote_count,
                    Width           = i.width,
                    Height          = i.height,
                    ProviderName    = Name,
                    Type            = ImageType.Backdrop,
                    RatingType      = RatingType.Score
                }));
            }

            var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);

            return(list.OrderByDescending(i =>
            {
                if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase))
                {
                    return 3;
                }
                if (!isLanguageEn)
                {
                    if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
                    {
                        return 2;
                    }
                }
                if (string.IsNullOrEmpty(i.Language))
                {
                    return isLanguageEn ? 3 : 2;
                }
                return 0;
            })
                   .ThenByDescending(i => i.CommunityRating ?? 0)
                   .ThenByDescending(i => i.VoteCount ?? 0)
                   .ToList());
        }
        /// <summary>
        /// Gets the posters.
        /// </summary>
        /// <param name="images">The images.</param>
        /// <param name="item">The item.</param>
        /// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
        private IEnumerable<MovieDbProvider.Poster> GetPosters(MovieDbProvider.Images images, BaseItem item)
        {
            var language = _config.Configuration.PreferredMetadataLanguage;

            return images.posters ?? new List<MovieDbProvider.Poster>();
        }