Add - Added "Remove Finished" to download queue

Fix - Fixed a crash when muxing title wasn't set
This commit is contained in:
Elwador 2024-06-24 22:29:13 +02:00
parent 29aac7ed8f
commit 89c7b1021f
4 changed files with 61 additions and 45 deletions

View File

@ -44,7 +44,6 @@ public class Crunchyroll{
public RefreshableObservableCollection<CrunchyEpMeta> Queue = new RefreshableObservableCollection<CrunchyEpMeta>();
public ObservableCollection<DownloadItemModel> DownloadItemModels = new ObservableCollection<DownloadItemModel>();
public int ActiveDownloads;
public bool AutoDownload = false;
#endregion
@ -103,6 +102,10 @@ public class Crunchyroll{
#endregion
public Crunchyroll(){
CrunOptions = new CrDownloadOptions();
}
public async Task Init(){
_widevine = Widevine.Instance;
@ -129,8 +132,8 @@ public class Crunchyroll{
Console.WriteLine($"Can Decrypt: {_widevine.canDecrypt}");
CrunOptions = new CrDownloadOptions();
CrunOptions.AutoDownload = false;
CrunOptions.RemoveFinishedDownload = false;
CrunOptions.Chapters = true;
CrunOptions.Hslang = "none";
CrunOptions.Force = "Y";
@ -441,6 +444,10 @@ public class Crunchyroll{
Doing = "Done"
};
if (CrunOptions.RemoveFinishedDownload){
Queue.Remove(data);
}
Queue.Refresh();
} else{
Console.WriteLine("Skipping mux");
@ -1384,7 +1391,7 @@ public class Crunchyroll{
Error = dlFailed,
FileName = fileName.Length > 0 ? (Path.IsPathRooted(fileName) ? fileName : Path.Combine(fileDir, fileName)) : "./unknown",
ErrorText = "",
VideoTitle = FileNameManager.ParseFileName(options.VideoTitle, variables, options.Numbers, options.Override).Last()
VideoTitle = FileNameManager.ParseFileName(options.VideoTitle ?? "", variables, options.Numbers, options.Override).Last()
};
}

View File

@ -5,6 +5,15 @@ using YamlDotNet.Serialization;
namespace CRD.Utils.Structs;
public class CrDownloadOptions{
[YamlIgnore]
public bool AutoDownload{ get; set; }
[YamlIgnore]
public bool RemoveFinishedDownload{ get; set; }
[YamlMember(Alias = "hard_sub_lang", ApplyNamingConventions = false)]
public string Hslang{ get; set; }

View File

@ -18,18 +18,19 @@ using CRD.Utils.Structs;
namespace CRD.ViewModels;
public partial class DownloadsPageViewModel : ViewModelBase{
public ObservableCollection<DownloadItemModel> Items{ get; }
[ObservableProperty] public bool _autoDownload;
[ObservableProperty]
public bool _autoDownload;
private SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
[ObservableProperty]
public bool _removeFinished;
public DownloadsPageViewModel(){
UpdateListItems();
Items = Crunchyroll.Instance.DownloadItemModels;
AutoDownload = Crunchyroll.Instance.AutoDownload;
AutoDownload = Crunchyroll.Instance.CrunOptions.AutoDownload;
RemoveFinished = Crunchyroll.Instance.CrunOptions.RemoveFinishedDownload;
Crunchyroll.Instance.Queue.CollectionChanged += UpdateItemListOnRemove;
// Items.Add(new DownloadItemModel{Title = "Test - S1E1"});
}
@ -64,19 +65,23 @@ public partial class DownloadsPageViewModel : ViewModelBase{
Crunchyroll.Instance.DownloadItemModels.Add(downloadItem);
}
if (downloadItem is{ isDownloading: false, Error: false } && Crunchyroll.Instance.AutoDownload && Crunchyroll.Instance.ActiveDownloads < Crunchyroll.Instance.CrunOptions.SimultaneousDownloads){
if (downloadItem is{ isDownloading: false, Error: false } && Crunchyroll.Instance.CrunOptions.AutoDownload && Crunchyroll.Instance.ActiveDownloads < Crunchyroll.Instance.CrunOptions.SimultaneousDownloads){
downloadItem.StartDownload();
}
}
}
partial void OnAutoDownloadChanged(bool value){
Crunchyroll.Instance.AutoDownload = value;
Crunchyroll.Instance.CrunOptions.AutoDownload = value;
if (value){
UpdateListItems();
}
}
partial void OnRemoveFinishedChanged(bool value){
Crunchyroll.Instance.CrunOptions.RemoveFinishedDownload = value;
}
public void Cleanup(){
Crunchyroll.Instance.Queue.CollectionChanged -= UpdateItemListOnRemove;
}
@ -190,20 +195,16 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
}
public event PropertyChangedEventHandler? PropertyChanged;
[RelayCommand]
public void ToggleIsDownloading(){
if (isDownloading){
//StopDownload();
epMeta.Paused = !epMeta.Paused;
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
} else{
if (epMeta.Paused){
epMeta.Paused = false;
@ -218,7 +219,6 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
if (PropertyChanged != null){
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("isDownloading"));
}
}
public async void StartDownload(){
@ -229,7 +229,6 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
await Crunchyroll.Instance.DownloadEpisode(epMeta, Crunchyroll.Instance.CrunOptions);
}
}
[RelayCommand]

View File

@ -21,8 +21,9 @@
<RowDefinition Height="*" /> <!-- For the ListBox to take remaining space -->
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right">
<!-- <Button Click="Button_OnClick">Test Download</Button> -->
<ToggleSwitch HorizontalAlignment="Right" Margin="0 0 10 0 " IsChecked="{Binding RemoveFinished}" OffContent="Remove Finished" OnContent="Remove Finished"></ToggleSwitch>
<ToggleSwitch HorizontalAlignment="Right" Margin="0 0 10 0 " IsChecked="{Binding AutoDownload}" OffContent="Auto Download" OnContent="Auto Download"></ToggleSwitch>
</StackPanel>