From e93700f9f80e157ced4da8d5209ddc0c1a30f8e1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 26 Dec 2013 22:48:05 -0500 Subject: [PATCH] support new tmdb param to get all images in one response --- .../Movies/ManualMovieDbImageProvider.cs | 2 +- .../Movies/MovieDbImagesProvider.cs | 2 +- .../Movies/MovieDbProvider.cs | 65 ++++++------------- 3 files changed, 23 insertions(+), 46 deletions(-) diff --git a/MediaBrowser.Providers/Movies/ManualMovieDbImageProvider.cs b/MediaBrowser.Providers/Movies/ManualMovieDbImageProvider.cs index 1cbbca9c7..b9cabded7 100644 --- a/MediaBrowser.Providers/Movies/ManualMovieDbImageProvider.cs +++ b/MediaBrowser.Providers/Movies/ManualMovieDbImageProvider.cs @@ -150,7 +150,7 @@ namespace MediaBrowser.Providers.Movies /// Task{MovieImages}. private MovieDbProvider.Images FetchImages(IHasImages item, IJsonSerializer jsonSerializer) { - var path = MovieDbProvider.Current.GetImagesDataFilePath((BaseItem)item); + var path = MovieDbProvider.Current.GetDataFilePath((BaseItem)item); if (!string.IsNullOrEmpty(path)) { diff --git a/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs b/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs index 4416671fa..7386f47f4 100644 --- a/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbImagesProvider.cs @@ -144,7 +144,7 @@ namespace MediaBrowser.Providers.Movies protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo) { - var path = MovieDbProvider.Current.GetImagesDataFilePath(item); + var path = MovieDbProvider.Current.GetDataFilePath(item); if (!string.IsNullOrEmpty(path)) { diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index b66dd95b5..52647b8a3 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -205,13 +205,9 @@ namespace MediaBrowser.Providers.Movies if (!string.IsNullOrEmpty(path)) { - var imagesFilePath = GetImagesDataFilePath(item); - var fileInfo = new FileInfo(path); - var imagesFileInfo = new FileInfo(imagesFilePath); - return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > providerInfo.LastRefreshed || - !imagesFileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(imagesFileInfo) > providerInfo.LastRefreshed; + return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > providerInfo.LastRefreshed; } return base.NeedsRefreshBasedOnCompareDate(item, providerInfo); @@ -508,10 +504,10 @@ namespace MediaBrowser.Providers.Movies var tmdbId = item.GetProviderId(MetadataProviders.Tmdb); - if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath) || !File.Exists(GetImagesDataFilePath(item))) - { - var isBoxSet = item is BoxSet; + var isBoxSet = item is BoxSet; + if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath)) + { var mainResult = await FetchMainResult(id, isBoxSet, language, cancellationToken).ConfigureAwait(false); if (mainResult == null) return; @@ -520,25 +516,18 @@ namespace MediaBrowser.Providers.Movies var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxSet, tmdbId); - dataFilePath = Path.Combine(movieDataPath, language + ".json"); + dataFilePath = Path.Combine(movieDataPath, "all.json"); var directory = Path.GetDirectoryName(dataFilePath); Directory.CreateDirectory(directory); JsonSerializer.SerializeToFile(mainResult, dataFilePath); - - // Now get the language-less version - mainResult = await FetchMainResult(id, isBoxSet, null, cancellationToken).ConfigureAwait(false); - - dataFilePath = Path.Combine(movieDataPath, "default.json"); - - JsonSerializer.SerializeToFile(mainResult, dataFilePath); } if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item)) { - dataFilePath = GetDataFilePath(item, tmdbId, language); + dataFilePath = GetDataFilePath(isBoxSet, tmdbId); if (!string.IsNullOrEmpty(dataFilePath)) { @@ -564,18 +553,11 @@ namespace MediaBrowser.Providers.Movies if (mainResult == null) return; - var dataFilePath = Path.Combine(dataPath, preferredMetadataLanguage + ".json"); + var dataFilePath = Path.Combine(dataPath, "all.json"); Directory.CreateDirectory(dataPath); JsonSerializer.SerializeToFile(mainResult, dataFilePath); - - // Now get the language-less version - mainResult = await FetchMainResult(id, isBoxSet, null, cancellationToken).ConfigureAwait(false); - - dataFilePath = Path.Combine(dataPath, "default.json"); - - JsonSerializer.SerializeToFile(mainResult, dataFilePath); } /// @@ -592,28 +574,14 @@ namespace MediaBrowser.Providers.Movies return null; } - return GetDataFilePath(item, id, item.GetPreferredMetadataLanguage()); + return GetDataFilePath(item is BoxSet, id); } - internal string GetDataFilePath(BaseItem item, string tmdbId, string preferredLanguage) + internal string GetDataFilePath(bool isBoxset, string tmdbId) { - var path = GetMovieDataPath(ConfigurationManager.ApplicationPaths, item is BoxSet, tmdbId); + var path = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxset, tmdbId); - path = Path.Combine(path, preferredLanguage + ".json"); - - return path; - } - - internal string GetImagesDataFilePath(BaseItem item) - { - var path = GetDataFilePath(item); - - if (!string.IsNullOrEmpty(path)) - { - path = Path.Combine(Path.GetDirectoryName(path), "default.json"); - } - - return path; + return Path.Combine(path, "all.json"); } /// @@ -630,9 +598,18 @@ namespace MediaBrowser.Providers.Movies var url = string.Format(baseUrl, id, ApiKey); + // Get images in english and with no language + url += "&include_image_language=en,null"; + if (!string.IsNullOrEmpty(language)) { - url += "&language=" + language; + // If preferred language isn't english, get those images too + if (!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) + { + url += string.Format(",{0}", language); + } + + url += string.Format("&language={0}", language); } CompleteMovieData mainResult;