feat: add tmdb proxy config. close #45

This commit is contained in:
cxfksword 2023-09-16 11:20:42 +08:00
parent 45e4a40c28
commit ca06af4b53
4 changed files with 91 additions and 5 deletions

View File

@ -29,7 +29,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
AllowAutoRedirect = false
};
httpClient = new HttpClient(handler);
httpClient.Timeout = TimeSpan.FromSeconds(5);
httpClient.Timeout = TimeSpan.FromSeconds(10);
}
/// <summary>

View File

@ -39,7 +39,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
var config = Plugin.Instance?.Configuration;
var apiKey = string.IsNullOrEmpty(config?.TmdbApiKey) ? DEFAULT_API_KEY : config.TmdbApiKey;
var host = string.IsNullOrEmpty(config?.TmdbHost) ? DEFAULT_API_HOST : config.TmdbHost;
_tmDbClient = new TMDbClient(apiKey, true, host);
_tmDbClient = new TMDbClient(apiKey, true, host, null, config.GetTmdbWebProxy());
_tmDbClient.Timeout = TimeSpan.FromSeconds(10);
// Not really interested in NotFoundException
_tmDbClient.ThrowApiExceptions = false;

View File

@ -1,5 +1,6 @@
using MediaBrowser.Model.Plugins;
using System.Net;
using System.Reflection;
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.MetaShark.Configuration;
@ -12,6 +13,9 @@ public class PluginConfiguration : BasePluginConfiguration
public const int MAX_CAST_MEMBERS = 15;
public const int MAX_SEARCH_RESULT = 5;
/// <summary>
/// 插件版本
/// </summary>
public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? string.Empty;
public string DoubanCookies { get; set; } = string.Empty;
@ -28,10 +32,19 @@ public class PluginConfiguration : BasePluginConfiguration
/// </summary>
public string DoubanImageProxyBaseUrl { get; set; } = string.Empty;
/// <summary>
/// 启用获取tmdb元数据
/// </summary>
public bool EnableTmdb { get; set; } = true;
/// <summary>
/// 启用显示tmdb搜索结果
/// </summary>
public bool EnableTmdbSearch { get; set; } = false;
/// <summary>
/// 启用tmdb获取背景图
/// </summary>
public bool EnableTmdbBackdrop { get; set; } = true;
/// <summary>
/// 是否获取电影系列信息
@ -41,9 +54,36 @@ public class PluginConfiguration : BasePluginConfiguration
/// 是否获取tmdb分级信息
/// </summary>
public bool EnableTmdbOfficialRating { get; set; } = true;
/// <summary>
/// tmdb api key
/// </summary>
public string TmdbApiKey { get; set; } = string.Empty;
/// <summary>
/// tmdb api host
/// </summary>
public string TmdbHost { get; set; } = string.Empty;
/// <summary>
/// 代理服务器类型0-禁用1-http2-https3-socket5
/// </summary>
public string TmdbProxyType { get; set; } = string.Empty;
/// <summary>
/// 代理服务器host
/// </summary>
public string TmdbProxyPort { get; set; } = string.Empty;
/// <summary>
/// 代理服务器端口
/// </summary>
public string TmdbProxyHost { get; set; } = string.Empty;
public IWebProxy GetTmdbWebProxy()
{
if (!string.IsNullOrEmpty(TmdbProxyType))
{
return new WebProxy($"{TmdbProxyType}://{TmdbProxyHost}:{TmdbProxyPort}", true);
}
return null;
}
}

View File

@ -119,6 +119,29 @@
<div class="fieldDescription">
填写Api域名可选api.tmdb.org/api.themoviedb.org默认api.tmdb.org.(需重启才能生效)</div>
</div>
<div class="selectContainer">
<label class="selectLabel" for="TmdbProxyType">Api代理服务器</label>
<select is="emby-select" id="TmdbProxyType" name="TmdbProxyType"
class="TmdbProxyType emby-select-withcolor emby-select">
<option value="">禁用</option>
<option value="http">HTTP</option>
<option value="https">HTTPS</option>
<option value="socks5">Socks5</option>
</select>
<div class="fieldDescription">
选择Api代理服务器方式.(需重启才能生效)</div>
</div>
<div class="inputContainer tmdb-proxy-wapper">
<label class="inputLabel inputLabel-float inputLabelUnfocused"
for="TmdbProxyHost">Api代理服务器Host:</label>
<input is="emby-input" id="TmdbProxyHost" name="TmdbProxyHost" class="emby-input">
</div>
<div class="inputContainer tmdb-proxy-wapper">
<label class="inputLabel inputLabel-float inputLabelUnfocused"
for="TmdbProxyPort">Api代理服务器端口:</label>
<input is="emby-input" type="number" id="TmdbProxyPort" name="TmdbProxyPort"
pattern="[0-9]*" min="1" max="65535" class="emby-input">
</div>
</fieldset>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
<span>Save</span>
@ -134,6 +157,7 @@
document.querySelector('#TemplateConfigPage')
.addEventListener('pageshow', function () {
console.log('metashark pageshow');
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
$('#current_version').text("v" + config.Version);
@ -151,6 +175,11 @@
document.querySelector('#TmdbApiKey').value = config.TmdbApiKey;
document.querySelector('#TmdbHost').value = config.TmdbHost;
document.querySelector('#TmdbProxyType').value = config.TmdbProxyType;
document.querySelector('#TmdbProxyHost').value = config.TmdbProxyHost;
document.querySelector('#TmdbProxyPort').value = config.TmdbProxyPort;
changeProxyDisplay();
checkDoubanLogin();
Dashboard.hideLoadingMsg();
@ -173,6 +202,9 @@
config.EnableTmdbOfficialRating = document.querySelector('#EnableTmdbOfficialRating').checked;
config.TmdbApiKey = document.querySelector('#TmdbApiKey').value;
config.TmdbHost = document.querySelector('#TmdbHost').value;
config.TmdbProxyType = document.querySelector('#TmdbProxyType').value;
config.TmdbProxyHost = document.querySelector('#TmdbProxyHost').value;
config.TmdbProxyPort = document.querySelector('#TmdbProxyPort').value;
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
@ -184,6 +216,20 @@
return false;
});
document.querySelector('#TmdbProxyType')
.addEventListener('change', function (e) {
changeProxyDisplay();
});
function changeProxyDisplay() {
let proxyType = document.querySelector('#TmdbProxyType').value;
if (proxyType) {
$('.tmdb-proxy-wapper').show()
} else {
$('.tmdb-proxy-wapper').hide()
}
}
function checkDoubanLogin() {
let cookie = document.querySelector('#DoubanCookies').value
if (!cookie || !$.trim(cookie)) {