mirror of
https://github.com/jellyfin/jellyfin-plugin-anidb.git
synced 2025-02-17 04:27:47 +00:00
Remove obsolete WebClient
This commit is contained in:
parent
ce100c4c1b
commit
5304d3f5d6
@ -1,6 +1,6 @@
|
||||
namespace Jellyfin.Plugin.Anime
|
||||
{
|
||||
static class Constants
|
||||
public static class Constants
|
||||
{
|
||||
public const string UserAgent = "jellyfin-plugin-anime";
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Jellyfin.Plugin.Anime.Configuration;
|
||||
using Jellyfin.Plugin.Anime.Providers.AniDB.Identity;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
@ -12,19 +13,28 @@ namespace Jellyfin.Plugin.Anime
|
||||
{
|
||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
{
|
||||
public override string Name => "Anime";
|
||||
|
||||
public override Guid Id => Guid.Parse("a4df60c5-6ab4-412a-8f79-2cab93fb2bc5");
|
||||
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger logger) : base(applicationPaths, xmlSerializer)
|
||||
public Plugin(
|
||||
IApplicationPaths applicationPaths,
|
||||
IXmlSerializer xmlSerializer,
|
||||
ILogger logger)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
AniDbTitleMatcher.DefaultInstance = new AniDbTitleMatcher(logger, new AniDbTitleDownloader(logger, applicationPaths));
|
||||
AniDbTitleMatcher.DefaultInstance = new AniDbTitleMatcher(
|
||||
logger,
|
||||
new AniDbTitleDownloader(logger, applicationPaths));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Anime";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Guid Id => Guid.Parse("a4df60c5-6ab4-412a-8f79-2cab93fb2bc5");
|
||||
|
||||
public static Plugin Instance { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PluginPageInfo> GetPages()
|
||||
{
|
||||
return new[]
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Anime.Providers.AniDB.Metadata;
|
||||
@ -20,14 +20,19 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB.Identity
|
||||
/// </summary>
|
||||
private const string TitlesUrl = "http://anidb.net/api/anime-titles.xml.gz";
|
||||
|
||||
private readonly IApplicationPaths _paths;
|
||||
private static readonly HttpClient _httpClient;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AniDbTitleDownloader(ILogger logger, IApplicationPaths paths)
|
||||
public AniDbTitleDownloader(ILogger logger, IApplicationPaths applicationPaths)
|
||||
{
|
||||
_logger = logger;
|
||||
_paths = paths;
|
||||
Paths = GetDataPath(paths);
|
||||
Paths = GetDataPath(applicationPaths);
|
||||
}
|
||||
|
||||
static AniDbTitleDownloader()
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent", Constants.UserAgent);
|
||||
}
|
||||
|
||||
public static string Paths { get; private set; }
|
||||
@ -76,10 +81,10 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB.Identity
|
||||
/// and saves it to disk.
|
||||
/// </summary>
|
||||
/// <param name="titlesFile">The destination file name.</param>
|
||||
private async Task DownloadTitles(string titlesFile)
|
||||
private Task DownloadTitles(string titlesFile)
|
||||
{
|
||||
_logger.LogDebug("Downloading new AniDB titles file.");
|
||||
await DownloadTitles_static(titlesFile);
|
||||
return DownloadTitles_static(titlesFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -90,12 +95,9 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB.Identity
|
||||
/// <returns></returns>
|
||||
private static async Task DownloadTitles_static(string titlesFile)
|
||||
{
|
||||
var client = new WebClient();
|
||||
client.Headers.Add("User-Agent", Constants.UserAgent);
|
||||
|
||||
await AniDbSeriesProvider.RequestLimiter.Tick().ConfigureAwait(false);
|
||||
await Task.Delay(Plugin.Instance.Configuration.AniDbRateLimit).ConfigureAwait(false);
|
||||
using (var stream = await client.OpenReadTaskAsync(TitlesUrl))
|
||||
using (var stream = await _httpClient.GetStreamAsync(TitlesUrl).ConfigureAwait(false))
|
||||
using (var unzipped = new GZipStream(stream, CompressionMode.Decompress))
|
||||
using (var writer = File.Open(titlesFile, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
|
@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Anime.Configuration;
|
||||
using Jellyfin.Plugin.Anime.Providers.AniList;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Anime.Providers.AniList
|
||||
{
|
||||
@ -21,7 +20,7 @@ namespace Jellyfin.Plugin.Anime.Providers.AniList
|
||||
/// </summary>
|
||||
public class AniListApi
|
||||
{
|
||||
private static IJsonSerializer _jsonSerializer;
|
||||
private static readonly HttpClient _httpClient;
|
||||
private const string SearchLink = @"https://graphql.anilist.co/api/v2?query=
|
||||
query ($query: String, $type: MediaType) {
|
||||
Page {
|
||||
@ -142,10 +141,13 @@ query ($query: String, $type: MediaType) {
|
||||
}
|
||||
}
|
||||
}&variables={ ""id"":""{0}"",""type"":""ANIME""}";
|
||||
public AniListApi(IJsonSerializer jsonSerializer)
|
||||
|
||||
static AniListApi()
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent", Constants.UserAgent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API call to get the anime with the id
|
||||
/// </summary>
|
||||
@ -154,7 +156,7 @@ query ($query: String, $type: MediaType) {
|
||||
public async Task<RemoteSearchResult> GetAnime(string id)
|
||||
{
|
||||
RootObject WebContent = await WebRequestAPI(AniList_anime_link.Replace("{0}",id));
|
||||
|
||||
|
||||
var result = new RemoteSearchResult
|
||||
{
|
||||
Name = ""
|
||||
@ -304,7 +306,7 @@ query ($query: String, $type: MediaType) {
|
||||
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -368,19 +370,12 @@ query ($query: String, $type: MediaType) {
|
||||
/// </summary>
|
||||
public async Task<RootObject> WebRequestAPI(string link)
|
||||
{
|
||||
string _strContent = "";
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.Headers.Add("User-Agent", Constants.UserAgent);
|
||||
var values = new System.Collections.Specialized.NameValueCollection();
|
||||
|
||||
var response = await Task.Run(() => client.UploadValues(new Uri(link),values));
|
||||
_strContent = System.Text.Encoding.Default.GetString(response);
|
||||
}
|
||||
|
||||
RootObject data = _jsonSerializer.DeserializeFromString<RootObject>(_strContent);
|
||||
|
||||
return data;
|
||||
using (HttpContent content = new FormUrlEncodedContent(Enumerable.Empty<KeyValuePair<string, string>>()))
|
||||
using (var response = await _httpClient.PostAsync(link, content).ConfigureAwait(false))
|
||||
using (var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||
{
|
||||
return await JsonSerializer.DeserializeAsync<RootObject>(responseStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ namespace Jellyfin.Plugin.Anime.Providers.AniList
|
||||
public int Order => -2;
|
||||
public string Name => "AniList";
|
||||
|
||||
public AniListSeriesProvider(IApplicationPaths appPaths, IHttpClient httpClient, ILogger<AniListSeriesProvider> logger, IJsonSerializer jsonSerializer)
|
||||
public AniListSeriesProvider(IApplicationPaths appPaths, IHttpClient httpClient, ILogger<AniListSeriesProvider> logger)
|
||||
{
|
||||
_log = logger;
|
||||
_httpClient = httpClient;
|
||||
_aniListApi = new AniListApi(jsonSerializer);
|
||||
_aniListApi = new AniListApi();
|
||||
_paths = appPaths;
|
||||
}
|
||||
|
||||
@ -49,14 +49,14 @@ namespace Jellyfin.Plugin.Anime.Providers.AniList
|
||||
RootObject WebContent = await _aniListApi.WebRequestAPI(_aniListApi.AniList_anime_link.Replace("{0}", aid));
|
||||
result.Item = new Series();
|
||||
result.HasMetadata = true;
|
||||
|
||||
|
||||
result.People = await _aniListApi.GetPersonInfo(WebContent.data.Media.id, cancellationToken);
|
||||
result.Item.ProviderIds.Add(ProviderNames.AniList, aid);
|
||||
result.Item.Overview = WebContent.data.Media.description;
|
||||
try
|
||||
{
|
||||
//AniList has a max rating of 5
|
||||
result.Item.CommunityRating = (WebContent.data.Media.averageScore/10);
|
||||
result.Item.CommunityRating = WebContent.data.Media.averageScore / 10;
|
||||
}
|
||||
catch (Exception) { }
|
||||
foreach (var genre in _aniListApi.Get_Genre(WebContent))
|
||||
@ -116,13 +116,11 @@ namespace Jellyfin.Plugin.Anime.Providers.AniList
|
||||
public class AniListSeriesImageProvider : IRemoteImageProvider
|
||||
{
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly AniListApi _aniListApi;
|
||||
public AniListSeriesImageProvider(IHttpClient httpClient, IApplicationPaths appPaths, IJsonSerializer jsonSerializer)
|
||||
public AniListSeriesImageProvider(IHttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_appPaths = appPaths;
|
||||
_aniListApi = new AniListApi(jsonSerializer);
|
||||
_aniListApi = new AniListApi();
|
||||
}
|
||||
|
||||
public string Name => "AniList";
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -20,6 +20,13 @@ namespace Jellyfin.Plugin.Anime.Providers.AniSearch
|
||||
public static List<string> anime_search_ids = new List<string>();
|
||||
public static string SearchLink = "https://www.anisearch.com/anime/index/?char=all&page=1&text={0}&smode=2&sort=title&order=asc&view=2&title=de,en,fr,it,pl,ru,es,tr&titlex=1,2&hentai=yes";
|
||||
public static string AniSearch_anime_link = "https://www.anisearch.com/anime/";
|
||||
public static readonly HttpClient _httpClient;
|
||||
|
||||
static AniSearchApi()
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent", Constants.UserAgent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API call to get the anime with the id
|
||||
@ -292,17 +299,7 @@ namespace Jellyfin.Plugin.Anime.Providers.AniSearch
|
||||
/// <summary>
|
||||
/// GET website content from the link
|
||||
/// </summary>
|
||||
public static async Task<string> WebRequestAPI(string link)
|
||||
{
|
||||
string _strContent = "";
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.Headers.Add("User-Agent", Constants.UserAgent);
|
||||
Task<string> async_content = client.DownloadStringTaskAsync(link);
|
||||
_strContent = await async_content;
|
||||
}
|
||||
|
||||
return _strContent;
|
||||
}
|
||||
public static Task<string> WebRequestAPI(string link)
|
||||
=> _httpClient.GetStringAsync(link);
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +108,10 @@ namespace Jellyfin.Plugin.Anime.Providers.AniSearch
|
||||
public class AniSearchSeriesImageProvider : IRemoteImageProvider
|
||||
{
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
|
||||
public AniSearchSeriesImageProvider(IHttpClient httpClient, IApplicationPaths appPaths)
|
||||
public AniSearchSeriesImageProvider(IHttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_appPaths = appPaths;
|
||||
}
|
||||
|
||||
public string Name => "AniSearch";
|
||||
|
Loading…
x
Reference in New Issue
Block a user