Added the TMDB Configuration service. This allows Image urls to be dynamically generated!

pull/34/head
Leonardo Galli 8 years ago
parent 87c7afac16
commit 1325822798

@ -7,6 +7,7 @@ namespace NzbDrone.Common.Cloud
IHttpRequestBuilderFactory Services { get; } IHttpRequestBuilderFactory Services { get; }
IHttpRequestBuilderFactory SkyHookTvdb { get; } IHttpRequestBuilderFactory SkyHookTvdb { get; }
IHttpRequestBuilderFactory TMDB { get; } IHttpRequestBuilderFactory TMDB { get; }
IHttpRequestBuilderFactory TMDBSingle { get; }
} }
public class SonarrCloudRequestBuilder : ISonarrCloudRequestBuilder public class SonarrCloudRequestBuilder : ISonarrCloudRequestBuilder
@ -23,11 +24,16 @@ namespace NzbDrone.Common.Cloud
TMDB = new HttpRequestBuilder("https://api.themoviedb.org/3/{route}/{id}{secondaryRoute}") TMDB = new HttpRequestBuilder("https://api.themoviedb.org/3/{route}/{id}{secondaryRoute}")
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212") .AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
.CreateFactory(); .CreateFactory();
TMDBSingle = new HttpRequestBuilder("https://api.themoviedb.org/3/{route}")
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
.CreateFactory();
} }
public IHttpRequestBuilderFactory Services { get; private set; } public IHttpRequestBuilderFactory Services { get; private set; }
public IHttpRequestBuilderFactory SkyHookTvdb { get; private set; } public IHttpRequestBuilderFactory SkyHookTvdb { get; private set; }
public IHttpRequestBuilderFactory TMDB { get; private set; } public IHttpRequestBuilderFactory TMDB { get; private set; }
public IHttpRequestBuilderFactory TMDBSingle { get; private set; }
} }
} }

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
{
public class ConfigResource
{
public Images images { get; set; }
public string[] change_keys { get; set; }
}
public class Images
{
public string base_url { get; set; }
public string secure_base_url { get; set; }
public string[] backdrop_sizes { get; set; }
public string[] logo_sizes { get; set; }
public string[] poster_sizes { get; set; }
public string[] profile_sizes { get; set; }
public string[] still_sizes { get; set; }
}
}

@ -9,6 +9,7 @@ using NzbDrone.Common.Http;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MetadataSource.SkyHook.Resource; using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -21,12 +22,14 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private readonly IHttpRequestBuilderFactory _requestBuilder; private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly IHttpRequestBuilderFactory _movieBuilder; private readonly IHttpRequestBuilderFactory _movieBuilder;
private readonly ITmdbConfigService _configService;
public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, Logger logger) public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, Logger logger)
{ {
_httpClient = httpClient; _httpClient = httpClient;
_requestBuilder = requestBuilder.SkyHookTvdb; _requestBuilder = requestBuilder.SkyHookTvdb;
_movieBuilder = requestBuilder.TMDB; _movieBuilder = requestBuilder.TMDB;
_configService = configService;
_logger = logger; _logger = logger;
} }
@ -89,8 +92,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
movie.InCinemas = DateTime.Parse(resource.release_date); movie.InCinemas = DateTime.Parse(resource.release_date);
movie.Year = movie.InCinemas.Value.Year; movie.Year = movie.InCinemas.Value.Year;
movie.Images.Add(new MediaCover.MediaCover(MediaCoverTypes.Poster, "http://image.tmdb.org/t/p/"+"w500"+resource.poster_path));//TODO: Update to load image specs from tmdb page! movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page!
movie.Images.Add(new MediaCover.MediaCover(MediaCoverTypes.Banner, "http://image.tmdb.org/t/p/" + "w1280" + resource.backdrop_path)); movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner));
movie.Runtime = resource.runtime; movie.Runtime = resource.runtime;
foreach(Title title in resource.alternative_titles.titles) foreach(Title title in resource.alternative_titles.titles)
@ -250,7 +253,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
try try
{ {
string url = result.poster_path; string url = result.poster_path;
var imdbPoster = new MediaCover.MediaCover(MediaCoverTypes.Poster, "http://image.tmdb.org/t/p/" + "w500" + url); var imdbPoster = _configService.GetCoverForURL(result.poster_path, MediaCoverTypes.Poster);
imdbMovie.Images.Add(imdbPoster); imdbMovie.Images.Add(imdbPoster);
} }
catch (Exception e) catch (Exception e)

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.MediaCover;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http;
using NzbDrone.Common.Cloud;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
namespace NzbDrone.Core.MetadataSource
{
public interface ITmdbConfigService
{
MediaCover.MediaCover GetCoverForURL(string url, MediaCover.MediaCoverTypes type);
}
class TmdbConfigService : ITmdbConfigService
{
private readonly ICached<ConfigResource> _configurationCache;
private readonly IHttpClient _httpClient;
private readonly IHttpRequestBuilderFactory _tmdbBuilder;
public TmdbConfigService(ICacheManager cacheManager, IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder)
{
_configurationCache = cacheManager.GetCache<ConfigResource>(GetType(), "configuration_cache");
_httpClient = httpClient;
_tmdbBuilder = requestBuilder.TMDBSingle;
}
public MediaCover.MediaCover GetCoverForURL(string url, MediaCover.MediaCoverTypes type)
{
if (_configurationCache.Count == 0)
{
RefreshCache();
}
var images = _configurationCache.Find("configuration").images;
var cover = new MediaCover.MediaCover();
cover.CoverType = type;
var realUrl = images.base_url;
switch (type)
{
case MediaCoverTypes.Banner:
realUrl += images.backdrop_sizes.Last();
break;
case MediaCoverTypes.Poster:
realUrl += images.poster_sizes.Last();
break;
default:
realUrl += "original";
break;
}
realUrl += url;
cover.Url = realUrl;
return cover;
}
private void RefreshCache()
{
var request = _tmdbBuilder.Create().SetSegment("route", "configuration").Build();
var response = _httpClient.Get<ConfigResource>(request);
if (response.Resource.images != null)
{
_configurationCache.Set("configuration", response.Resource);
}
}
}
}

@ -805,6 +805,7 @@
<Compile Include="MetadataSource\IProvideMovieInfo.cs" /> <Compile Include="MetadataSource\IProvideMovieInfo.cs" />
<Compile Include="MetadataSource\ISearchForNewMovie.cs" /> <Compile Include="MetadataSource\ISearchForNewMovie.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\ActorResource.cs" /> <Compile Include="MetadataSource\SkyHook\Resource\ActorResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\ConfigurationResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\EpisodeResource.cs" /> <Compile Include="MetadataSource\SkyHook\Resource\EpisodeResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\ImageResource.cs" /> <Compile Include="MetadataSource\SkyHook\Resource\ImageResource.cs" />
<Compile Include="MetadataSource\SkyHook\Resource\RatingResource.cs" /> <Compile Include="MetadataSource\SkyHook\Resource\RatingResource.cs" />
@ -837,6 +838,7 @@
<Compile Include="Extras\Metadata\MetadataType.cs" /> <Compile Include="Extras\Metadata\MetadataType.cs" />
<Compile Include="MetadataSource\IProvideSeriesInfo.cs" /> <Compile Include="MetadataSource\IProvideSeriesInfo.cs" />
<Compile Include="MetadataSource\ISearchForNewSeries.cs" /> <Compile Include="MetadataSource\ISearchForNewSeries.cs" />
<Compile Include="MetadataSource\TmdbConfigurationService.cs" />
<Compile Include="Notifications\Join\JoinAuthException.cs" /> <Compile Include="Notifications\Join\JoinAuthException.cs" />
<Compile Include="Notifications\Join\JoinInvalidDeviceException.cs" /> <Compile Include="Notifications\Join\JoinInvalidDeviceException.cs" />
<Compile Include="Notifications\Join\JoinResponseModel.cs" /> <Compile Include="Notifications\Join\JoinResponseModel.cs" />

Loading…
Cancel
Save