From f7900e77570f87a4a55ff11a087e8a98ae1f5d5d Mon Sep 17 00:00:00 2001 From: softworkz Date: Sat, 4 Jun 2016 03:08:27 +0200 Subject: [PATCH] OmdbImageProvider: Check poster field of cached item to determine if an image is available --- .../Omdb/OmdbImageProvider.cs | 35 ++++++++--------- MediaBrowser.Providers/Omdb/OmdbProvider.cs | 38 +++++++++++-------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs index a1e038374..e795d638d 100644 --- a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs @@ -7,6 +7,8 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; using System.Collections.Generic; +using System.IO; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -29,22 +31,27 @@ namespace MediaBrowser.Providers.Omdb }; } - public Task> GetImages(IHasImages item, CancellationToken cancellationToken) + public async Task> GetImages(IHasImages item, CancellationToken cancellationToken) { var imdbId = item.GetProviderId(MetadataProviders.Imdb); var list = new List(); - if (!string.IsNullOrWhiteSpace(imdbId)) + if (!string.IsNullOrWhiteSpace(imdbId) && OmdbProvider.Current != null) { - list.Add(new RemoteImageInfo + OmdbProvider.RootObject rootObject = await OmdbProvider.Current.GetRootObject(imdbId, cancellationToken); + + if (!string.IsNullOrEmpty(rootObject.Poster)) { - ProviderName = Name, - Url = string.Format("https://img.omdbapi.com/?i={0}&apikey=82e83907", imdbId) - }); + list.Add(new RemoteImageInfo + { + ProviderName = Name, + Url = string.Format("https://img.omdbapi.com/?i={0}&apikey=82e83907", imdbId) + }); + } } - return Task.FromResult>(list); + return list; } public Task GetImageResponse(string url, CancellationToken cancellationToken) @@ -65,18 +72,6 @@ namespace MediaBrowser.Providers.Omdb public bool Supports(IHasImages item) { - // We'll hammer Omdb if we enable this - if (item is Person) - { - return false; - } - - // Save the http requests since we know it's not currently supported - if (item is Season || item is Episode) - { - return false; - } - // Supports images for tv movies var tvProgram = item as LiveTvProgram; if (tvProgram != null && tvProgram.IsMovie) @@ -84,7 +79,7 @@ namespace MediaBrowser.Providers.Omdb return true; } - return item is Movie || item is Trailer; + return item is Movie || item is Trailer || item is Episode; } public int Order diff --git a/MediaBrowser.Providers/Omdb/OmdbProvider.cs b/MediaBrowser.Providers/Omdb/OmdbProvider.cs index 823a29d54..9873447be 100644 --- a/MediaBrowser.Providers/Omdb/OmdbProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbProvider.cs @@ -44,20 +44,7 @@ namespace MediaBrowser.Providers.Omdb throw new ArgumentNullException("imdbId"); } - var path = await EnsureItemInfo(imdbId, cancellationToken); - - string resultString; - - using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072)) - { - using (var reader = new StreamReader(stream, new UTF8Encoding(false))) - { - resultString = reader.ReadToEnd(); - resultString = resultString.Replace("\"N/A\"", "\"\""); - } - } - - var result = _jsonSerializer.DeserializeFromString(resultString); + var result = await GetRootObject(imdbId, cancellationToken); // Only take the name and rating if the user's language is set to english, since Omdb has no localization if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) @@ -131,7 +118,26 @@ namespace MediaBrowser.Providers.Omdb ParseAdditionalMetadata(item, result); } - internal async Task EnsureItemInfo(string imdbId, CancellationToken cancellationToken) + internal async Task GetRootObject(string imdbId, CancellationToken cancellationToken) + { + var path = await EnsureItemInfo(imdbId, cancellationToken); + + string resultString; + + using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072)) + { + using (var reader = new StreamReader(stream, new UTF8Encoding(false))) + { + resultString = reader.ReadToEnd(); + resultString = resultString.Replace("\"N/A\"", "\"\""); + } + } + + var result = _jsonSerializer.DeserializeFromString(resultString); + return result; + } + + private async Task EnsureItemInfo(string imdbId, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(imdbId)) { @@ -236,7 +242,7 @@ namespace MediaBrowser.Providers.Omdb return string.Equals(lang, "en", StringComparison.OrdinalIgnoreCase); } - private class RootObject + internal class RootObject { public string Title { get; set; } public string Year { get; set; }