From a9eed234ba2a366fe014f0cc6f462c3764528948 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 6 Oct 2014 19:30:05 -0400 Subject: [PATCH] fixes #931 - Downloading/Missing Art --- .../Movies/MovieDbProvider.cs | 71 ++++++++----------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index a27c8b54e..5b313edd9 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -156,7 +156,7 @@ namespace MediaBrowser.Providers.Movies CancellationToken = cancellationToken, AcceptHeader = AcceptHeader, CacheMode = CacheMode.Unconditional, - CacheLength = TimeSpan.FromDays(3) + CacheLength = TimeSpan.FromDays(1) }).ConfigureAwait(false)) { @@ -231,7 +231,7 @@ namespace MediaBrowser.Providers.Movies if (fileInfo.Exists) { // If it's recent or automatic updates are enabled, don't re-download - if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7) + if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 3) { return _cachedTask; } @@ -259,6 +259,31 @@ namespace MediaBrowser.Providers.Movies return Path.Combine(path, filename); } + public static string GetImageLanguagesParam(ILocalizationManager localization, string preferredLanguage) + { + var languages = new List(); + + if (!string.IsNullOrEmpty(preferredLanguage)) + { + languages.Add(preferredLanguage); + } + languages.Add("null"); + if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase)) + { + languages.Add("en"); + } + + var allLanguages = localization.GetCultures() + .Select(i => i.TwoLetterISOLanguageName) + .Distinct(StringComparer.OrdinalIgnoreCase) + .Where(i => !languages.Contains(i, StringComparer.OrdinalIgnoreCase)) + .ToList(); + + languages.AddRange(allLanguages); + + return string.Join(",", languages.ToArray()); + } + /// /// Fetches the main result. /// @@ -271,25 +296,12 @@ namespace MediaBrowser.Providers.Movies { var url = string.Format(GetMovieInfo3, id, ApiKey); - var imageLanguages = _localization.GetCultures() - .Select(i => i.TwoLetterISOLanguageName) - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToList(); - - imageLanguages.Add("null"); - if (!string.IsNullOrEmpty(language)) { - // If preferred language isn't english, get those images too - if (!imageLanguages.Contains(language, StringComparer.OrdinalIgnoreCase)) - { - imageLanguages.Add(language); - } - url += string.Format("&language={0}", language); } - var includeImageLanguageParam = string.Join(",", imageLanguages.ToArray()); + var includeImageLanguageParam = GetImageLanguagesParam(_localization, language); // Get images in english and with no language url += "&include_image_language=" + includeImageLanguageParam; @@ -342,35 +354,14 @@ namespace MediaBrowser.Providers.Movies return mainResult; } - private DateTime _lastRequestDate = DateTime.MinValue; - /// /// Gets the movie db response. /// - internal async Task GetMovieDbResponse(HttpRequestOptions options) + internal Task GetMovieDbResponse(HttpRequestOptions options) { - var cancellationToken = options.CancellationToken; + options.ResourcePool = MovieDbResourcePool; - await MovieDbResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - - try - { - var diff = 100 - (DateTime.Now - _lastRequestDate).TotalMilliseconds; - - if (diff > 0) - { - _logger.Debug("Throttling MovieDb by {0} ms", diff); - await Task.Delay(Convert.ToInt32(diff), cancellationToken).ConfigureAwait(false); - } - - return await _httpClient.Get(options).ConfigureAwait(false); - } - finally - { - _lastRequestDate = DateTime.Now; - - MovieDbResourcePool.Release(); - } + return _httpClient.Get(options); } public bool HasChanged(IHasMetadata item, DateTime date)