Add tmdb api host config
This commit is contained in:
parent
d3e839ec0e
commit
b7ee0b956d
|
@ -0,0 +1,53 @@
|
||||||
|
using Jellyfin.Plugin.MetaShark.Api;
|
||||||
|
using Jellyfin.Plugin.MetaShark.Core;
|
||||||
|
using Jellyfin.Plugin.MetaShark.Providers;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MetaShark.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class SeasonProviderTest
|
||||||
|
{
|
||||||
|
|
||||||
|
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||||
|
builder.AddSimpleConsole(options =>
|
||||||
|
{
|
||||||
|
options.IncludeScopes = true;
|
||||||
|
options.SingleLine = true;
|
||||||
|
options.TimestampFormat = "hh:mm:ss ";
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetMetadata()
|
||||||
|
{
|
||||||
|
var info = new SeasonInfo() { Name = "第 18 季", IndexNumber = 18, SeriesProviderIds = new Dictionary<string, string>() { { BaseProvider.DoubanProviderId, "2059529" }, { MetadataProvider.Tmdb.ToString(), "34860" } } };
|
||||||
|
var doubanApi = new DoubanApi(loggerFactory);
|
||||||
|
var tmdbApi = new TmdbApi(loggerFactory);
|
||||||
|
var omdbApi = new OmdbApi(loggerFactory);
|
||||||
|
var httpClientFactory = new DefaultHttpClientFactory();
|
||||||
|
var libraryManagerStub = new Mock<ILibraryManager>();
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var provider = new SeasonProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, doubanApi, tmdbApi, omdbApi);
|
||||||
|
var result = await provider.GetMetadata(info, CancellationToken.None);
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
|
||||||
|
var str = result.ToJson();
|
||||||
|
Console.WriteLine(result.ToJson());
|
||||||
|
}).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
public class TmdbApi : IDisposable
|
public class TmdbApi : IDisposable
|
||||||
{
|
{
|
||||||
public const string DEFAULT_API_KEY = "4219e299c89411838049ab0dab19ebd5";
|
public const string DEFAULT_API_KEY = "4219e299c89411838049ab0dab19ebd5";
|
||||||
|
public const string DEFAULT_API_HOST = "api.tmdb.org";
|
||||||
private const int CacheDurationInHours = 1;
|
private const int CacheDurationInHours = 1;
|
||||||
private readonly ILogger<TmdbApi> _logger;
|
private readonly ILogger<TmdbApi> _logger;
|
||||||
private readonly IMemoryCache _memoryCache;
|
private readonly IMemoryCache _memoryCache;
|
||||||
|
@ -37,7 +38,8 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
_memoryCache = new MemoryCache(new MemoryCacheOptions());
|
_memoryCache = new MemoryCache(new MemoryCacheOptions());
|
||||||
var config = Plugin.Instance?.Configuration;
|
var config = Plugin.Instance?.Configuration;
|
||||||
var apiKey = config == null || string.IsNullOrEmpty(config.TmdbApiKey) ? DEFAULT_API_KEY : config.TmdbApiKey;
|
var apiKey = config == null || string.IsNullOrEmpty(config.TmdbApiKey) ? DEFAULT_API_KEY : config.TmdbApiKey;
|
||||||
_tmDbClient = new TMDbClient(apiKey);
|
var host = config == null || string.IsNullOrEmpty(config.TmdbHost) ? DEFAULT_API_HOST : config.TmdbHost;
|
||||||
|
_tmDbClient = new TMDbClient(apiKey, true, host);
|
||||||
_tmDbClient.RequestTimeout = TimeSpan.FromSeconds(10);
|
_tmDbClient.RequestTimeout = TimeSpan.FromSeconds(10);
|
||||||
// Not really interested in NotFoundException
|
// Not really interested in NotFoundException
|
||||||
_tmDbClient.ThrowApiExceptions = false;
|
_tmDbClient.ThrowApiExceptions = false;
|
||||||
|
|
|
@ -35,6 +35,8 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||||
|
|
||||||
public string TmdbApiKey { get; set; } = string.Empty;
|
public string TmdbApiKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string TmdbHost { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string DoubanCookies { get; set; } = string.Empty;
|
public string DoubanCookies { get; set; } = string.Empty;
|
||||||
|
|
||||||
public int MaxCastMembers { get; set; } = 15;
|
public int MaxCastMembers { get; set; } = 15;
|
||||||
|
|
|
@ -53,6 +53,12 @@
|
||||||
<input id="TmdbApiKey" name="TmdbApiKey" type="text" is="emby-input" />
|
<input id="TmdbApiKey" name="TmdbApiKey" type="text" is="emby-input" />
|
||||||
<div class="fieldDescription">填写自定义Api Key,不填写会使用默认api key.(需重启才能生效)</div>
|
<div class="fieldDescription">填写自定义Api Key,不填写会使用默认api key.(需重启才能生效)</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="TmdbHost">Api Host</label>
|
||||||
|
<input id="TmdbHost" name="TmdbHost" type="text" is="emby-input"
|
||||||
|
placeholder="api.tmdb.org" />
|
||||||
|
<div class="fieldDescription">填写Api域名,默认api.tmdb.org.(需重启才能生效)</div>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||||
<span>Save</span>
|
<span>Save</span>
|
||||||
|
@ -75,6 +81,7 @@
|
||||||
document.querySelector('#EnableTmdb').checked = config.EnableTmdb;
|
document.querySelector('#EnableTmdb').checked = config.EnableTmdb;
|
||||||
document.querySelector('#EnableTmdbSearch').checked = config.EnableTmdbSearch;
|
document.querySelector('#EnableTmdbSearch').checked = config.EnableTmdbSearch;
|
||||||
document.querySelector('#TmdbApiKey').value = config.TmdbApiKey;
|
document.querySelector('#TmdbApiKey').value = config.TmdbApiKey;
|
||||||
|
document.querySelector('#TmdbHost').value = config.TmdbHost;
|
||||||
Dashboard.hideLoadingMsg();
|
Dashboard.hideLoadingMsg();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -87,6 +94,7 @@
|
||||||
config.EnableTmdb = document.querySelector('#EnableTmdb').checked;
|
config.EnableTmdb = document.querySelector('#EnableTmdb').checked;
|
||||||
config.EnableTmdbSearch = document.querySelector('#EnableTmdbSearch').checked;
|
config.EnableTmdbSearch = document.querySelector('#EnableTmdbSearch').checked;
|
||||||
config.TmdbApiKey = document.querySelector('#TmdbApiKey').value;
|
config.TmdbApiKey = document.querySelector('#TmdbApiKey').value;
|
||||||
|
config.TmdbHost = document.querySelector('#TmdbHost').value;
|
||||||
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
|
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
|
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
|
||||||
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace TMDbLib.Client
|
||||||
public partial class TMDbClient : IDisposable
|
public partial class TMDbClient : IDisposable
|
||||||
{
|
{
|
||||||
private const string ApiVersion = "3";
|
private const string ApiVersion = "3";
|
||||||
private const string ProductionUrl = "api.tmdb.org";
|
private const string ProductionUrl = "api.themoviedb.org";
|
||||||
|
|
||||||
private readonly ITMDbSerializer _serializer;
|
private readonly ITMDbSerializer _serializer;
|
||||||
private RestClient _client;
|
private RestClient _client;
|
||||||
|
|
Loading…
Reference in New Issue