From a0fba6359962450b09c66eb46f5b4b26c2ca0c2b Mon Sep 17 00:00:00 2001 From: jerry08 Date: Fri, 4 Oct 2024 13:53:23 -0400 Subject: [PATCH] Update --- Directory.Build.props | 2 +- Juro.Core/Juro.Core.csproj | 2 +- Juro.Extractors/Juro.Extractors.csproj | 2 +- .../Juro.Providers.Adult.csproj | 2 +- Juro.Providers/Juro.Providers.csproj | 2 +- .../Controllers/Anime/AnimeController.cs | 10 ++ .../Controllers/Manga/MangaController.cs | 10 ++ Juro/Clients/AnimeApiClient.cs | 17 +-- Juro/Clients/MangaApiClient.cs | 108 ++++++++++++++++++ Juro/Juro.csproj | 2 +- 10 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 Juro.WebApi/Controllers/Anime/AnimeController.cs create mode 100644 Juro.WebApi/Controllers/Manga/MangaController.cs create mode 100644 Juro/Clients/MangaApiClient.cs diff --git a/Directory.Build.props b/Directory.Build.props index 4e188b1..59af8cb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.4.3 + 1.4.4 Berry Copyright (C) Jerry Berry latest diff --git a/Juro.Core/Juro.Core.csproj b/Juro.Core/Juro.Core.csproj index a66c829..1cb1119 100644 --- a/Juro.Core/Juro.Core.csproj +++ b/Juro.Core/Juro.Core.csproj @@ -1,7 +1,7 @@ - netstandard2.0;netstandard2.1;net461;net6.0 + netstandard2.0;netstandard2.1;net461;net8.0 true diff --git a/Juro.Extractors/Juro.Extractors.csproj b/Juro.Extractors/Juro.Extractors.csproj index a7d83bf..3498f3b 100644 --- a/Juro.Extractors/Juro.Extractors.csproj +++ b/Juro.Extractors/Juro.Extractors.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;net461;net6.0 + netstandard2.0;netstandard2.1;net461;net8.0 true diff --git a/Juro.Providers.Adult/Juro.Providers.Adult.csproj b/Juro.Providers.Adult/Juro.Providers.Adult.csproj index 1d807df..d722b31 100644 --- a/Juro.Providers.Adult/Juro.Providers.Adult.csproj +++ b/Juro.Providers.Adult/Juro.Providers.Adult.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;net461;net6.0; + netstandard2.0;netstandard2.1;net461;net8.0 true diff --git a/Juro.Providers/Juro.Providers.csproj b/Juro.Providers/Juro.Providers.csproj index 9fd7fec..ef8c267 100644 --- a/Juro.Providers/Juro.Providers.csproj +++ b/Juro.Providers/Juro.Providers.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netstandard2.1;net461;net6.0 + netstandard2.0;netstandard2.1;net461;net8.0 true true diff --git a/Juro.WebApi/Controllers/Anime/AnimeController.cs b/Juro.WebApi/Controllers/Anime/AnimeController.cs new file mode 100644 index 0000000..06e7efb --- /dev/null +++ b/Juro.WebApi/Controllers/Anime/AnimeController.cs @@ -0,0 +1,10 @@ +using Juro.Providers.Anime; +using Microsoft.AspNetCore.Mvc; + +namespace Juro.WebApi.Controllers.Anime; + +[ApiController] +[Route("api/[controller]")] +public class AnimeController(Gogoanime provider) : GogoanimeController(provider) +{ +} diff --git a/Juro.WebApi/Controllers/Manga/MangaController.cs b/Juro.WebApi/Controllers/Manga/MangaController.cs new file mode 100644 index 0000000..fe27d7f --- /dev/null +++ b/Juro.WebApi/Controllers/Manga/MangaController.cs @@ -0,0 +1,10 @@ +using Juro.Providers.Manga; +using Microsoft.AspNetCore.Mvc; + +namespace Juro.WebApi.Controllers.Manga; + +[ApiController] +[Route("api/[controller]")] +public class MangaController(Mangadex provider) : MangadexController(provider) +{ +} diff --git a/Juro/Clients/AnimeApiClient.cs b/Juro/Clients/AnimeApiClient.cs index 0448414..bc11464 100644 --- a/Juro/Clients/AnimeApiClient.cs +++ b/Juro/Clients/AnimeApiClient.cs @@ -21,7 +21,7 @@ public class AnimeApiClient(string baseUrl, IHttpClientFactory httpClientFactory public string BaseUrl { get; set; } = baseUrl; - public string ProviderKey { get; set; } = "Gogoanime"; + public string ProviderKey { get; set; } = "Anime"; /// /// Initializes an instance of . @@ -36,30 +36,17 @@ public AnimeApiClient(string baseUrl) : this(baseUrl, Http.ClientProvider) { } public async ValueTask> GetProvidersAsync( - ProviderType type, CancellationToken cancellationToken = default ) { var response = await _http.ExecuteAsync( - $"{BaseUrl}/Providers?type={type}", + $"{BaseUrl}/Providers?type={(int)ProviderType.Anime}", cancellationToken: cancellationToken ); return JsonSerializer.Deserialize>(response, _options)!; } - public async ValueTask GetDefaultProviderAsync( - CancellationToken cancellationToken = default - ) - { - var response = await _http.ExecuteAsync( - $"{BaseUrl}/Providers", - cancellationToken: cancellationToken - ); - - return JsonSerializer.Deserialize(response, _options)!; - } - public async ValueTask GetAsync( string id, CancellationToken cancellationToken = default diff --git a/Juro/Clients/MangaApiClient.cs b/Juro/Clients/MangaApiClient.cs new file mode 100644 index 0000000..ddad3ab --- /dev/null +++ b/Juro/Clients/MangaApiClient.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; +using System.Threading; +using System.Threading.Tasks; +using Juro.Core; +using Juro.Core.Models; +using Juro.Core.Models.Manga; +using Juro.Core.Utils; +using Juro.Core.Utils.Extensions; + +namespace Juro.Clients; + +public class MangaApiClient(string baseUrl, IHttpClientFactory httpClientFactory) +{ + private readonly HttpClient _http = httpClientFactory.CreateClient(); + private readonly JsonSerializerOptions _options = + new() + { + PropertyNameCaseInsensitive = true, + TypeInfoResolver = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + static typeInfo => + { + if (typeInfo.Type == typeof(IMangaInfo)) + typeInfo.CreateObject = () => new MangaInfo(); + else if (typeInfo.Type == typeof(IMangaResult)) + typeInfo.CreateObject = () => new MangaResult(); + else if (typeInfo.Type == typeof(IMangaChapter)) + typeInfo.CreateObject = () => new MangaChapter(); + else if (typeInfo.Type == typeof(IMangaChapterPage)) + typeInfo.CreateObject = () => new MangaChapterPage(); + }, + }, + }, + }; + + public string BaseUrl { get; set; } = baseUrl; + + public string ProviderKey { get; set; } = "MangaPill"; + + /// + /// Initializes an instance of . + /// + public MangaApiClient(string baseUrl, Func httpClientProvider) + : this(baseUrl, new HttpClientFactory(httpClientProvider)) { } + + /// + /// Initializes an instance of . + /// + public MangaApiClient(string baseUrl) + : this(baseUrl, Http.ClientProvider) { } + + public async ValueTask> GetProvidersAsync( + CancellationToken cancellationToken = default + ) + { + var response = await _http.ExecuteAsync( + $"{BaseUrl}/Providers?type={(int)ProviderType.Manga}", + cancellationToken: cancellationToken + ); + + return JsonSerializer.Deserialize>(response, _options)!; + } + + public async ValueTask GetAsync( + string id, + CancellationToken cancellationToken = default + ) + { + var response = await _http.ExecuteAsync( + $"{BaseUrl}/{ProviderKey}/{Uri.EscapeDataString(id)}", + cancellationToken: cancellationToken + ); + + return JsonSerializer.Deserialize(response, _options)!; + } + + public async ValueTask> SearchAsync( + string query, + CancellationToken cancellationToken = default + ) + { + var response = await _http.ExecuteAsync( + $"{BaseUrl}/{ProviderKey}/Search?q={Uri.EscapeDataString(query)}", + cancellationToken: cancellationToken + ); + + return JsonSerializer.Deserialize>(response, _options) ?? []; + } + + public async ValueTask> GetChapterPagesAsync( + string id, + CancellationToken cancellationToken = default + ) + { + var response = await _http.ExecuteAsync( + $"{BaseUrl}/{ProviderKey}/ChapterPages/{Uri.EscapeDataString(id)}", + cancellationToken: cancellationToken + ); + + return JsonSerializer.Deserialize>(response, _options) ?? []; + } +} diff --git a/Juro/Juro.csproj b/Juro/Juro.csproj index 492634c..ab736af 100644 --- a/Juro/Juro.csproj +++ b/Juro/Juro.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 true