Merge pull request #6874 from 1337joe/tmdb-image-size-options

pull/6941/head
Cody Robibero 3 years ago committed by GitHub
commit 9cea773d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,41 @@
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TMDbLib.Objects.General;
namespace MediaBrowser.Providers.Plugins.Tmdb.Api
{
/// <summary>
/// The TMDb api controller.
/// </summary>
[ApiController]
[Authorize(Policy = "DefaultAuthorization")]
[Route("[controller]")]
[Produces(MediaTypeNames.Application.Json)]
public class TmdbController : ControllerBase
{
private readonly TmdbClientManager _tmdbClientManager;
/// <summary>
/// Initializes a new instance of the <see cref="TmdbController"/> class.
/// </summary>
/// <param name="tmdbClientManager">The TMDb client manager.</param>
public TmdbController(TmdbClientManager tmdbClientManager)
{
_tmdbClientManager = tmdbClientManager;
}
/// <summary>
/// Gets the TMDb image configuration options.
/// </summary>
/// <returns>The image portion of the TMDb client configuration.</returns>
[HttpGet("ClientConfiguration")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ConfigImageTypes> TmdbClientConfiguration()
{
return (await _tmdbClientManager.GetClientConfiguration().ConfigureAwait(false)).Images;
}
}
}

@ -26,5 +26,25 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// Gets or sets a value indicating the maximum number of cast members to fetch for an item.
/// </summary>
public int MaxCastMembers { get; set; } = 15;
/// <summary>
/// Gets or sets a value indicating the poster image size to fetch.
/// </summary>
public string? PosterSize { get; set; }
/// <summary>
/// Gets or sets a value indicating the backdrop image size to fetch.
/// </summary>
public string? BackdropSize { get; set; }
/// <summary>
/// Gets or sets a value indicating the profile image size to fetch.
/// </summary>
public string? ProfileSize { get; set; }
/// <summary>
/// Gets or sets a value indicating the still image size to fetch.
/// </summary>
public string? StillSize { get; set; }
}
}

@ -24,7 +24,21 @@
<input is="emby-input" type="number" id="maxCastMembers" pattern="[0-9]*" required min="0" max="1000" label="Max Cast Members" />
<div class="fieldDescription">The maximum number of cast members to fetch for an item.</div>
</div>
<br />
<div class="verticalSection verticalSection-extrabottompadding">
<h2>Image Scaling</h2>
<div class="selectContainer">
<select is="emby-select" id="selectPosterSize" label="Poster"></select>
</div>
<div class="selectContainer">
<select is="emby-select" id="selectBackdropSize" label="Backdrop"></select>
</div>
<div class="selectContainer">
<select is="emby-select" id="selectProfileSize" label="Profile"></select>
</div>
<div class="selectContainer">
<select is="emby-select" id="selectStillSize" label="Still"></select>
</div>
</div>
<div>
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
</div>
@ -39,6 +53,47 @@
document.querySelector('.configPage')
.addEventListener('pageshow', function () {
Dashboard.showLoadingMsg();
var clientConfig, pluginConfig;
var configureImageScaling = function() {
if (clientConfig === null || pluginConfig === null) {
return;
}
var sizeOptionsGenerator = function (size) {
return '<option value="' + size + '">' + size + '</option>';
}
var selPosterSize = document.querySelector('#selectPosterSize');
selPosterSize.innerHTML = clientConfig.PosterSizes.map(sizeOptionsGenerator);
selPosterSize.value = pluginConfig.PosterSize;
var selBackdropSize = document.querySelector('#selectBackdropSize');
selBackdropSize.innerHTML = clientConfig.BackdropSizes.map(sizeOptionsGenerator);
selBackdropSize.value = pluginConfig.BackdropSize;
var selProfileSize = document.querySelector('#selectProfileSize');
selProfileSize.innerHTML = clientConfig.ProfileSizes.map(sizeOptionsGenerator);
selProfileSize.value = pluginConfig.ProfileSize;
var selStillSize = document.querySelector('#selectStillSize');
selStillSize.innerHTML = clientConfig.StillSizes.map(sizeOptionsGenerator);
selStillSize.value = pluginConfig.StillSize;
Dashboard.hideLoadingMsg();
}
const request = {
url: ApiClient.getUrl('tmdb/ClientConfiguration'),
dataType: 'json',
type: 'GET',
headers: { accept: 'application/json' }
}
ApiClient.fetch(request).then(function (config) {
clientConfig = config;
configureImageScaling();
});
ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
document.querySelector('#includeAdult').checked = config.IncludeAdult;
document.querySelector('#excludeTagsSeries').checked = config.ExcludeTagsSeries;
@ -51,7 +106,8 @@
cancelable: false
}));
Dashboard.hideLoadingMsg();
pluginConfig = config;
configureImageScaling();
});
});
@ -65,6 +121,10 @@
config.ExcludeTagsSeries = document.querySelector('#excludeTagsSeries').checked;
config.ExcludeTagsMovies = document.querySelector('#excludeTagsMovies').checked;
config.MaxCastMembers = document.querySelector('#maxCastMembers').value;
config.PosterSize = document.querySelector('#selectPosterSize').value;
config.BackdropSize = document.querySelector('#selectBackdropSize').value;
config.ProfileSize = document.querySelector('#selectProfileSize').value;
config.StillSize = document.querySelector('#selectStillSize').value;
ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult);
});

@ -508,7 +508,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <returns>The absolute URL.</returns>
public string GetPosterUrl(string posterPath)
{
return GetUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath);
return GetUrl(Plugin.Instance.Configuration.PosterSize, posterPath);
}
/// <summary>
@ -518,7 +518,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <returns>The absolute URL.</returns>
public string GetProfileUrl(string actorProfilePath)
{
return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath);
return GetUrl(Plugin.Instance.Configuration.ProfileSize, actorProfilePath);
}
/// <summary>
@ -529,7 +529,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.PosterSizes[^1], ImageType.Primary, requestLanguage, results);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.PosterSize, ImageType.Primary, requestLanguage, results);
}
/// <summary>
@ -540,7 +540,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertBackdropsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.BackdropSizes[^1], ImageType.Backdrop, requestLanguage, results);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.BackdropSize, ImageType.Backdrop, requestLanguage, results);
}
/// <summary>
@ -551,7 +551,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertProfilesToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.ProfileSizes[^1], ImageType.Primary, requestLanguage, results);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.ProfileSize, ImageType.Primary, requestLanguage, results);
}
/// <summary>
@ -562,7 +562,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="results">The collection to add the remote images into.</param>
public void ConvertStillsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
{
ConvertToRemoteImageInfo(images, _tmDbClient.Config.Images.StillSizes[^1], ImageType.Primary, requestLanguage, results);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.StillSize, ImageType.Primary, requestLanguage, results);
}
/// <summary>
@ -575,16 +575,20 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="results">The collection to add the remote images into.</param>
private void ConvertToRemoteImageInfo(List<ImageData> images, string size, ImageType type, string requestLanguage, List<RemoteImageInfo> results)
{
// sizes provided are for original resolution, don't store them when downloading scaled images
var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase);
for (var i = 0; i < images.Count; i++)
{
var image = images[i];
results.Add(new RemoteImageInfo
{
Url = GetUrl(size, image.FilePath),
CommunityRating = image.VoteAverage,
VoteCount = image.VoteCount,
Width = image.Width,
Height = image.Height,
Width = scaleImage ? null : image.Width,
Height = scaleImage ? null : image.Height,
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage),
ProviderName = TmdbUtils.ProviderName,
Type = type,
@ -593,9 +597,51 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
}
}
private Task EnsureClientConfigAsync()
private async Task EnsureClientConfigAsync()
{
if (!_tmDbClient.HasConfig)
{
var config = await _tmDbClient.GetConfigAsync().ConfigureAwait(false);
ValidatePreferences(config);
}
}
private static void ValidatePreferences(TMDbConfig config)
{
return !_tmDbClient.HasConfig ? _tmDbClient.GetConfigAsync() : Task.CompletedTask;
var imageConfig = config.Images;
var pluginConfig = Plugin.Instance.Configuration;
if (!imageConfig.PosterSizes.Contains(pluginConfig.PosterSize))
{
pluginConfig.PosterSize = imageConfig.PosterSizes[^1];
}
if (!imageConfig.BackdropSizes.Contains(pluginConfig.BackdropSize))
{
pluginConfig.BackdropSize = imageConfig.BackdropSizes[^1];
}
if (!imageConfig.ProfileSizes.Contains(pluginConfig.ProfileSize))
{
pluginConfig.ProfileSize = imageConfig.ProfileSizes[^1];
}
if (!imageConfig.StillSizes.Contains(pluginConfig.StillSize))
{
pluginConfig.StillSize = imageConfig.StillSizes[^1];
}
}
/// <summary>
/// Gets the <see cref="TMDbClient"/> configuration.
/// </summary>
/// <returns>The configuration.</returns>
public async Task<TMDbConfig> GetClientConfiguration()
{
await EnsureClientConfigAsync().ConfigureAwait(false);
return _tmDbClient.Config;
}
/// <inheritdoc />

Loading…
Cancel
Save