Address review comments
Store null instead of calculating scaled image sizes. Add endpoint to provide TMDb image size options.
This commit is contained in:
parent
6d3b129666
commit
0af5e60094
41
MediaBrowser.Providers/Plugins/Tmdb/Api/TmdbController.cs
Normal file
41
MediaBrowser.Providers/Plugins/Tmdb/Api/TmdbController.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Plugins.Tmdb
|
namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
|
@ -33,39 +32,19 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? PosterSize { get; set; }
|
public string? PosterSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the available options for poster size.
|
|
||||||
/// </summary>
|
|
||||||
public List<string> PosterSizeOptions { get; set; } = new List<string>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating the backdrop image size to fetch.
|
/// Gets or sets a value indicating the backdrop image size to fetch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? BackdropSize { get; set; }
|
public string? BackdropSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the available options for backdrop size.
|
|
||||||
/// </summary>
|
|
||||||
public List<string> BackdropSizeOptions { get; set; } = new List<string>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating the profile image size to fetch.
|
/// Gets or sets a value indicating the profile image size to fetch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ProfileSize { get; set; }
|
public string? ProfileSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the available options for profile size.
|
|
||||||
/// </summary>
|
|
||||||
public List<string> ProfileSizeOptions { get; set; } = new List<string>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating the still image size to fetch.
|
/// Gets or sets a value indicating the still image size to fetch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? StillSize { get; set; }
|
public string? StillSize { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the available options for still size.
|
|
||||||
/// </summary>
|
|
||||||
public List<string> StillSizeOptions { get; set; } = new List<string>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="verticalSection verticalSection-extrabottompadding">
|
<div class="verticalSection verticalSection-extrabottompadding">
|
||||||
<h2>Image Scaling</h2>
|
<h2>Image Scaling</h2>
|
||||||
<p>If size options are not populated then refresh metadata for any item from TMDb and reload this page.</p>
|
|
||||||
<div class="selectContainer">
|
<div class="selectContainer">
|
||||||
<select is="emby-select" id="selectPosterSize" label="Poster"></select>
|
<select is="emby-select" id="selectPosterSize" label="Poster"></select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,6 +53,47 @@
|
||||||
document.querySelector('.configPage')
|
document.querySelector('.configPage')
|
||||||
.addEventListener('pageshow', function () {
|
.addEventListener('pageshow', function () {
|
||||||
Dashboard.showLoadingMsg();
|
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) {
|
ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
|
||||||
document.querySelector('#includeAdult').checked = config.IncludeAdult;
|
document.querySelector('#includeAdult').checked = config.IncludeAdult;
|
||||||
document.querySelector('#excludeTagsSeries').checked = config.ExcludeTagsSeries;
|
document.querySelector('#excludeTagsSeries').checked = config.ExcludeTagsSeries;
|
||||||
|
@ -66,27 +106,8 @@
|
||||||
cancelable: false
|
cancelable: false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var sizeOptionsGenerator = function (size) {
|
pluginConfig = config;
|
||||||
return '<option value="' + size + '">' + size + '</option>';
|
configureImageScaling();
|
||||||
}
|
|
||||||
|
|
||||||
var selPosterSize = document.querySelector('#selectPosterSize');
|
|
||||||
selPosterSize.innerHTML = config.PosterSizeOptions.map(sizeOptionsGenerator);
|
|
||||||
selPosterSize.value = config.PosterSize;
|
|
||||||
|
|
||||||
var selBackdropSize = document.querySelector('#selectBackdropSize');
|
|
||||||
selBackdropSize.innerHTML = config.BackdropSizeOptions.map(sizeOptionsGenerator);
|
|
||||||
selBackdropSize.value = config.BackdropSize;
|
|
||||||
|
|
||||||
var selProfileSize = document.querySelector('#selectProfileSize');
|
|
||||||
selProfileSize.innerHTML = config.ProfileSizeOptions.map(sizeOptionsGenerator);
|
|
||||||
selProfileSize.value = config.ProfileSize;
|
|
||||||
|
|
||||||
var selStillSize = document.querySelector('#selectStillSize');
|
|
||||||
selStillSize.innerHTML = config.StillSizeOptions.map(sizeOptionsGenerator);
|
|
||||||
selStillSize.value = config.StillSize;
|
|
||||||
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
|
@ -576,51 +575,20 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// <param name="results">The collection to add the remote images into.</param>
|
/// <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)
|
private void ConvertToRemoteImageInfo(List<ImageData> images, string size, ImageType type, string requestLanguage, List<RemoteImageInfo> results)
|
||||||
{
|
{
|
||||||
int? targetHeight = null;
|
// sizes provided are for original resolution, don't store them when downloading scaled images
|
||||||
int? targetWidth = null;
|
var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase);
|
||||||
var match = Regex.Match(size, @"(?<dimension>[hw])(?<size>[0-9]+)");
|
|
||||||
if (match.Success)
|
|
||||||
{
|
|
||||||
var targetSize = int.Parse(match.Groups["size"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
|
|
||||||
if (string.Equals(match.Groups["dimension"].Value, "h", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
targetHeight = targetSize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
targetWidth = targetSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < images.Count; i++)
|
for (var i = 0; i < images.Count; i++)
|
||||||
{
|
{
|
||||||
var image = images[i];
|
var image = images[i];
|
||||||
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
if (targetHeight.HasValue)
|
|
||||||
{
|
|
||||||
width = (int)Math.Round((double)targetHeight.Value / image.Height * image.Width);
|
|
||||||
height = targetHeight.Value;
|
|
||||||
}
|
|
||||||
else if (targetWidth.HasValue)
|
|
||||||
{
|
|
||||||
height = (int)Math.Round((double)targetWidth.Value / image.Width * image.Height);
|
|
||||||
width = targetWidth.Value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
width = image.Width;
|
|
||||||
height = image.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
results.Add(new RemoteImageInfo
|
results.Add(new RemoteImageInfo
|
||||||
{
|
{
|
||||||
Url = GetUrl(size, image.FilePath),
|
Url = GetUrl(size, image.FilePath),
|
||||||
CommunityRating = image.VoteAverage,
|
CommunityRating = image.VoteAverage,
|
||||||
VoteCount = image.VoteCount,
|
VoteCount = image.VoteCount,
|
||||||
Width = width,
|
Width = scaleImage ? null : image.Width,
|
||||||
Height = height,
|
Height = scaleImage ? null : image.Height,
|
||||||
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage),
|
Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage),
|
||||||
ProviderName = TmdbUtils.ProviderName,
|
ProviderName = TmdbUtils.ProviderName,
|
||||||
Type = type,
|
Type = type,
|
||||||
|
@ -644,31 +612,38 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
|
|
||||||
var pluginConfig = Plugin.Instance.Configuration;
|
var pluginConfig = Plugin.Instance.Configuration;
|
||||||
|
|
||||||
pluginConfig.PosterSizeOptions = imageConfig.PosterSizes;
|
if (!imageConfig.PosterSizes.Contains(pluginConfig.PosterSize))
|
||||||
if (!pluginConfig.PosterSizeOptions.Contains(pluginConfig.PosterSize))
|
|
||||||
{
|
{
|
||||||
pluginConfig.PosterSize = pluginConfig.PosterSizeOptions[^1];
|
pluginConfig.PosterSize = imageConfig.PosterSizes[^1];
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginConfig.BackdropSizeOptions = imageConfig.BackdropSizes;
|
if (!imageConfig.BackdropSizes.Contains(pluginConfig.BackdropSize))
|
||||||
if (!pluginConfig.BackdropSizeOptions.Contains(pluginConfig.BackdropSize))
|
|
||||||
{
|
{
|
||||||
pluginConfig.BackdropSize = pluginConfig.BackdropSizeOptions[^1];
|
pluginConfig.BackdropSize = imageConfig.BackdropSizes[^1];
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginConfig.ProfileSizeOptions = imageConfig.ProfileSizes;
|
if (!imageConfig.ProfileSizes.Contains(pluginConfig.ProfileSize))
|
||||||
if (!pluginConfig.ProfileSizeOptions.Contains(pluginConfig.ProfileSize))
|
|
||||||
{
|
{
|
||||||
pluginConfig.ProfileSize = pluginConfig.ProfileSizeOptions[^1];
|
pluginConfig.ProfileSize = imageConfig.ProfileSizes[^1];
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginConfig.StillSizeOptions = imageConfig.StillSizes;
|
if (!imageConfig.StillSizes.Contains(pluginConfig.StillSize))
|
||||||
if (!pluginConfig.StillSizeOptions.Contains(pluginConfig.StillSize))
|
|
||||||
{
|
{
|
||||||
pluginConfig.StillSize = pluginConfig.StillSizeOptions[^1];
|
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 />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user