Merge pull request #5009 from MrTimscampi/studios-images-plugin

This commit is contained in:
Cody Robibero 2021-12-24 02:40:59 +00:00 committed by GitHub
commit b5459f49d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 134 additions and 4 deletions

View File

@ -46,6 +46,8 @@
<EmbeddedResource Include="Plugins\Omdb\Configuration\config.html" />
<None Remove="Plugins\MusicBrainz\Configuration\config.html" />
<EmbeddedResource Include="Plugins\MusicBrainz\Configuration\config.html" />
<None Remove="Plugins\StudioImages\Configuration\config.html" />
<EmbeddedResource Include="Plugins\StudioImages\Configuration\config.html" />
<None Remove="Plugins\Tmdb\Configuration\config.html" />
<EmbeddedResource Include="Plugins\Tmdb\Configuration\config.html" />
</ItemGroup>

View File

@ -0,0 +1,24 @@
#pragma warning disable CS1591
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Providers.Plugins.StudioImages
{
public class PluginConfiguration : BasePluginConfiguration
{
private string _repository = Plugin.DefaultServer;
public string RepositoryUrl
{
get
{
return _repository;
}
set
{
_repository = value.TrimEnd('/');
}
}
}
}

View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>Studio Images</title>
</head>
<body>
<div data-role="page" class="page type-interior pluginConfigurationPage configPage" data-require="emby-input,emby-button,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<form class="configForm">
<div class="inputContainer">
<input is="emby-input" type="text" id="repository" required label="Repository" />
<div class="fieldDescription">This can be any Jellyfin-compatible artwork repository.</div>
</div>
<br />
<div>
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
var PluginConfig = {
pluginId: "872a7849-1171-458d-a6fb-3de3d442ad30"
};
document.querySelector('.configPage')
.addEventListener('pageshow', function () {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
var repository = document.querySelector('#repository');
repository.value = config.RepositoryUrl;
repository.dispatchEvent(new Event('change', {
bubbles: true,
cancelable: false
}));
Dashboard.hideLoadingMsg();
});
});
document.querySelector('.configForm')
.addEventListener('submit', function (e) {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
config.RepositoryUrl = document.querySelector('#server').value;
ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult);
});
e.preventDefault();
return false;
});
</script>
</div>
</body>
</html>

View File

@ -0,0 +1,43 @@
#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Providers.Plugins.StudioImages
{
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
}
public static Plugin Instance { get; private set; }
public override Guid Id => new Guid("872a7849-1171-458d-a6fb-3de3d442ad30");
public override string Name => "Studio Images";
public override string Description => "Get artwork for studios from any Jellyfin-compatible repository.";
// TODO change this for a Jellyfin-hosted repository.
public const string DefaultServer = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname";
// TODO remove when plugin removed from server.
public override string ConfigurationFileName => "Jellyfin.Plugin.StudioImages.xml";
public IEnumerable<PluginPageInfo> GetPages()
{
yield return new PluginPageInfo
{
Name = Name,
EmbeddedResourcePath = GetType().Namespace + ".Configuration.config.html"
};
}
}
}

View File

@ -18,6 +18,7 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.Plugins.StudioImages;
namespace MediaBrowser.Providers.Studios
{
@ -26,15 +27,17 @@ namespace MediaBrowser.Providers.Studios
private readonly IServerConfigurationManager _config;
private readonly IHttpClientFactory _httpClientFactory;
private readonly IFileSystem _fileSystem;
private readonly String repositoryUrl;
public StudiosImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem)
{
_config = config;
_httpClientFactory = httpClientFactory;
_fileSystem = fileSystem;
repositoryUrl = Plugin.Instance.Configuration.RepositoryUrl;
}
public string Name => "Emby Designs";
public string Name => "Artwork Repository";
public int Order => 0;
@ -107,19 +110,19 @@ namespace MediaBrowser.Providers.Studios
private string GetUrl(string image, string filename)
{
return string.Format(CultureInfo.InvariantCulture, "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studios/{0}/{1}.jpg", image, filename);
return string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}.jpg", repositoryUrl, image, filename);
}
private Task<string> EnsureThumbsList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studiothumbs.txt";
string url = string.Format(CultureInfo.InvariantCulture, "{0}/studiothumbs.txt", repositoryUrl);
return EnsureList(url, file, _fileSystem, cancellationToken);
}
private Task<string> EnsurePosterList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studioposters.txt";
string url = string.Format(CultureInfo.InvariantCulture, "{0}/studioposters.txt", repositoryUrl);
return EnsureList(url, file, _fileSystem, cancellationToken);
}