Skip to content

Commit

Permalink
add watch external for recently aired episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Mar 20, 2024
1 parent dd86751 commit ec5c8f0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Totoro.Core/ViewModels/Discover/RecentEpisodesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ private async Task LoadPage(int page)
}

IsEpisodesLoading = true;
List<IAiredAnimeEpisode> results = [];
try
{
results = await Provider.AiredAnimeEpisodeProvider.GetRecentlyAiredEpisodes().ToListAsync();
var results = await Provider.AiredAnimeEpisodeProvider.GetRecentlyAiredEpisodes(page).ToListAsync();
_episodesCache.AddOrUpdate(results);
}
catch(Exception ex)
Expand Down
7 changes: 6 additions & 1 deletion Totoro.WinUI/Helpers/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private static PluginOptions GetOptions<T>(string pluginName)
[GeneratedRegex(@"(?'Type'.+)\sDub(?'Season'\d+)")]
private static partial Regex DubRegex();

private static ICommand WatchExternal { get; set; } = ReactiveCommand.Create<object>(async param =>
public static ICommand WatchExternal { get; set; } = ReactiveCommand.Create<object>(async param =>
{
switch (param)
{
Expand All @@ -315,6 +315,11 @@ private static PluginOptions GetOptions<T>(string pluginName)
await App.GetService<ExternalMediaPlayerLauncher>().Initialize(anime, providerType, App.GetService<ISettings>().DefaultMediaPlayer);
}
break;
case (IAiredAnimeEpisode episode, string providerType):
{
App.GetService<ExternalMediaPlayerLauncher>().Initialize(episode, providerType, App.GetService<ISettings>().DefaultMediaPlayer);
}
break;
}
});
}
11 changes: 11 additions & 0 deletions Totoro.WinUI/Services/ExternalMediaPlayerLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public async Task Initialize(AnimeModel anime, string providerType, string media
EpisodeModels.SelectEpisode(currentEp);
}

public void Initialize(IAiredAnimeEpisode episode, string providerType, string mediaPlayerType)
{
ProviderType = providerType;
Provider = PluginFactory<AnimeProvider>.Instance.CreatePlugin(providerType);
_mediaPlayer = PluginFactory<INativeMediaPlayer>.Instance.CreatePlugin(mediaPlayerType);
_videoStreamResolver = _videoStreamResolverFactory.CreateAnimDLResolver(ProviderType, episode.Url);
EpisodeModels = EpisodeModelCollection.FromEpisode(episode.Episode);
_title = $"{episode.Title} - {episode.EpisodeString.PadLeft(2, '0')}";
EpisodeModels.SelectEpisode(episode.Episode);
}

private async Task<(ICatalogItem Sub, ICatalogItem Dub)> SearchProvider(string title)
{
var results = await Provider.Catalog.Search(title).ToListAsync();
Expand Down
10 changes: 10 additions & 0 deletions Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pc="using:Totoro.Plugins.Anime.Contracts"
xmlns:uc="using:Totoro.WinUI.UserControls"
xmlns:ui="using:CommunityToolkit.WinUI"
mc:Ignorable="d">

<Grid>
Expand Down Expand Up @@ -60,6 +61,15 @@
<ItemsView.ItemTemplate>
<DataTemplate x:DataType="pc:IAiredAnimeEpisode">
<ItemContainer Height="320">
<ItemContainer.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem
Click="WatchExternalClicked"
Icon="{ui:FontIcon Glyph=&#xEC15;}"
Tag="{x:Bind}"
Text="WatchExternal" />
</MenuFlyout>
</ItemContainer.ContextFlyout>
<Grid x:Name="MainGrid" CornerRadius="3">
<Grid.RowDefinitions>
<RowDefinition />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Totoro.Core.ViewModels.Discover;
using ReactiveMarbles.ObservableEvents;
using Totoro.Plugins.Anime.Contracts;
using Microsoft.UI.Xaml.Controls;
using Totoro.WinUI.Helpers;

namespace Totoro.WinUI.Views.DiscoverSections;

Expand All @@ -19,4 +22,10 @@ public RecentEpisodesSection()
.InvokeCommand(ViewModel.SelectEpisode);
});
}

private void WatchExternalClicked(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
var episode = (IAiredAnimeEpisode)((MenuFlyoutItem)sender).Tag;
Converters.WatchExternal.Execute(new Tuple<IAiredAnimeEpisode, string>(episode, ViewModel.SelectedProvider.Name));
}
}

0 comments on commit ec5c8f0

Please sign in to comment.