From 342d05d1bbaf3ad1df7a8786a0358042e6472e03 Mon Sep 17 00:00:00 2001 From: Athul Raj Date: Sat, 24 Dec 2022 21:56:44 +0530 Subject: [PATCH] bring back quality selection, add yugen anime for supported provider. --- Totoro.Core/Totoro.Core.csproj | 4 ++-- Totoro.Core/ViewModels/SettingsViewModel.cs | 7 +++++-- Totoro.Core/ViewModels/WatchViewModel.cs | 13 ++++++++++++- .../Media/CustomMediaTransportControls.cs | 17 ++++++++++------- Totoro.WinUI/Services/ActivationService.cs | 11 ----------- .../Styles/MediaTransportControls.xaml | 19 +++++++++---------- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Totoro.Core/Totoro.Core.csproj b/Totoro.Core/Totoro.Core.csproj index 49295179..1da8e634 100644 --- a/Totoro.Core/Totoro.Core.csproj +++ b/Totoro.Core/Totoro.Core.csproj @@ -14,9 +14,9 @@ - + - + diff --git a/Totoro.Core/ViewModels/SettingsViewModel.cs b/Totoro.Core/ViewModels/SettingsViewModel.cs index beb13e19..e818d28c 100644 --- a/Totoro.Core/ViewModels/SettingsViewModel.cs +++ b/Totoro.Core/ViewModels/SettingsViewModel.cs @@ -1,4 +1,5 @@ using AnimDL.Api; +using Splat; namespace Totoro.Core.ViewModels; @@ -15,7 +16,7 @@ public class SettingsViewModel : NavigatableViewModel, ISettings [Reactive] public bool ContributeTimeStamps { get; set; } [Reactive] public DefaultUrls DefaultUrls { get; set; } public List Themes { get; set; } = Enum.GetValues().Cast().ToList(); - public List ProviderTypes { get; set; } = new List { ProviderType.GogoAnime }; + public List ProviderTypes { get; set; } = new List { ProviderType.GogoAnime, ProviderType.Yugen }; public ICommand AuthenticateCommand { get; } public SettingsViewModel(IThemeSelectorService themeSelectorService, @@ -51,7 +52,9 @@ public SettingsViewModel(IThemeSelectorService themeSelectorService, .Select(x => GetType().GetProperty(x.PropertyName)) .Subscribe(propInfo => { - localSettingsService.SaveSetting(propInfo.Name, propInfo.GetValue(this)); + var value = propInfo.GetValue(this); + this.Log().Debug($"""Setting Changed "{propInfo.Name}" => {value}"""); + localSettingsService.SaveSetting(propInfo.Name, value); }) .DisposeWith(Garbage); diff --git a/Totoro.Core/ViewModels/WatchViewModel.cs b/Totoro.Core/ViewModels/WatchViewModel.cs index 19fe185a..d9c8661f 100644 --- a/Totoro.Core/ViewModels/WatchViewModel.cs +++ b/Totoro.Core/ViewModels/WatchViewModel.cs @@ -120,7 +120,7 @@ public WatchViewModel(IProviderFactory providerFactory, this.WhenAnyValue(x => x.Query) .Where(query => query is { Length: > 3 }) .Throttle(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler) - .SelectMany(query => animeService.GetAnime(query)) + .SelectMany(animeService.GetAnime) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(list => _searchResultCache.EditDiff(list, (first, second) => first.Title == second.Title), RxApp.DefaultExceptionHandler.OnNext); @@ -129,6 +129,7 @@ public WatchViewModel(IProviderFactory providerFactory, .Where(_ => !UseLocalMedia) .WhereNotNull() .SelectMany(model => Find(model.Id, model.Title)) + .Log(this, "Selected Anime", x => $"{x.Sub.Title}") .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => SelectedAnimeResult = x); @@ -163,6 +164,7 @@ public WatchViewModel(IProviderFactory providerFactory, this.ObservableForProperty(x => x.SelectedAudio, x => x) .Do(result => DoIfRpcEnabled(() => discordRichPresense.UpdateDetails(result.Title))) .SelectMany(result => Provider.StreamProvider.GetNumberOfStreams(result.Url)) + .Log(this, "Number of Episodes") .Select(count => Enumerable.Range(1, count).ToList()) .Do(list => _episodesCache.EditDiff(list)) .Select(_ => _episodeRequest ?? (Anime?.Tracking?.WatchedEpisodes ?? 0) + 1) @@ -174,6 +176,7 @@ public WatchViewModel(IProviderFactory providerFactory, episodeChanged .Where(_ => !UseLocalMedia) .Do(x => DoIfRpcEnabled(() => discordRichPresense.UpdateState($"Episode {x}"))) + .Log(this, "Current Episode") .ObserveOn(RxApp.TaskpoolScheduler) .SelectMany(ep => Provider.StreamProvider.GetStreams(SelectedAudio.Url, ep.Value..ep.Value).ToListAsync().AsTask()) .Select(list => list.FirstOrDefault()) @@ -195,6 +198,7 @@ public WatchViewModel(IProviderFactory providerFactory, this.ObservableForProperty(x => x.Streams, x => x) .WhereNotNull() .Select(x => x.Qualities.Keys) + .Log(this, "Qualities", x => string.Join(",", x)) .ObserveOn(RxApp.MainThreadScheduler) .ToPropertyEx(this, x => x.Qualities, Enumerable.Empty(), true); @@ -202,6 +206,7 @@ public WatchViewModel(IProviderFactory providerFactory, this.ObservableForProperty(x => x.SelectedStream, x => x) .WhereNotNull() .ObserveOn(RxApp.MainThreadScheduler) + .Log(this, "Stream changed", x => x.Url) .Do(mediaPlayer.SetMedia) .Do(_ => mediaPlayer.Play(playbackStateStorage.GetTime(Anime?.Id ?? 0, CurrentEpisode ?? 0))) .Subscribe(); @@ -247,6 +252,12 @@ public WatchViewModel(IProviderFactory providerFactory, .Select(x => x.Items?.FirstOrDefault(x => x.SkipType == "ed")) .Select(x => x?.Interval?.StartTime ?? 0) .ToPropertyEx(this, x => x.OutroPosition, true); + + this.WhenAnyValue(x => x.Qualities) + .Where(x => x.Count() > 1) + .Select(x => x.Select(int.Parse).Max().ToString()) + .Log(this, "Selected Quality") + .InvokeCommand(ChangeQuality); } [Reactive] public string Query { get; set; } diff --git a/Totoro.WinUI/Media/CustomMediaTransportControls.cs b/Totoro.WinUI/Media/CustomMediaTransportControls.cs index 29e64608..d0173571 100644 --- a/Totoro.WinUI/Media/CustomMediaTransportControls.cs +++ b/Totoro.WinUI/Media/CustomMediaTransportControls.cs @@ -47,18 +47,21 @@ private static void OnQualitiesChanged(DependencyObject d, DependencyPropertyCha if (e.NewValue is IEnumerable values) { var qualities = values.ToList(); - if (qualities.Count <= 1) + if (qualities.Count == 1) { mtc._onQualityChanged.OnNext("default"); + mtc._qualitiesButton.Visibility = Visibility.Collapsed; return; } - - mtc._qualitiesButton.IsEnabled = true; - foreach (var item in qualities) + else if(qualities.Count > 1) { - var flyoutItem = new MenuFlyoutItem { Text = item }; - flyoutItem.Click += mtc.FlyoutItem_Click; - flyout.Items.Add(flyoutItem); + mtc._qualitiesButton.IsEnabled = true; + foreach (var item in qualities) + { + var flyoutItem = new MenuFlyoutItem { Text = item }; + flyoutItem.Click += mtc.FlyoutItem_Click; + flyout.Items.Add(flyoutItem); + } } } } diff --git a/Totoro.WinUI/Services/ActivationService.cs b/Totoro.WinUI/Services/ActivationService.cs index ed4e6456..1030515c 100644 --- a/Totoro.WinUI/Services/ActivationService.cs +++ b/Totoro.WinUI/Services/ActivationService.cs @@ -129,15 +129,4 @@ private async Task StartupAsync() } catch { } } - - private static async Task RequestFullscreen() - { - var windowHandle = WindowNative.GetWindowHandle(App.MainWindow); - var windowId = Win32Interop.GetWindowIdFromWindow(windowHandle); - var appWindow = AppWindow.GetFromWindowId(windowId); - appWindow.SetPresenter(AppWindowPresenterKind.FullScreen); - await Task.Delay(250); - appWindow.SetPresenter(AppWindowPresenterKind.Default); - appWindow.SetPresenter(AppWindowPresenterKind.FullScreen); - } } diff --git a/Totoro.WinUI/Styles/MediaTransportControls.xaml b/Totoro.WinUI/Styles/MediaTransportControls.xaml index 984d2eba..d23e7ca8 100644 --- a/Totoro.WinUI/Styles/MediaTransportControls.xaml +++ b/Totoro.WinUI/Styles/MediaTransportControls.xaml @@ -262,6 +262,15 @@ + + + + + - - - - -