OmdbImageProvider: Check poster field of cached item to determine if an image is available

This commit is contained in:
softworkz 2016-06-04 03:08:27 +02:00
parent f601614539
commit f7900e7757
2 changed files with 37 additions and 36 deletions

View File

@ -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<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
public async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
{
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
var list = new List<RemoteImageInfo>();
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<IEnumerable<RemoteImageInfo>>(list);
return list;
}
public Task<HttpResponseInfo> 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

View File

@ -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<RootObject>(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<string> EnsureItemInfo(string imdbId, CancellationToken cancellationToken)
internal async Task<RootObject> 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<RootObject>(resultString);
return result;
}
private async Task<string> 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; }