Skip to content

Commit

Permalink
upgrade aniwave plugin, but doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Feb 11, 2024
1 parent 915acd0 commit fa7ce76
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using Flurl;
using Totoro.Plugins.Options;
using Xunit.Abstractions;

namespace Totoro.Plugins.Anime.Aniwave.Tests;
Expand All @@ -14,7 +15,7 @@ public class StreamProviderTests
private readonly JsonSerializerOptions _searializerOption = new() { WriteIndented = true };
private readonly Dictionary<string, string> _urlMap = new()
{
{ Hyouka, Url.Combine(Config.Url, "/watch/hyouka.lqq") }
{ Hyouka, Url.Combine(ConfigManager<Config>.Current.Url, "/watch/hyouka.lqq") }
};
private readonly bool _allEpisodes = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -22,4 +22,8 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Totoro.Plugins.Anime.Aniwave\Totoro.Plugins.Anime.Aniwave.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HtmlAgilityPack;
using HtmlAgilityPack.CssSelectors.NetCore;
using Totoro.Plugins.Anime.Contracts;
using Totoro.Plugins.Options;

namespace Totoro.Plugins.Anime.Aniwave;

Expand All @@ -20,7 +21,7 @@ class AiredEpisode : IAiredAnimeEpisode

public async IAsyncEnumerable<IAiredAnimeEpisode> GetRecentlyAiredEpisodes(int page = 1)
{
var response = await Config.Url.AppendPathSegment("/ajax/home/widget/updated-all")
var response = await ConfigManager<Config>.Current.Url.AppendPathSegment("/ajax/home/widget/updated-all")
.SetQueryParam("page", page)
.GetJsonAsync();

Expand All @@ -41,7 +42,7 @@ public async IAsyncEnumerable<IAiredAnimeEpisode> GetRecentlyAiredEpisodes(int p
{
Title = title,
Image = img,
Url = Url.Combine(Config.Url, animeUrl),
Url = Url.Combine(ConfigManager<Config>.Current.Url, animeUrl),
Episode = epInt,
EpisodeString = eps
};
Expand Down
7 changes: 4 additions & 3 deletions Plugins/Anime/Totoro.Plugins.Anime.Aniwave/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Totoro.Plugins.Anime.Contracts;
using Totoro.Plugins.Contracts.Optional;
using Totoro.Plugins.Helpers;
using Totoro.Plugins.Options;

namespace Totoro.Plugins.Anime.Aniwave;

Expand All @@ -17,8 +18,8 @@ class SearchResult : ICatalogItem, IHaveImage

public async IAsyncEnumerable<ICatalogItem> Search(string query)
{
var vrf = await Vrf.Encode(query);
var doc = await Config.Url
var vrf = Vrf.Encode(query);
var doc = await ConfigManager<Config>.Current.Url
.AppendPathSegment("/filter")
.SetQueryParam("language[]", "subbed")
.SetQueryParam("keyword", query)
Expand All @@ -28,7 +29,7 @@ public async IAsyncEnumerable<ICatalogItem> Search(string query)

foreach (var item in doc.QuerySelectorAll("#list-items div.ani.poster.tip > a"))
{
var url = Url.Combine(Config.Url, item.Attributes["href"].Value);
var url = Url.Combine(ConfigManager<Config>.Current.Url, item.Attributes["href"].Value);
var imageNode = item.QuerySelector("img");
var title = imageNode.Attributes["alt"].Value;
var image = imageNode.Attributes["src"].Value;
Expand Down
11 changes: 8 additions & 3 deletions Plugins/Anime/Totoro.Plugins.Anime.Aniwave/Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace Totoro.Plugins.Anime.Aniwave;
using System.ComponentModel;
using Totoro.Plugins.Options;

internal static class Config
namespace Totoro.Plugins.Anime.Aniwave;

public class Config : AnimeProviderConfigObject
{
internal static string Url { get; set; } = "https://aniwave.to";
[Description("Url to home page")]
[Glyph(Glyphs.Url)]
public string Url { get; set; } = "https://aniwave.to";
}
26 changes: 3 additions & 23 deletions Plugins/Anime/Totoro.Plugins.Anime.Aniwave/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,21 @@

namespace Totoro.Plugins.Anime.Aniwave;

public class Plugin : IPlugin<AnimeProvider>
public class Plugin : Plugin<AnimeProvider, Config>
{
public AnimeProvider Create() => new()
public override AnimeProvider Create() => new()
{
Catalog = new Catalog(),
StreamProvider = new StreamProvider(),
AiredAnimeEpisodeProvider = new AiredEpisodesProvider()
};

public PluginInfo GetInfo() => new()
public override PluginInfo GetInfo() => new()
{
DisplayName = "Aniwave",
Name = "aniwave",
Version = Assembly.GetExecutingAssembly().GetName().Version!,
Icon = typeof(Plugin).Assembly.GetManifestResourceStream("Totoro.Plugins.Anime.Aniwave.aniwave-logo.png"),
Description = "previously 9anime"
};

public PluginOptions GetOptions()
{
return new PluginOptions()
.AddOption(x =>
{
return x.WithNameAndValue(Config.Url)
.WithDisplayName("Url")
.WithDescription("Url to home page")
.WithGlyph(Glyphs.Url)
.ToPluginOption();
});
}

public void SetOptions(PluginOptions options)
{
Config.Url = options.GetString(nameof(Config.Url), Config.Url);
}

object IPlugin.Create() => Create();
}
19 changes: 11 additions & 8 deletions Plugins/Anime/Totoro.Plugins.Anime.Aniwave/StreamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Totoro.Plugins.Anime.Contracts;
using Totoro.Plugins.Anime.Models;
using Totoro.Plugins.Helpers;
using Totoro.Plugins.Options;

namespace Totoro.Plugins.Anime.Aniwave;

Expand All @@ -19,8 +20,8 @@ public async Task<int> GetNumberOfStreams(string url)
{
var doc = await url.GetHtmlDocumentAsync();
var animeId = doc.QuerySelector("#watch-main").Attributes["data-id"].Value;
var vrf = await Vrf.Encode(animeId);
var body = await Config.Url
var vrf = Vrf.Encode(animeId);
var body = await ConfigManager<Config>.Current.Url
.AppendPathSegment($"/ajax/episode/list/{animeId}")
.SetQueryParam("vrf", vrf)
.GetStringAsync();
Expand All @@ -45,8 +46,8 @@ public async IAsyncEnumerable<VideoStreamsForEpisode> GetStreams(string url, Ran
{
var doc = await url.GetHtmlDocumentAsync();
var animeId = doc.QuerySelector("#watch-main").Attributes["data-id"].Value;
var vrf = await Vrf.Encode(animeId);
var body = await Config.Url
var vrf = Vrf.Encode(animeId);
var body = await ConfigManager<Config>.Current.Url
.AppendPathSegment($"/ajax/episode/list/{animeId}")
.SetQueryParam("vrf", vrf)
.GetStringAsync();
Expand Down Expand Up @@ -84,10 +85,11 @@ public async IAsyncEnumerable<VideoStreamsForEpisode> GetStreams(string url, Ran
continue;
}

body = await Config.Url
body = await ConfigManager<Config>.Current.Url
.AppendPathSegment($"/ajax/server/list/{id}")
.SetQueryParam("vrf", await Vrf.Encode(id))
.SetQueryParam("vrf", Vrf.Encode(id))
.GetStringAsync();

jObject = JsonNode.Parse(body);
html = jObject!["result"]!.ToString();
var doc2 = new HtmlDocument();
Expand All @@ -97,10 +99,11 @@ public async IAsyncEnumerable<VideoStreamsForEpisode> GetStreams(string url, Ran
{
var name = serverItem.InnerText;
var serverId = serverItem.Attributes["data-link-id"].Value;
var result = await Config.Url
var result = await ConfigManager<Config>.Current.Url
.AppendPathSegment($"/ajax/server/{serverId}")
.SetQueryParam("vrf", await Vrf.Encode(serverId))
.SetQueryParam("vrf", Vrf.Encode(serverId))
.GetStringAsync();

jObject = JsonNode.Parse(result);
var encodedUrl = jObject!["result"]!["url"]!.ToString();
var decoded = await Vrf.Decode(encodedUrl);
Expand Down
14 changes: 14 additions & 0 deletions Totoro.WinUI/Totoro.GUI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Totoro.Plugins.Manga.MangaD
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Totoro.Plugins.Manga.MangaDex.Tests", "..\Plugins\Manga\Totoro.Plugins.Manga.MangaDex.Tests\Totoro.Plugins.Manga.MangaDex.Tests.csproj", "{CC7B1FE4-CF75-45EC-9B64-6AE500D81E8C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Totoro.Plugins.Anime.Aniwave", "..\Plugins\Anime\Totoro.Plugins.Anime.Aniwave\Totoro.Plugins.Anime.Aniwave.csproj", "{994C74C7-3CC0-4A35-9A20-BDAB738FE24B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Totoro.Plugins.Anime.Aniwave.Tests", "..\Plugins\Anime\Totoro.Plugins.Anime.Aniwave.Tests\Totoro.Plugins.Anime.Aniwave.Tests.csproj", "{1955598A-A37F-4B3F-953F-7AC8D8770858}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -217,6 +221,14 @@ Global
{CC7B1FE4-CF75-45EC-9B64-6AE500D81E8C}.Debug|x64.Build.0 = Debug|x64
{CC7B1FE4-CF75-45EC-9B64-6AE500D81E8C}.Release|x64.ActiveCfg = Release|x64
{CC7B1FE4-CF75-45EC-9B64-6AE500D81E8C}.Release|x64.Build.0 = Release|x64
{994C74C7-3CC0-4A35-9A20-BDAB738FE24B}.Debug|x64.ActiveCfg = Debug|x64
{994C74C7-3CC0-4A35-9A20-BDAB738FE24B}.Debug|x64.Build.0 = Debug|x64
{994C74C7-3CC0-4A35-9A20-BDAB738FE24B}.Release|x64.ActiveCfg = Release|x64
{994C74C7-3CC0-4A35-9A20-BDAB738FE24B}.Release|x64.Build.0 = Release|x64
{1955598A-A37F-4B3F-953F-7AC8D8770858}.Debug|x64.ActiveCfg = Debug|x64
{1955598A-A37F-4B3F-953F-7AC8D8770858}.Debug|x64.Build.0 = Debug|x64
{1955598A-A37F-4B3F-953F-7AC8D8770858}.Release|x64.ActiveCfg = Release|x64
{1955598A-A37F-4B3F-953F-7AC8D8770858}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -254,6 +266,8 @@ Global
{C3C023F8-74CB-4201-A926-C86D22DDB1CF} = {E2331907-A768-4E4A-AACA-B53B83AA1919}
{2D423284-85B6-4C57-B8CE-AC62DC3EBD75} = {C3C023F8-74CB-4201-A926-C86D22DDB1CF}
{CC7B1FE4-CF75-45EC-9B64-6AE500D81E8C} = {C3C023F8-74CB-4201-A926-C86D22DDB1CF}
{994C74C7-3CC0-4A35-9A20-BDAB738FE24B} = {9F7BCE27-2A3F-4D82-8F52-903C9B356F25}
{1955598A-A37F-4B3F-953F-7AC8D8770858} = {9F7BCE27-2A3F-4D82-8F52-903C9B356F25}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98BB8C58-726D-4AB8-A113-D44B55413B79}
Expand Down

0 comments on commit fa7ce76

Please sign in to comment.