use tmdb updates for images
This commit is contained in:
parent
32cb872b06
commit
c997effcb1
|
@ -9,6 +9,7 @@ using MediaBrowser.Model.Logging;
|
|||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -142,6 +143,23 @@ namespace MediaBrowser.Providers.Movies
|
|||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
return fileInfo.LastWriteTimeUtc > providerInfo.LastRefreshed;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
|
@ -151,18 +169,15 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <returns>Task{System.Boolean}.</returns>
|
||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
BaseProviderInfo data;
|
||||
var images = FetchImages(item, item.GetProviderId(MetadataProviders.Tmdb), cancellationToken);
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out data))
|
||||
var status = ProviderRefreshStatus.Success;
|
||||
|
||||
if (images != null)
|
||||
{
|
||||
data = new BaseProviderInfo();
|
||||
item.ProviderData[Id] = data;
|
||||
status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var images = await FetchImages(item, item.GetProviderId(MetadataProviders.Tmdb), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
SetLastRefreshed(item, DateTime.UtcNow, status);
|
||||
return true;
|
||||
}
|
||||
|
@ -174,20 +189,23 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <param name="id">The id.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{MovieImages}.</returns>
|
||||
private async Task<MovieImages> FetchImages(BaseItem item, string id, CancellationToken cancellationToken)
|
||||
private MovieDbProvider.Images FetchImages(BaseItem item, string id, CancellationToken cancellationToken)
|
||||
{
|
||||
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
||||
{
|
||||
Url = string.Format(GetImages, id, MovieDbProvider.ApiKey, item is BoxSet ? "collection" : "movie"),
|
||||
CancellationToken = cancellationToken,
|
||||
AcceptHeader = MovieDbProvider.AcceptHeader
|
||||
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
return _jsonSerializer.DeserializeFromStream<MovieImages>(json);
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
return _jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the images.
|
||||
/// </summary>
|
||||
|
@ -195,14 +213,14 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <param name="images">The images.</param>
|
||||
/// <param name="cancellationToken">The cancellation token</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected virtual async Task<ProviderRefreshStatus> ProcessImages(BaseItem item, MovieImages images, CancellationToken cancellationToken)
|
||||
private async Task<ProviderRefreshStatus> ProcessImages(BaseItem item, MovieDbProvider.Images images, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var status = ProviderRefreshStatus.Success;
|
||||
|
||||
var eligiblePosters = images.posters == null ?
|
||||
new List<Poster>() :
|
||||
new List<MovieDbProvider.Poster>() :
|
||||
images.posters.Where(i => i.width >= ConfigurationManager.Configuration.MinMoviePosterWidth)
|
||||
.ToList();
|
||||
|
||||
|
@ -255,7 +273,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var eligibleBackdrops = images.backdrops == null ? new List<Backdrop>() :
|
||||
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbProvider.Backdrop>() :
|
||||
images.backdrops.Where(i => i.width >= ConfigurationManager.Configuration.MinMovieBackdropWidth)
|
||||
.ToList();
|
||||
|
||||
|
@ -294,107 +312,5 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class Backdrop
|
||||
/// </summary>
|
||||
protected class Backdrop
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the file_path.
|
||||
/// </summary>
|
||||
/// <value>The file_path.</value>
|
||||
public string file_path { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the width.
|
||||
/// </summary>
|
||||
/// <value>The width.</value>
|
||||
public int width { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the height.
|
||||
/// </summary>
|
||||
/// <value>The height.</value>
|
||||
public int height { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the iso_639_1.
|
||||
/// </summary>
|
||||
/// <value>The iso_639_1.</value>
|
||||
public string iso_639_1 { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the aspect_ratio.
|
||||
/// </summary>
|
||||
/// <value>The aspect_ratio.</value>
|
||||
public double aspect_ratio { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the vote_average.
|
||||
/// </summary>
|
||||
/// <value>The vote_average.</value>
|
||||
public double vote_average { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the vote_count.
|
||||
/// </summary>
|
||||
/// <value>The vote_count.</value>
|
||||
public int vote_count { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class Poster
|
||||
/// </summary>
|
||||
protected class Poster
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the file_path.
|
||||
/// </summary>
|
||||
/// <value>The file_path.</value>
|
||||
public string file_path { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the width.
|
||||
/// </summary>
|
||||
/// <value>The width.</value>
|
||||
public int width { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the height.
|
||||
/// </summary>
|
||||
/// <value>The height.</value>
|
||||
public int height { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the iso_639_1.
|
||||
/// </summary>
|
||||
/// <value>The iso_639_1.</value>
|
||||
public string iso_639_1 { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the aspect_ratio.
|
||||
/// </summary>
|
||||
/// <value>The aspect_ratio.</value>
|
||||
public double aspect_ratio { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the vote_average.
|
||||
/// </summary>
|
||||
/// <value>The vote_average.</value>
|
||||
public double vote_average { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the vote_count.
|
||||
/// </summary>
|
||||
/// <value>The vote_count.</value>
|
||||
public int vote_count { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class MovieImages
|
||||
/// </summary>
|
||||
protected class MovieImages
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the backdrops.
|
||||
/// </summary>
|
||||
/// <value>The backdrops.</value>
|
||||
public List<Backdrop> backdrops { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the posters.
|
||||
/// </summary>
|
||||
/// <value>The posters.</value>
|
||||
public List<Poster> posters { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,8 +181,8 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
|
||||
private const string Search3 = @"http://api.themoviedb.org/3/search/{3}?api_key={1}&query={0}&language={2}";
|
||||
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords,trailers";
|
||||
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images";
|
||||
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&append_to_response=casts,releases,images,keywords,trailers";
|
||||
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&append_to_response=images";
|
||||
|
||||
internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669";
|
||||
internal static string AcceptHeader = "application/json,image/*";
|
||||
|
@ -517,15 +517,22 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
if (mainResult == null) return;
|
||||
|
||||
var path = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxSet, mainResult.id.ToString(_usCulture));
|
||||
var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, isBoxSet, mainResult.id.ToString(_usCulture));
|
||||
|
||||
dataFilePath = Path.Combine(path, language + ".json");
|
||||
dataFilePath = Path.Combine(movieDataPath, language + ".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)
|
||||
|
@ -559,6 +566,13 @@ namespace MediaBrowser.Providers.Movies
|
|||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -567,7 +581,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <param name="item">The item.</param>
|
||||
/// <param name="language">The language.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private string GetDataFilePath(BaseItem item, string language)
|
||||
internal string GetDataFilePath(BaseItem item, string language)
|
||||
{
|
||||
var id = item.GetProviderId(MetadataProviders.Tmdb);
|
||||
|
||||
|
@ -591,11 +605,17 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <param name="language">The language.</param>
|
||||
/// <param name="cancellationToken">The cancellation token</param>
|
||||
/// <returns>Task{CompleteMovieData}.</returns>
|
||||
protected async Task<CompleteMovieData> FetchMainResult(string id, bool isBoxSet, string language, CancellationToken cancellationToken)
|
||||
private async Task<CompleteMovieData> FetchMainResult(string id, bool isBoxSet, string language, CancellationToken cancellationToken)
|
||||
{
|
||||
var baseUrl = isBoxSet ? GetBoxSetInfo3 : GetMovieInfo3;
|
||||
|
||||
string url = string.Format(baseUrl, id, ApiKey, language);
|
||||
var url = string.Format(baseUrl, id, ApiKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(language))
|
||||
{
|
||||
url += "&language=" + language;
|
||||
}
|
||||
|
||||
CompleteMovieData mainResult;
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -615,7 +635,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
|
||||
if (mainResult != null && string.IsNullOrEmpty(mainResult.overview))
|
||||
{
|
||||
if (language.ToLower() != "en")
|
||||
if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Logger.Info("MovieDbProvider couldn't find meta for language " + language + ". Trying English...");
|
||||
|
||||
|
@ -647,7 +667,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// </summary>
|
||||
/// <param name="movie">The movie.</param>
|
||||
/// <param name="movieData">The movie data.</param>
|
||||
protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
|
||||
private void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData)
|
||||
{
|
||||
if (movie != null && movieData != null)
|
||||
{
|
||||
|
@ -871,13 +891,15 @@ namespace MediaBrowser.Providers.Movies
|
|||
}
|
||||
}
|
||||
|
||||
#region Result Objects
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class TmdbTitle
|
||||
/// </summary>
|
||||
protected class TmdbTitle
|
||||
internal class TmdbTitle
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the iso_3166_1.
|
||||
|
@ -894,7 +916,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <summary>
|
||||
/// Class TmdbAltTitleResults
|
||||
/// </summary>
|
||||
protected class TmdbAltTitleResults
|
||||
internal class TmdbAltTitleResults
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the id.
|
||||
|
@ -911,7 +933,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <summary>
|
||||
/// Class TmdbMovieSearchResult
|
||||
/// </summary>
|
||||
protected class TmdbMovieSearchResult
|
||||
internal class TmdbMovieSearchResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="TmdbMovieSearchResult" /> is adult.
|
||||
|
@ -972,7 +994,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <summary>
|
||||
/// Class TmdbMovieSearchResults
|
||||
/// </summary>
|
||||
protected class TmdbMovieSearchResults
|
||||
internal class TmdbMovieSearchResults
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the page.
|
||||
|
@ -996,7 +1018,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
public int total_results { get; set; }
|
||||
}
|
||||
|
||||
protected class BelongsToCollection
|
||||
internal class BelongsToCollection
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
|
@ -1004,31 +1026,31 @@ namespace MediaBrowser.Providers.Movies
|
|||
public string backdrop_path { get; set; }
|
||||
}
|
||||
|
||||
protected class GenreItem
|
||||
internal class GenreItem
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
protected class ProductionCompany
|
||||
internal class ProductionCompany
|
||||
{
|
||||
public string name { get; set; }
|
||||
public int id { get; set; }
|
||||
}
|
||||
|
||||
protected class ProductionCountry
|
||||
internal class ProductionCountry
|
||||
{
|
||||
public string iso_3166_1 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
protected class SpokenLanguage
|
||||
internal class SpokenLanguage
|
||||
{
|
||||
public string iso_639_1 { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
protected class Cast
|
||||
internal class Cast
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
|
@ -1038,7 +1060,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
public string profile_path { get; set; }
|
||||
}
|
||||
|
||||
protected class Crew
|
||||
internal class Crew
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
|
@ -1047,36 +1069,77 @@ namespace MediaBrowser.Providers.Movies
|
|||
public string profile_path { get; set; }
|
||||
}
|
||||
|
||||
protected class Casts
|
||||
internal class Casts
|
||||
{
|
||||
public List<Cast> cast { get; set; }
|
||||
public List<Crew> crew { get; set; }
|
||||
}
|
||||
|
||||
protected class Country
|
||||
internal class Country
|
||||
{
|
||||
public string iso_3166_1 { get; set; }
|
||||
public string certification { get; set; }
|
||||
public DateTime release_date { get; set; }
|
||||
}
|
||||
|
||||
protected class Releases
|
||||
internal class Releases
|
||||
{
|
||||
public List<Country> countries { get; set; }
|
||||
}
|
||||
|
||||
protected class Keyword
|
||||
internal class Backdrop
|
||||
{
|
||||
public string file_path { get; set; }
|
||||
public int width { get; set; }
|
||||
public int height { get; set; }
|
||||
public object iso_639_1 { get; set; }
|
||||
public double aspect_ratio { get; set; }
|
||||
public double vote_average { get; set; }
|
||||
public int vote_count { get; set; }
|
||||
}
|
||||
|
||||
internal class Poster
|
||||
{
|
||||
public string file_path { get; set; }
|
||||
public int width { get; set; }
|
||||
public int height { get; set; }
|
||||
public string iso_639_1 { get; set; }
|
||||
public double aspect_ratio { get; set; }
|
||||
public double vote_average { get; set; }
|
||||
public int vote_count { get; set; }
|
||||
}
|
||||
|
||||
internal class Images
|
||||
{
|
||||
public List<Backdrop> backdrops { get; set; }
|
||||
public List<Poster> posters { get; set; }
|
||||
}
|
||||
|
||||
internal class Keyword
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
protected class Keywords
|
||||
internal class Keywords
|
||||
{
|
||||
public List<Keyword> keywords { get; set; }
|
||||
}
|
||||
|
||||
protected class CompleteMovieData
|
||||
internal class Youtube
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string size { get; set; }
|
||||
public string source { get; set; }
|
||||
}
|
||||
|
||||
internal class Trailers
|
||||
{
|
||||
public List<object> quicktime { get; set; }
|
||||
public List<Youtube> youtube { get; set; }
|
||||
}
|
||||
|
||||
internal class CompleteMovieData
|
||||
{
|
||||
public bool adult { get; set; }
|
||||
public string backdrop_path { get; set; }
|
||||
|
@ -1086,7 +1149,6 @@ namespace MediaBrowser.Providers.Movies
|
|||
public string homepage { get; set; }
|
||||
public int id { get; set; }
|
||||
public string imdb_id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string original_title { get; set; }
|
||||
public string overview { get; set; }
|
||||
public double popularity { get; set; }
|
||||
|
@ -1100,27 +1162,17 @@ namespace MediaBrowser.Providers.Movies
|
|||
public string status { get; set; }
|
||||
public string tagline { get; set; }
|
||||
public string title { get; set; }
|
||||
public string name { get; set; }
|
||||
public double vote_average { get; set; }
|
||||
public int vote_count { get; set; }
|
||||
public Casts casts { get; set; }
|
||||
public Releases releases { get; set; }
|
||||
public Images images { get; set; }
|
||||
public Keywords keywords { get; set; }
|
||||
public Trailers trailers { get; set; }
|
||||
}
|
||||
|
||||
public class Trailers
|
||||
{
|
||||
public List<Youtube> youtube { get; set; }
|
||||
}
|
||||
|
||||
public class Youtube
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string size { get; set; }
|
||||
public string source { get; set; }
|
||||
}
|
||||
|
||||
public class TmdbImageSettings
|
||||
internal class TmdbImageSettings
|
||||
{
|
||||
public List<string> backdrop_sizes { get; set; }
|
||||
public string base_url { get; set; }
|
||||
|
@ -1128,15 +1180,9 @@ namespace MediaBrowser.Providers.Movies
|
|||
public List<string> profile_sizes { get; set; }
|
||||
}
|
||||
|
||||
public class TmdbSettingsResult
|
||||
internal class TmdbSettingsResult
|
||||
{
|
||||
public TmdbImageSettings images { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
|||
|
||||
var sources = additionalBackdrops
|
||||
.Select(musicArtist.GetImageSourceInfo)
|
||||
.Where(i => i != null)
|
||||
.ToList();
|
||||
|
||||
foreach (var path in additionalBackdrops)
|
||||
|
|
Loading…
Reference in New Issue
Block a user