jellyfin-plugin-anidb/Jellyfin.Plugin.AniDB/Plugin.cs

65 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using Jellyfin.Plugin.AniDB.Configuration;
using Jellyfin.Plugin.AniDB.Providers.AniDB.Identity;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.AniDB
{
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
IHttpClientFactory _httpClientFactory;
public Plugin(
IApplicationPaths applicationPaths,
IXmlSerializer xmlSerializer,
ILogger<AniDbTitleMatcher> matcherLogger,
ILogger<AniDbTitleDownloader> downloaderLogger,
IHttpClientFactory httpClientFactory)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
_httpClientFactory = httpClientFactory;
AniDbTitleMatcher.DefaultInstance = new AniDbTitleMatcher(
matcherLogger,
new AniDbTitleDownloader(downloaderLogger, applicationPaths));
}
public HttpClient GetHttpClient() {
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
httpClient.DefaultRequestHeaders.UserAgent.Add(
new ProductInfoHeaderValue(Name, Version.ToString()));
return httpClient;
}
/// <inheritdoc />
public override string Name => Constants.PluginName;
/// <inheritdoc />
public override Guid Id => Guid.Parse(Constants.PluginGuid);
public static Plugin Instance { get; private set; }
/// <inheritdoc />
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
{
new PluginPageInfo
{
Name = Name,
EmbeddedResourcePath = string.Format("{0}.Configuration.configPage.html", GetType().Namespace)
}
};
}
}
}