mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Added the TMDB Configuration service. This allows Image urls to be dynamically generated!
This commit is contained in:
parent
87c7afac16
commit
1325822798
5 changed files with 118 additions and 4 deletions
|
@ -7,6 +7,7 @@ namespace NzbDrone.Common.Cloud
|
|||
IHttpRequestBuilderFactory Services { get; }
|
||||
IHttpRequestBuilderFactory SkyHookTvdb { get; }
|
||||
IHttpRequestBuilderFactory TMDB { get; }
|
||||
IHttpRequestBuilderFactory TMDBSingle { get; }
|
||||
}
|
||||
|
||||
public class SonarrCloudRequestBuilder : ISonarrCloudRequestBuilder
|
||||
|
@ -23,11 +24,16 @@ namespace NzbDrone.Common.Cloud
|
|||
TMDB = new HttpRequestBuilder("https://api.themoviedb.org/3/{route}/{id}{secondaryRoute}")
|
||||
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
|
||||
.CreateFactory();
|
||||
|
||||
TMDBSingle = new HttpRequestBuilder("https://api.themoviedb.org/3/{route}")
|
||||
.AddQueryParam("api_key", "1a7373301961d03f97f853a876dd1212")
|
||||
.CreateFactory();
|
||||
}
|
||||
|
||||
public IHttpRequestBuilderFactory Services { get; private set; }
|
||||
|
||||
public IHttpRequestBuilderFactory SkyHookTvdb { 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.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Tv;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -21,12 +22,14 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
|
||||
private readonly IHttpRequestBuilderFactory _requestBuilder;
|
||||
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;
|
||||
_requestBuilder = requestBuilder.SkyHookTvdb;
|
||||
_movieBuilder = requestBuilder.TMDB;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -89,8 +92,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
movie.InCinemas = DateTime.Parse(resource.release_date);
|
||||
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(new MediaCover.MediaCover(MediaCoverTypes.Banner, "http://image.tmdb.org/t/p/" + "w1280" + resource.backdrop_path));
|
||||
movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page!
|
||||
movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner));
|
||||
movie.Runtime = resource.runtime;
|
||||
|
||||
foreach(Title title in resource.alternative_titles.titles)
|
||||
|
@ -250,7 +253,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
77
src/NzbDrone.Core/MetadataSource/TmdbConfigurationService.cs
Normal file
77
src/NzbDrone.Core/MetadataSource/TmdbConfigurationService.cs
Normal file
|
@ -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\ISearchForNewMovie.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\ImageResource.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\Resource\RatingResource.cs" />
|
||||
|
@ -837,6 +838,7 @@
|
|||
<Compile Include="Extras\Metadata\MetadataType.cs" />
|
||||
<Compile Include="MetadataSource\IProvideSeriesInfo.cs" />
|
||||
<Compile Include="MetadataSource\ISearchForNewSeries.cs" />
|
||||
<Compile Include="MetadataSource\TmdbConfigurationService.cs" />
|
||||
<Compile Include="Notifications\Join\JoinAuthException.cs" />
|
||||
<Compile Include="Notifications\Join\JoinInvalidDeviceException.cs" />
|
||||
<Compile Include="Notifications\Join\JoinResponseModel.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue