Skip to content

Commit

Permalink
bring back quality selection,
Browse files Browse the repository at this point in the history
add yugen anime for supported provider.
  • Loading branch information
insomniachi committed Dec 24, 2022
1 parent 0264e5d commit 342d05d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Totoro.Core/Totoro.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageReference Include="GraphQL.Client.Serializer.SystemTextJson" Version="5.1.0" />
<PackageReference Include="Humanizer.Core.uk" Version="2.14.1" />
<PackageReference Include="MalApi.V2" Version="2.0.8" />
<PackageReference Include="AnimDL.Core" Version="0.4.2" />
<PackageReference Include="AnimDL.Core" Version="0.4.3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="MonoTorrent" Version="2.0.6" />
<PackageReference Include="MonoTorrent" Version="2.0.7" />
<PackageReference Include="ReactiveUI.Fody" Version="18.4.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Splat.Microsoft.Extensions.Logging" Version="14.6.1" />
Expand Down
7 changes: 5 additions & 2 deletions Totoro.Core/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AnimDL.Api;
using Splat;

namespace Totoro.Core.ViewModels;

Expand All @@ -15,7 +16,7 @@ public class SettingsViewModel : NavigatableViewModel, ISettings
[Reactive] public bool ContributeTimeStamps { get; set; }
[Reactive] public DefaultUrls DefaultUrls { get; set; }
public List<ElementTheme> Themes { get; set; } = Enum.GetValues<ElementTheme>().Cast<ElementTheme>().ToList();
public List<ProviderType> ProviderTypes { get; set; } = new List<ProviderType> { ProviderType.GogoAnime };
public List<ProviderType> ProviderTypes { get; set; } = new List<ProviderType> { ProviderType.GogoAnime, ProviderType.Yugen };
public ICommand AuthenticateCommand { get; }

public SettingsViewModel(IThemeSelectorService themeSelectorService,
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 12 additions & 1 deletion Totoro.Core/ViewModels/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -195,13 +198,15 @@ 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<string>(), true);

// Start playing when we can and start from the previous session if exists
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();
Expand Down Expand Up @@ -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; }
Expand Down
17 changes: 10 additions & 7 deletions Totoro.WinUI/Media/CustomMediaTransportControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ private static void OnQualitiesChanged(DependencyObject d, DependencyPropertyCha
if (e.NewValue is IEnumerable<string> 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);
}
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions Totoro.WinUI/Services/ActivationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
19 changes: 9 additions & 10 deletions Totoro.WinUI/Styles/MediaTransportControls.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@
<SymbolIcon Symbol="Clock" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton
x:Name="QualitiesButton"
IsEnabled="False"
Style="{StaticResource AppBarButtonStyle}"
ToolTipService.ToolTip="Quality">
<AppBarButton.Icon>
<FontIcon Glyph="&#xe93e;" />
</AppBarButton.Icon>
</AppBarButton>
</StackPanel>

<StackPanel
Expand Down Expand Up @@ -316,16 +325,6 @@
Grid.Column="2"
HorizontalAlignment="Right"
Orientation="Horizontal">
<AppBarButton
x:Name="QualitiesButton"
IsEnabled="False"
Style="{StaticResource AppBarButtonStyle}"
ToolTipService.ToolTip="Quality"
Visibility="Collapsed">
<AppBarButton.Icon>
<FontIcon Glyph="&#xED1F;" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton
x:Name="SkipIntroButton"
Style="{StaticResource AppBarButtonStyle}"
Expand Down

0 comments on commit 342d05d

Please sign in to comment.