diff --git a/Totoro.Core/ViewModels/Discover/RecentEpisodesViewModel.cs b/Totoro.Core/ViewModels/Discover/RecentEpisodesViewModel.cs index 2e530a1..913dbc4 100644 --- a/Totoro.Core/ViewModels/Discover/RecentEpisodesViewModel.cs +++ b/Totoro.Core/ViewModels/Discover/RecentEpisodesViewModel.cs @@ -81,10 +81,9 @@ private async Task LoadPage(int page) } IsEpisodesLoading = true; - List results = []; try { - results = await Provider.AiredAnimeEpisodeProvider.GetRecentlyAiredEpisodes().ToListAsync(); + var results = await Provider.AiredAnimeEpisodeProvider.GetRecentlyAiredEpisodes(page).ToListAsync(); _episodesCache.AddOrUpdate(results); } catch(Exception ex) diff --git a/Totoro.WinUI/Helpers/Converters.cs b/Totoro.WinUI/Helpers/Converters.cs index a43d08c..261fc1b 100644 --- a/Totoro.WinUI/Helpers/Converters.cs +++ b/Totoro.WinUI/Helpers/Converters.cs @@ -306,7 +306,7 @@ private static PluginOptions GetOptions(string pluginName) [GeneratedRegex(@"(?'Type'.+)\sDub(?'Season'\d+)")] private static partial Regex DubRegex(); - private static ICommand WatchExternal { get; set; } = ReactiveCommand.Create(async param => + public static ICommand WatchExternal { get; set; } = ReactiveCommand.Create(async param => { switch (param) { @@ -315,6 +315,11 @@ private static PluginOptions GetOptions(string pluginName) await App.GetService().Initialize(anime, providerType, App.GetService().DefaultMediaPlayer); } break; + case (IAiredAnimeEpisode episode, string providerType): + { + App.GetService().Initialize(episode, providerType, App.GetService().DefaultMediaPlayer); + } + break; } }); } \ No newline at end of file diff --git a/Totoro.WinUI/Services/ExternalMediaPlayerLauncher.cs b/Totoro.WinUI/Services/ExternalMediaPlayerLauncher.cs index cb6e8ad..ec22834 100644 --- a/Totoro.WinUI/Services/ExternalMediaPlayerLauncher.cs +++ b/Totoro.WinUI/Services/ExternalMediaPlayerLauncher.cs @@ -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.Instance.CreatePlugin(providerType); + _mediaPlayer = PluginFactory.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(); diff --git a/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml b/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml index 02c9853..6ae2026 100644 --- a/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml +++ b/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml @@ -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"> @@ -60,6 +61,15 @@ + + + + + diff --git a/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml.cs b/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml.cs index 1bb7e2b..da4105c 100644 --- a/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml.cs +++ b/Totoro.WinUI/Views/DiscoverSections/RecentEpisodesSection.xaml.cs @@ -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; @@ -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(episode, ViewModel.SelectedProvider.Name)); + } }