Skip to content

Commit

Permalink
bring back anime pahe
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Feb 9, 2024
1 parent 99f12a2 commit 5823ea8
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 16 deletions.
Binary file modified Plugins Store/Totoro.Plugins.Anime.AnimePahe.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class StreamProviderTests
private readonly JsonSerializerOptions _searializerOption = new() { WriteIndented = true };
private readonly Dictionary<string, string> _urlMap = new()
{
{ Hyouka, Url.Combine(ConfigManager<Config>.Current.Url, "/anime/bcc68f86-30c0-477f-6b6b-615cecdad923") },
{ Hyouka, Url.Combine(ConfigManager<Config>.Current.Url, "/anime/79997f02-ab7a-b12e-51bf-ca4454374da1") },
{ OshiNoKo, Url.Combine(ConfigManager<Config>.Current.Url, "/anime/ae95c1fc-25d9-d824-1340-d46440e9652e") },
{ RentAGFS3, Url.Combine(ConfigManager<Config>.Current.Url, "/anime/e53e054a-c233-f2ba-45d5-d762e183cc96") },
{ JjkS2, Url.Combine(ConfigManager<Config>.Current.Url, "/anime/c24ef525-a643-7dc5-1882-a6b27b2421c2") }
};

private readonly bool _allEpisodes = true;
private readonly bool _allEpisodes = false;

public StreamProviderTests(ITestOutputHelper output)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AiredEpisode : IAiredAnimeEpisode, IHaveCreatedTime
public async IAsyncEnumerable<IAiredAnimeEpisode> GetRecentlyAiredEpisodes(int page = 1)
{
var json = await ConfigManager<Config>.Current.Url.AppendPathSegment("api")
.WithHeaders(ConfigManager<Config>.Current.GetHeaders())
.SetQueryParams(new
{
m = "airing",
Expand Down
1 change: 1 addition & 0 deletions Plugins/Anime/Totoro.Plugins.Anime.AnimePahe/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async IAsyncEnumerable<ICatalogItem> Search(string query)
{
var json = await ConfigManager<Config>.Current.Url
.AppendPathSegment("api")
.WithHeaders(ConfigManager<Config>.Current.GetHeaders())
.SetQueryParams(new
{
m = "search",
Expand Down
10 changes: 10 additions & 0 deletions Plugins/Anime/Totoro.Plugins.Anime.AnimePahe/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Totoro.Plugins.Helpers;
using Totoro.Plugins.Options;

namespace Totoro.Plugins.Anime.AnimePahe;
Expand All @@ -8,4 +9,13 @@ public class Config : AnimeProviderConfigObject
[Description("Url to home page")]
[Glyph(Glyphs.Url)]
public string Url { get; set; } = "https://animepahe.ru/";

public Dictionary<string,string> GetHeaders()
{
return new Dictionary<string, string>
{
{ HeaderNames.Referer, Url },
{ HeaderNames.Cookie, "__ddg2_=YW5pbWRsX3NheXNfaGkNCg.;" }
};
}
}
3 changes: 2 additions & 1 deletion Plugins/Anime/Totoro.Plugins.Anime.AnimePahe/IdMapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
using Flurl.Http;
using Totoro.Plugins.Anime.Models;
using Totoro.Plugins.Options;

namespace Totoro.Plugins.Anime.AnimePahe;

Expand All @@ -11,7 +12,7 @@ internal partial class IdMapper : IIdMapper

public async Task<AnimeId> MapId(string url)
{
var html = await url.GetStringAsync();
var html = await url.WithHeaders(ConfigManager<Config>.Current.GetHeaders()).GetStringAsync();

var animeId = new AnimeId();

Expand Down
13 changes: 10 additions & 3 deletions Plugins/Anime/Totoro.Plugins.Anime.AnimePahe/StreamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ internal partial class StreamProvider : IAnimeStreamProvider, IEnableLogger
private static partial Regex StreamsRegex();

public const string CHARACTER_MAP = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/";

private readonly IFlurlClient _client = new FlurlClient(new HttpClient(new HttpClientHandler { AllowAutoRedirect = false }));

public async Task<int> GetNumberOfStreams(string url)
{
var html = await url.WithClient(_client).GetStringAsync();
var html = await url.WithClient(_client).WithHeaders(ConfigManager<Config>.Current.GetHeaders()).GetStringAsync();
var releaseId = IdRegex().Match(html).Groups[1].Value;
var page = await GetSessionPage(releaseId, 1);
return (int)page.total;
}

public async IAsyncEnumerable<VideoStreamsForEpisode> GetStreams(string url, Range range)
{
var doc = await url.GetHtmlDocumentAsync();
var doc = await url
.WithHeaders(ConfigManager<Config>.Current.GetHeaders())
.GetHtmlDocumentAsync();

var releaseId = IdRegex().Match(doc.Text).Groups[1].Value;
var firstPage = await GetSessionPage(releaseId, 1);
Expand Down Expand Up @@ -115,6 +118,7 @@ private async IAsyncEnumerable<VideoStreamsForEpisode> GetStreamFromPage(AnimePa
private async Task<AnimePaheEpisodePage> GetSessionPage(string releaseId, int page)
{
return await ConfigManager<Config>.Current.Url.AppendPathSegment("api")
.WithHeaders(ConfigManager<Config>.Current.GetHeaders())
.SetQueryParams(new
{
m = "release",
Expand All @@ -127,7 +131,10 @@ private async Task<AnimePaheEpisodePage> GetSessionPage(string releaseId, int pa

private async Task<Dictionary<string, string>> GetStreamUrl(string releaseId, string streamSession)
{
var streamData = await ConfigManager<Config>.Current.Url.AppendPathSegments("play", releaseId, streamSession).GetStringAsync();
var streamData = await ConfigManager<Config>.Current.Url.AppendPathSegments("play", releaseId, streamSession)
.WithHeaders(ConfigManager<Config>.Current.GetHeaders())
.GetStringAsync();

var result = new Dictionary<string, string>();

foreach (var match in StreamsRegex().Matches(streamData).Cast<Match>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<Version>1.10</Version>
<Version>1.11</Version>
<OutputPath Condition="$(Configuration) == Release">..\..\..\Plugins Store\</OutputPath>
<AppendTargetFrameworkToOutputPath Condition="$(Configuration) == Release">false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath Condition="$(Configuration) == Release">false</AppendRuntimeIdentifierToOutputPath>
Expand Down
2 changes: 1 addition & 1 deletion Totoro.Core/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static IServiceCollection AddPlugins(this IServiceCollection services)

#if DEBUG
// anime
//PluginFactory<AnimeProvider>.Instance.LoadPlugin(new Plugins.Anime.AnimePahe.Plugin());
PluginFactory<AnimeProvider>.Instance.LoadPlugin(new Plugins.Anime.AnimePahe.Plugin());
PluginFactory<AnimeProvider>.Instance.LoadPlugin(new Plugins.Anime.AllAnime.Plugin());
PluginFactory<AnimeProvider>.Instance.LoadPlugin(new Plugins.Anime.YugenAnime.Plugin());
PluginFactory<AnimeProvider>.Instance.LoadPlugin(new Plugins.Anime.GogoAnime.Plugin());
Expand Down
28 changes: 21 additions & 7 deletions Totoro.WinUI/Media/Flyleaf/FlyleafTransportControls.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animations="using:CommunityToolkit.WinUI.Animations"
xmlns:c="using:Totoro.Core.Models"
xmlns:ctk="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:help="using:Totoro.WinUI.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -98,14 +99,27 @@
VerticalAlignment="Center"
Text="{x:Bind help:Converters.TicksToTime(Player.CurTime), Mode=OneWay}" />

<Slider
x:Name="TimeSlider"
<ctk:SwitchPresenter
Grid.Column="1"
Margin="10,0,10,0"
VerticalAlignment="Center"
IsTabStop="False"
Maximum="{x:Bind help:Converters.TiksToSeconds(Player.Duration), Mode=OneWay}"
Value="{x:Bind help:Converters.TiksToSeconds(Player.CurTime), Mode=OneWay}" />
TargetType="x:Boolean"
Value="{x:Bind Buffering}">
<ctk:Case Value="True">
<ProgressBar
Margin="10,0,10,0"
VerticalAlignment="Center"
IsIndeterminate="True" />
</ctk:Case>
<ctk:Case Value="False">
<Slider
x:Name="TimeSlider"
Grid.Column="1"
Margin="10,0,10,0"
VerticalAlignment="Center"
IsTabStop="False"
Maximum="{x:Bind help:Converters.TiksToSeconds(Player.Duration), Mode=OneWay}"
Value="{x:Bind help:Converters.TiksToSeconds(Player.CurTime), Mode=OneWay}" />
</ctk:Case>
</ctk:SwitchPresenter>

<TextBlock
Grid.Column="2"
Expand Down
38 changes: 37 additions & 1 deletion Totoro.WinUI/Media/Flyleaf/FlyleafTransportControls.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reactive.Concurrency;
using System.Reactive.Subjects;
using FlyleafLib.MediaFramework.MediaStream;
using FlyleafLib.MediaPlayer;
Expand Down Expand Up @@ -65,6 +66,15 @@ public IEnumerable<string> Resolutions
set { SetValue(ResolutionsProperty, value); }
}

public bool Buffering
{
get { return (bool)GetValue(BufferingProperty); }
set { SetValue(BufferingProperty, value); }
}

public static readonly DependencyProperty BufferingProperty =
DependencyProperty.Register("Buffering", typeof(bool), typeof(FlyleafTransportControls), new PropertyMetadata(false));

public static readonly DependencyProperty ResolutionsProperty =
DependencyProperty.Register("Resolutions", typeof(IEnumerable<string>), typeof(FlyleafTransportControls), new PropertyMetadata(null, OnResolutionsChanged));

Expand All @@ -87,7 +97,23 @@ public IEnumerable<string> Resolutions
DependencyProperty.Register("IsNextTrackButtonVisible", typeof(bool), typeof(FlyleafTransportControls), new PropertyMetadata(false));

public static readonly DependencyProperty PlayerProperty =
DependencyProperty.Register("Player", typeof(Player), typeof(FlyleafTransportControls), new PropertyMetadata(null));
DependencyProperty.Register("Player", typeof(Player), typeof(FlyleafTransportControls), new PropertyMetadata(null, OnPlayerChanged));

private static void OnPlayerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var tc = (FlyleafTransportControls)d;
if(e.OldValue is Player oldPlayer)
{
oldPlayer.BufferingStarted -= tc.Player_BufferingStarted;
oldPlayer.BufferingCompleted -= tc.Player_BufferingCompleted;
}

if(e.NewValue is Player newPlayer)
{
newPlayer.BufferingStarted += tc.Player_BufferingStarted;
newPlayer.BufferingCompleted += tc.Player_BufferingCompleted;
}
}

private static void OnSelectedResolutionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Expand Down Expand Up @@ -207,6 +233,16 @@ public FlyleafTransportControls()
});
}

private void Player_BufferingCompleted(object sender, BufferingCompletedArgs e)
{
RxApp.MainThreadScheduler.Schedule(() => Buffering = false);
}

private void Player_BufferingStarted(object sender, EventArgs e)
{
RxApp.MainThreadScheduler.Schedule(() => Buffering = true);
}

public string TimeRemaning(long currentTime, long duration)
{
var remaning = duration - currentTime;
Expand Down
5 changes: 5 additions & 0 deletions plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"DisplayName": "Wit Anime",
"Version": "1.3.0.0",
"FileName": "Totoro.Plugins.Anime.WitAnime.dll"
},
{
"DisplayName": "Anime Pahe",
"Version": "1.11.0.0",
"FileName": "Totoro.Plugins.Anime.AnimePahe.dll"
}
],
"Manga": [
Expand Down

0 comments on commit 5823ea8

Please sign in to comment.