Add image scaling options for tmdb
This commit is contained in:
parent
fa366f0099
commit
6d3b129666
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Plugins.Tmdb
|
namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
|
@ -26,5 +27,45 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// Gets or sets a value indicating the maximum number of cast members to fetch for an item.
|
/// Gets or sets a value indicating the maximum number of cast members to fetch for an item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxCastMembers { get; set; } = 15;
|
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 the available options for poster size.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> PosterSizeOptions { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating the backdrop image size to fetch.
|
||||||
|
/// </summary>
|
||||||
|
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>
|
||||||
|
/// Gets or sets a value indicating the profile image size to fetch.
|
||||||
|
/// </summary>
|
||||||
|
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>
|
||||||
|
/// Gets or sets a value indicating the still image size to fetch.
|
||||||
|
/// </summary>
|
||||||
|
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>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,22 @@
|
||||||
<input is="emby-input" type="number" id="maxCastMembers" pattern="[0-9]*" required min="0" max="1000" label="Max Cast Members" />
|
<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 class="fieldDescription">The maximum number of cast members to fetch for an item.</div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<div class="verticalSection verticalSection-extrabottompadding">
|
||||||
|
<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">
|
||||||
|
<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>
|
<div>
|
||||||
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
|
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -51,6 +66,26 @@
|
||||||
cancelable: false
|
cancelable: false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
var sizeOptionsGenerator = function (size) {
|
||||||
|
return '<option value="' + size + '">' + size + '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
Dashboard.hideLoadingMsg();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -65,6 +100,10 @@
|
||||||
config.ExcludeTagsSeries = document.querySelector('#excludeTagsSeries').checked;
|
config.ExcludeTagsSeries = document.querySelector('#excludeTagsSeries').checked;
|
||||||
config.ExcludeTagsMovies = document.querySelector('#excludeTagsMovies').checked;
|
config.ExcludeTagsMovies = document.querySelector('#excludeTagsMovies').checked;
|
||||||
config.MaxCastMembers = document.querySelector('#maxCastMembers').value;
|
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);
|
ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
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;
|
||||||
|
@ -508,7 +509,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// <returns>The absolute URL.</returns>
|
/// <returns>The absolute URL.</returns>
|
||||||
public string GetPosterUrl(string posterPath)
|
public string GetPosterUrl(string posterPath)
|
||||||
{
|
{
|
||||||
return GetUrl(_tmDbClient.Config.Images.PosterSizes[^1], posterPath);
|
return GetUrl(Plugin.Instance.Configuration.PosterSize, posterPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -518,7 +519,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// <returns>The absolute URL.</returns>
|
/// <returns>The absolute URL.</returns>
|
||||||
public string GetProfileUrl(string actorProfilePath)
|
public string GetProfileUrl(string actorProfilePath)
|
||||||
{
|
{
|
||||||
return GetUrl(_tmDbClient.Config.Images.ProfileSizes[^1], actorProfilePath);
|
return GetUrl(Plugin.Instance.Configuration.ProfileSize, actorProfilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -529,7 +530,7 @@ 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>
|
||||||
public void ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
|
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>
|
/// <summary>
|
||||||
|
@ -540,7 +541,7 @@ 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>
|
||||||
public void ConvertBackdropsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
|
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>
|
/// <summary>
|
||||||
|
@ -551,7 +552,7 @@ 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>
|
||||||
public void ConvertProfilesToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
|
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>
|
/// <summary>
|
||||||
|
@ -562,7 +563,7 @@ 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>
|
||||||
public void ConvertStillsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results)
|
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>
|
/// <summary>
|
||||||
|
@ -575,16 +576,51 @@ 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;
|
||||||
|
int? targetWidth = null;
|
||||||
|
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 = image.Width,
|
Width = width,
|
||||||
Height = image.Height,
|
Height = 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,
|
||||||
|
@ -593,9 +629,44 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task EnsureClientConfigAsync()
|
private async Task EnsureClientConfigAsync()
|
||||||
{
|
{
|
||||||
return !_tmDbClient.HasConfig ? _tmDbClient.GetConfigAsync() : Task.CompletedTask;
|
if (!_tmDbClient.HasConfig)
|
||||||
|
{
|
||||||
|
var config = await _tmDbClient.GetConfigAsync().ConfigureAwait(false);
|
||||||
|
ValidatePreferences(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidatePreferences(TMDbConfig config)
|
||||||
|
{
|
||||||
|
var imageConfig = config.Images;
|
||||||
|
|
||||||
|
var pluginConfig = Plugin.Instance.Configuration;
|
||||||
|
|
||||||
|
pluginConfig.PosterSizeOptions = imageConfig.PosterSizes;
|
||||||
|
if (!pluginConfig.PosterSizeOptions.Contains(pluginConfig.PosterSize))
|
||||||
|
{
|
||||||
|
pluginConfig.PosterSize = pluginConfig.PosterSizeOptions[^1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginConfig.BackdropSizeOptions = imageConfig.BackdropSizes;
|
||||||
|
if (!pluginConfig.BackdropSizeOptions.Contains(pluginConfig.BackdropSize))
|
||||||
|
{
|
||||||
|
pluginConfig.BackdropSize = pluginConfig.BackdropSizeOptions[^1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginConfig.ProfileSizeOptions = imageConfig.ProfileSizes;
|
||||||
|
if (!pluginConfig.ProfileSizeOptions.Contains(pluginConfig.ProfileSize))
|
||||||
|
{
|
||||||
|
pluginConfig.ProfileSize = pluginConfig.ProfileSizeOptions[^1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginConfig.StillSizeOptions = imageConfig.StillSizes;
|
||||||
|
if (!pluginConfig.StillSizeOptions.Contains(pluginConfig.StillSize))
|
||||||
|
{
|
||||||
|
pluginConfig.StillSize = pluginConfig.StillSizeOptions[^1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user