Add - Added season select button to Add tab

Add - Added season download button to history
Add - Added some error messages
This commit is contained in:
Elwador 2024-07-23 21:14:55 +02:00
parent 18648fac1a
commit 2c9169f633
7 changed files with 216 additions and 23 deletions

View File

@ -642,12 +642,20 @@ public class CrunchyrollManager{
Console.WriteLine($"Selecting stream with {Languages.Locale2language(options.Hslang).Language} hardsubs"); Console.WriteLine($"Selecting stream with {Languages.Locale2language(options.Hslang).Language} hardsubs");
streams = streams.Where((s) => s.HardsubLang != "-" && s.HardsubLang == options.Hslang).ToList(); streams = streams.Where((s) => s.HardsubLang != "-" && s.HardsubLang == options.Hslang).ToList();
} else{ } else{
Console.WriteLine($"Selected stream with {Languages.Locale2language(options.Hslang).Language} hardsubs not available"); Console.Error.WriteLine($"Selected stream with {Languages.Locale2language(options.Hslang).Language} hardsubs not available");
if (hsLangs.Count > 0){ if (hsLangs.Count > 0){
Console.WriteLine("Try hardsubs stream: " + string.Join(", ", hsLangs)); Console.Error.WriteLine("Try hardsubs stream: " + string.Join(", ", hsLangs));
} }
dlFailed = true; dlFailed = true;
return new DownloadResponse{
Data = new List<DownloadedMedia>(),
Error = dlFailed,
FileName = "./unknown",
ErrorText = "Hardsubs not available"
};
} }
} else{ } else{
streams = streams.Where((s) => { streams = streams.Where((s) => {
@ -659,9 +667,9 @@ public class CrunchyrollManager{
}).ToList(); }).ToList();
if (streams.Count < 1){ if (streams.Count < 1){
Console.WriteLine("Raw streams not available!"); Console.Error.WriteLine("Raw streams not available!");
if (hsLangs.Count > 0){ if (hsLangs.Count > 0){
Console.WriteLine("Try hardsubs stream: " + string.Join(", ", hsLangs)); Console.Error.WriteLine("Try hardsubs stream: " + string.Join(", ", hsLangs));
} }
dlFailed = true; dlFailed = true;
@ -776,7 +784,7 @@ public class CrunchyrollManager{
} }
if (chosenVideoQuality > videos.Count){ if (chosenVideoQuality > videos.Count){
Console.WriteLine($"The requested quality of {chosenVideoQuality} is greater than the maximum {videos.Count}.\n[WARN] Therefore, the maximum will be capped at {videos.Count}."); Console.Error.WriteLine($"The requested quality of {chosenVideoQuality} is greater than the maximum {videos.Count}.\n[WARN] Therefore, the maximum will be capped at {videos.Count}.");
chosenVideoQuality = videos.Count; chosenVideoQuality = videos.Count;
} }

View File

@ -18,6 +18,7 @@ using CRD.Utils;
using CRD.Utils.Structs; using CRD.Utils.Structs;
using CRD.Views; using CRD.Views;
using DynamicData; using DynamicData;
using FluentAvalonia.Core;
using ReactiveUI; using ReactiveUI;
@ -25,31 +26,37 @@ namespace CRD.ViewModels;
public partial class AddDownloadPageViewModel : ViewModelBase{ public partial class AddDownloadPageViewModel : ViewModelBase{
[ObservableProperty] [ObservableProperty]
public string _urlInput = ""; private string _urlInput = "";
[ObservableProperty] [ObservableProperty]
public string _buttonText = "Enter Url"; private string _buttonText = "Enter Url";
[ObservableProperty] [ObservableProperty]
public bool _addAllEpisodes = false; private string _buttonTextSelectSeason = "Select Season";
[ObservableProperty] [ObservableProperty]
public bool _buttonEnabled = false; private bool _addAllEpisodes = false;
[ObservableProperty] [ObservableProperty]
public bool _allButtonEnabled = false; private bool _buttonEnabled = false;
[ObservableProperty] [ObservableProperty]
public bool _showLoading = false; private bool _allButtonEnabled = false;
[ObservableProperty] [ObservableProperty]
public bool _searchEnabled = false; private bool _showLoading = false;
[ObservableProperty] [ObservableProperty]
public bool _searchVisible = true; private bool _searchEnabled = false;
[ObservableProperty] [ObservableProperty]
public bool _searchPopupVisible = false; private bool _searchVisible = true;
[ObservableProperty]
private bool _slectSeasonVisible = false;
[ObservableProperty]
private bool _searchPopupVisible = false;
public ObservableCollection<ItemModel> Items{ get; } = new(); public ObservableCollection<ItemModel> Items{ get; } = new();
public ObservableCollection<CrBrowseSeries> SearchItems{ get; set; } = new(); public ObservableCollection<CrBrowseSeries> SearchItems{ get; set; } = new();
@ -69,6 +76,8 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
private CrunchySeriesList? currentSeriesList; private CrunchySeriesList? currentSeriesList;
private bool CurrentSeasonFullySelected = false;
private readonly SemaphoreSlim _updateSearchSemaphore = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _updateSearchSemaphore = new SemaphoreSlim(1, 1);
public AddDownloadPageViewModel(){ public AddDownloadPageViewModel(){
@ -93,6 +102,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
SearchItems.Add(episode); SearchItems.Add(episode);
} }
SearchPopupVisible = true; SearchPopupVisible = true;
RaisePropertyChanged(nameof(SearchItems)); RaisePropertyChanged(nameof(SearchItems));
RaisePropertyChanged(nameof(SearchVisible)); RaisePropertyChanged(nameof(SearchVisible));
@ -117,19 +127,23 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
ButtonText = "Add Episode to Queue"; ButtonText = "Add Episode to Queue";
ButtonEnabled = true; ButtonEnabled = true;
SearchVisible = false; SearchVisible = false;
SlectSeasonVisible = false;
} else if (UrlInput.Contains("/series/")){ } else if (UrlInput.Contains("/series/")){
//Series //Series
ButtonText = "List Episodes"; ButtonText = "List Episodes";
ButtonEnabled = true; ButtonEnabled = true;
SearchVisible = false; SearchVisible = false;
SlectSeasonVisible = false;
} else{ } else{
ButtonEnabled = false; ButtonEnabled = false;
SearchVisible = true; SearchVisible = true;
SlectSeasonVisible = false;
} }
} else{ } else{
ButtonText = "Enter Url"; ButtonText = "Enter Url";
ButtonEnabled = false; ButtonEnabled = false;
SearchVisible = true; SearchVisible = true;
SlectSeasonVisible = false;
} }
} }
@ -173,6 +187,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
ButtonText = "Enter Url"; ButtonText = "Enter Url";
ButtonEnabled = false; ButtonEnabled = false;
SearchVisible = true; SearchVisible = true;
SlectSeasonVisible = false;
} else if (UrlInput.Length > 9){ } else if (UrlInput.Length > 9){
episodesBySeason.Clear(); episodesBySeason.Clear();
SeasonList.Clear(); SeasonList.Clear();
@ -233,6 +248,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
CurrentSelectedSeason = SeasonList[0]; CurrentSelectedSeason = SeasonList[0];
ButtonEnabled = false; ButtonEnabled = false;
AllButtonEnabled = true; AllButtonEnabled = true;
SlectSeasonVisible = true;
ButtonText = "Select Episodes"; ButtonText = "Select Episodes";
} else{ } else{
ButtonEnabled = true; ButtonEnabled = true;
@ -244,6 +260,28 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
} }
} }
[RelayCommand]
public void OnSelectSeasonPressed(){
if (CurrentSeasonFullySelected){
foreach (var item in Items){
selectedEpisodes.Remove(item.AbsolutNum);
SelectedItems.Remove(item);
}
ButtonTextSelectSeason = "Select Season";
} else{
var selectedItemsSet = new HashSet<ItemModel>(SelectedItems);
foreach (var item in Items){
if (selectedItemsSet.Add(item)){
SelectedItems.Add(item);
}
}
ButtonTextSelectSeason = "Deselect Season";
}
}
partial void OnCurrentSelectedSeasonChanging(ComboBoxItem? oldValue, ComboBoxItem newValue){ partial void OnCurrentSelectedSeasonChanging(ComboBoxItem? oldValue, ComboBoxItem newValue){
foreach (var selectedItem in SelectedItems){ foreach (var selectedItem in SelectedItems){
if (!selectedEpisodes.Contains(selectedItem.AbsolutNum)){ if (!selectedEpisodes.Contains(selectedItem.AbsolutNum)){
@ -261,6 +299,14 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
} }
private void OnSelectedItemsChanged(object? sender, NotifyCollectionChangedEventArgs e){ private void OnSelectedItemsChanged(object? sender, NotifyCollectionChangedEventArgs e){
CurrentSeasonFullySelected = Items.All(item => SelectedItems.Contains(item));
if (CurrentSeasonFullySelected){
ButtonTextSelectSeason = "Deselect Season";
} else{
ButtonTextSelectSeason = "Select Season";
}
if (selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes){ if (selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes){
ButtonText = "Add Episodes to Queue"; ButtonText = "Add Episodes to Queue";
ButtonEnabled = true; ButtonEnabled = true;
@ -289,6 +335,7 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
RaisePropertyChanged(nameof(SearchVisible)); RaisePropertyChanged(nameof(SearchVisible));
SearchItems.Clear(); SearchItems.Clear();
SearchVisible = false; SearchVisible = false;
SlectSeasonVisible = true;
ButtonEnabled = false; ButtonEnabled = false;
ShowLoading = true; ShowLoading = true;
var list = await CrunchyrollManager.Instance.CrSeries.ListSeriesId(value.Id, var list = await CrunchyrollManager.Instance.CrSeries.ListSeriesId(value.Id,
@ -341,6 +388,14 @@ public partial class AddDownloadPageViewModel : ViewModelBase{
} }
} }
} }
CurrentSeasonFullySelected = Items.All(item => SelectedItems.Contains(item));
if (CurrentSeasonFullySelected){
ButtonTextSelectSeason = "Deselect Season";
} else{
ButtonTextSelectSeason = "Select Season";
}
} }
} }

View File

@ -319,6 +319,27 @@ public partial class HistoryPageViewModel : ViewModelBase{
} }
} }
} }
[RelayCommand]
public async Task DownloadSeasonAll(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList){
await historyEpisode.DownloadEpisode();
}
}
[RelayCommand]
public async Task DownloadSeasonMissing(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList.Where(historyEpisode => !historyEpisode.WasDownloaded)){
await historyEpisode.DownloadEpisode();
}
}
[RelayCommand]
public async Task DownloadSeasonMissingSonarr(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList.Where(historyEpisode => !historyEpisode.SonarrHasFile)){
await historyEpisode.DownloadEpisode();
}
}
public void SetStorageProvider(IStorageProvider storageProvider){ public void SetStorageProvider(IStorageProvider storageProvider){

View File

@ -28,10 +28,6 @@ public partial class SeriesPageViewModel : ViewModelBase{
[ObservableProperty] [ObservableProperty]
public static bool _sonarrAvailable; public static bool _sonarrAvailable;
private IStorageProvider? _storageProvider; private IStorageProvider? _storageProvider;
public SeriesPageViewModel(){ public SeriesPageViewModel(){
@ -84,6 +80,27 @@ public partial class SeriesPageViewModel : ViewModelBase{
} }
[RelayCommand]
public async Task DownloadSeasonAll(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList){
await historyEpisode.DownloadEpisode();
}
}
[RelayCommand]
public async Task DownloadSeasonMissing(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList.Where(historyEpisode => !historyEpisode.WasDownloaded)){
await historyEpisode.DownloadEpisode();
}
}
[RelayCommand]
public async Task DownloadSeasonMissingSonarr(HistorySeason season){
foreach (var historyEpisode in season.EpisodesList.Where(historyEpisode => !historyEpisode.SonarrHasFile)){
await historyEpisode.DownloadEpisode();
}
}
[RelayCommand] [RelayCommand]
public async Task UpdateData(string? season){ public async Task UpdateData(string? season){
await SelectedSeries.FetchData(season); await SelectedSeries.FetchData(season);

View File

@ -115,6 +115,10 @@
<CheckBox IsEnabled="{Binding AllButtonEnabled}" IsChecked="{Binding AddAllEpisodes}" <CheckBox IsEnabled="{Binding AllButtonEnabled}" IsChecked="{Binding AddAllEpisodes}"
Content="All" Margin="5 0 0 0"> Content="All" Margin="5 0 0 0">
</CheckBox> </CheckBox>
<Button IsVisible="{Binding SlectSeasonVisible}" IsEnabled="{Binding !ShowLoading}" Width="200" Command="{Binding OnSelectSeasonPressed}"
Content="{Binding ButtonTextSelectSeason}">
</Button>
<CheckBox IsVisible="{Binding SearchVisible}" IsChecked="{Binding SearchEnabled}" <CheckBox IsVisible="{Binding SearchVisible}" IsChecked="{Binding SearchEnabled}"
Content="Search" Margin="5 0 0 0"> Content="Search" Margin="5 0 0 0">

View File

@ -237,14 +237,13 @@
<ScrollViewer> <ScrollViewer>
<ItemsControl ItemsSource="{Binding Items}" <ItemsControl ItemsSource="{Binding Items}"
IsEnabled="{Binding !FetchingData}" IsEnabled="{Binding !FetchingData}"
Margin="5" IsVisible="{Binding IsTableViewSelected}"> Margin="5" IsVisible="{Binding IsTableViewSelected}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
<controls:SettingsExpander <controls:SettingsExpander
x:Name="SettingsExpanderSeries"
Header="{Binding .}" Header="{Binding .}"
ItemsSource="{Binding .}" ItemsSource="{Binding .}"
IsExpanded="{Binding IsExpanded}"> IsExpanded="{Binding IsExpanded}">
@ -516,8 +515,7 @@
<StackPanel VerticalAlignment="Center" <StackPanel VerticalAlignment="Center"
Margin="0 0 5 0" Margin="0 0 5 0"
IsVisible="{Binding $parent[ItemsControl].((vm:SeriesPageViewModel)DataContext).SonarrAvailable}"> IsVisible="{Binding $parent[ScrollViewer].((history:HistorySeries)DataContext).SonarrSeriesId, Converter={StaticResource UiSonarrIdToVisibilityConverter}}">
<controls:ImageIcon <controls:ImageIcon
IsVisible="{Binding SonarrHasFile}" IsVisible="{Binding SonarrHasFile}"
@ -598,6 +596,51 @@
</StackPanel> </StackPanel>
</Button> </Button>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<ToggleButton x:Name="ToggleDownloadAdd" Margin="10 0 0 0" FontStyle="Italic"
VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="Download" FontSize="18" />
</StackPanel>
</ToggleButton>
<Popup IsLightDismissEnabled="True"
MaxWidth="400"
MaxHeight="600"
IsOpen="{Binding IsChecked, ElementName=ToggleDownloadAdd, Mode=TwoWay}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=ToggleDownloadAdd}">
<Border BorderThickness="1" Background="{DynamicResource ComboBoxDropDownBackground}">
<StackPanel>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download All"
Command="{Binding $parent[UserControl].((vm:HistoryPageViewModel)DataContext).DownloadSeasonAll}"
CommandParameter="{Binding }">
</Button>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download Missing"
Command="{Binding $parent[UserControl].((vm:HistoryPageViewModel)DataContext).DownloadSeasonMissing}"
CommandParameter="{Binding }">
</Button>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download Missing from Sonarr"
IsEnabled="{Binding $parent[ScrollViewer].((history:HistorySeries)DataContext).SonarrSeriesId, Converter={StaticResource UiSonarrIdToVisibilityConverter}}"
Command="{Binding $parent[UserControl].((vm:HistoryPageViewModel)DataContext).DownloadSeasonMissingSonarr}"
CommandParameter="{Binding }">
</Button>
</StackPanel>
</Border>
</Popup>
</StackPanel>
<Button Margin="10 0 0 0" FontStyle="Italic" <Button Margin="10 0 0 0" FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"
Command="{Binding $parent[UserControl].((vm:HistoryPageViewModel)DataContext).OpenFolderDialogAsyncSeason}" Command="{Binding $parent[UserControl].((vm:HistoryPageViewModel)DataContext).OpenFolderDialogAsyncSeason}"

View File

@ -232,7 +232,7 @@
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center"> <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel VerticalAlignment="Center" Margin="0 0 5 0" <StackPanel VerticalAlignment="Center" Margin="0 0 5 0"
IsVisible="{Binding $parent[ItemsControl].((vm:SeriesPageViewModel)DataContext).SonarrAvailable}"> IsVisible="{Binding $parent[UserControl].((vm:SeriesPageViewModel)DataContext).SonarrAvailable}">
<controls:ImageIcon IsVisible="{Binding SonarrHasFile}" <controls:ImageIcon IsVisible="{Binding SonarrHasFile}"
@ -297,6 +297,51 @@
<controls:SymbolIcon Symbol="Refresh" FontSize="18" /> <controls:SymbolIcon Symbol="Refresh" FontSize="18" />
</StackPanel> </StackPanel>
</Button> </Button>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<ToggleButton x:Name="ToggleDownloadAdd" Margin="10 0 0 0" FontStyle="Italic"
VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="Download" FontSize="18" />
</StackPanel>
</ToggleButton>
<Popup IsLightDismissEnabled="True"
MaxWidth="400"
MaxHeight="600"
IsOpen="{Binding IsChecked, ElementName=ToggleDownloadAdd, Mode=TwoWay}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=ToggleDownloadAdd}">
<Border BorderThickness="1" Background="{DynamicResource ComboBoxDropDownBackground}">
<StackPanel>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download All"
Command="{Binding $parent[UserControl].((vm:SeriesPageViewModel)DataContext).DownloadSeasonAll}"
CommandParameter="{Binding }">
</Button>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download Missing"
Command="{Binding $parent[UserControl].((vm:SeriesPageViewModel)DataContext).DownloadSeasonMissing}"
CommandParameter="{Binding }">
</Button>
<Button Margin="10 5"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Content="Download Missing from Sonarr"
IsEnabled="{Binding $parent[UserControl].((vm:SeriesPageViewModel)DataContext).SonarrAvailable}"
Command="{Binding $parent[UserControl].((vm:SeriesPageViewModel)DataContext).DownloadSeasonMissingSonarr}"
CommandParameter="{Binding }">
</Button>
</StackPanel>
</Border>
</Popup>
</StackPanel>
<Button Margin="10 0 0 0" FontStyle="Italic" <Button Margin="10 0 0 0" FontStyle="Italic"
VerticalAlignment="Center" VerticalAlignment="Center"