Add - Added "Remove Finished" to download queue
Fix - Fixed a crash when muxing title wasn't set
This commit is contained in:
parent
29aac7ed8f
commit
89c7b1021f
|
@ -44,7 +44,6 @@ public class Crunchyroll{
|
||||||
public RefreshableObservableCollection<CrunchyEpMeta> Queue = new RefreshableObservableCollection<CrunchyEpMeta>();
|
public RefreshableObservableCollection<CrunchyEpMeta> Queue = new RefreshableObservableCollection<CrunchyEpMeta>();
|
||||||
public ObservableCollection<DownloadItemModel> DownloadItemModels = new ObservableCollection<DownloadItemModel>();
|
public ObservableCollection<DownloadItemModel> DownloadItemModels = new ObservableCollection<DownloadItemModel>();
|
||||||
public int ActiveDownloads;
|
public int ActiveDownloads;
|
||||||
public bool AutoDownload = false;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -103,6 +102,10 @@ public class Crunchyroll{
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public Crunchyroll(){
|
||||||
|
CrunOptions = new CrDownloadOptions();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Init(){
|
public async Task Init(){
|
||||||
_widevine = Widevine.Instance;
|
_widevine = Widevine.Instance;
|
||||||
|
|
||||||
|
@ -129,8 +132,8 @@ public class Crunchyroll{
|
||||||
|
|
||||||
Console.WriteLine($"Can Decrypt: {_widevine.canDecrypt}");
|
Console.WriteLine($"Can Decrypt: {_widevine.canDecrypt}");
|
||||||
|
|
||||||
CrunOptions = new CrDownloadOptions();
|
CrunOptions.AutoDownload = false;
|
||||||
|
CrunOptions.RemoveFinishedDownload = false;
|
||||||
CrunOptions.Chapters = true;
|
CrunOptions.Chapters = true;
|
||||||
CrunOptions.Hslang = "none";
|
CrunOptions.Hslang = "none";
|
||||||
CrunOptions.Force = "Y";
|
CrunOptions.Force = "Y";
|
||||||
|
@ -441,6 +444,10 @@ public class Crunchyroll{
|
||||||
Doing = "Done"
|
Doing = "Done"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (CrunOptions.RemoveFinishedDownload){
|
||||||
|
Queue.Remove(data);
|
||||||
|
}
|
||||||
|
|
||||||
Queue.Refresh();
|
Queue.Refresh();
|
||||||
} else{
|
} else{
|
||||||
Console.WriteLine("Skipping mux");
|
Console.WriteLine("Skipping mux");
|
||||||
|
@ -1384,7 +1391,7 @@ public class Crunchyroll{
|
||||||
Error = dlFailed,
|
Error = dlFailed,
|
||||||
FileName = fileName.Length > 0 ? (Path.IsPathRooted(fileName) ? fileName : Path.Combine(fileDir, fileName)) : "./unknown",
|
FileName = fileName.Length > 0 ? (Path.IsPathRooted(fileName) ? fileName : Path.Combine(fileDir, fileName)) : "./unknown",
|
||||||
ErrorText = "",
|
ErrorText = "",
|
||||||
VideoTitle = FileNameManager.ParseFileName(options.VideoTitle, variables, options.Numbers, options.Override).Last()
|
VideoTitle = FileNameManager.ParseFileName(options.VideoTitle ?? "", variables, options.Numbers, options.Override).Last()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,15 @@ using YamlDotNet.Serialization;
|
||||||
namespace CRD.Utils.Structs;
|
namespace CRD.Utils.Structs;
|
||||||
|
|
||||||
public class CrDownloadOptions{
|
public class CrDownloadOptions{
|
||||||
|
|
||||||
|
[YamlIgnore]
|
||||||
|
public bool AutoDownload{ get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[YamlIgnore]
|
||||||
|
public bool RemoveFinishedDownload{ get; set; }
|
||||||
|
|
||||||
|
|
||||||
[YamlMember(Alias = "hard_sub_lang", ApplyNamingConventions = false)]
|
[YamlMember(Alias = "hard_sub_lang", ApplyNamingConventions = false)]
|
||||||
public string Hslang{ get; set; }
|
public string Hslang{ get; set; }
|
||||||
|
|
||||||
|
|
|
@ -18,18 +18,19 @@ using CRD.Utils.Structs;
|
||||||
namespace CRD.ViewModels;
|
namespace CRD.ViewModels;
|
||||||
|
|
||||||
public partial class DownloadsPageViewModel : ViewModelBase{
|
public partial class DownloadsPageViewModel : ViewModelBase{
|
||||||
|
|
||||||
|
|
||||||
public ObservableCollection<DownloadItemModel> Items{ get; }
|
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(){
|
public DownloadsPageViewModel(){
|
||||||
UpdateListItems();
|
UpdateListItems();
|
||||||
Items = Crunchyroll.Instance.DownloadItemModels;
|
Items = Crunchyroll.Instance.DownloadItemModels;
|
||||||
AutoDownload = Crunchyroll.Instance.AutoDownload;
|
AutoDownload = Crunchyroll.Instance.CrunOptions.AutoDownload;
|
||||||
|
RemoveFinished = Crunchyroll.Instance.CrunOptions.RemoveFinishedDownload;
|
||||||
Crunchyroll.Instance.Queue.CollectionChanged += UpdateItemListOnRemove;
|
Crunchyroll.Instance.Queue.CollectionChanged += UpdateItemListOnRemove;
|
||||||
// Items.Add(new DownloadItemModel{Title = "Test - S1E1"});
|
// Items.Add(new DownloadItemModel{Title = "Test - S1E1"});
|
||||||
}
|
}
|
||||||
|
@ -51,32 +52,36 @@ public partial class DownloadsPageViewModel : ViewModelBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateListItems(){
|
public void UpdateListItems(){
|
||||||
var list = Crunchyroll.Instance.Queue;
|
var list = Crunchyroll.Instance.Queue;
|
||||||
|
|
||||||
foreach (CrunchyEpMeta crunchyEpMeta in list){
|
foreach (CrunchyEpMeta crunchyEpMeta in list){
|
||||||
var downloadItem = Crunchyroll.Instance.DownloadItemModels.FirstOrDefault(e => e.epMeta.Equals(crunchyEpMeta));
|
var downloadItem = Crunchyroll.Instance.DownloadItemModels.FirstOrDefault(e => e.epMeta.Equals(crunchyEpMeta));
|
||||||
if (downloadItem != null){
|
if (downloadItem != null){
|
||||||
downloadItem.Refresh();
|
downloadItem.Refresh();
|
||||||
} else{
|
} else{
|
||||||
downloadItem = new DownloadItemModel(crunchyEpMeta);
|
downloadItem = new DownloadItemModel(crunchyEpMeta);
|
||||||
downloadItem.LoadImage();
|
downloadItem.LoadImage();
|
||||||
Crunchyroll.Instance.DownloadItemModels.Add(downloadItem);
|
Crunchyroll.Instance.DownloadItemModels.Add(downloadItem);
|
||||||
}
|
|
||||||
|
|
||||||
if (downloadItem is{ isDownloading: false, Error: false } && Crunchyroll.Instance.AutoDownload && Crunchyroll.Instance.ActiveDownloads < Crunchyroll.Instance.CrunOptions.SimultaneousDownloads){
|
|
||||||
downloadItem.StartDownload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
partial void OnAutoDownloadChanged(bool value){
|
||||||
Crunchyroll.Instance.AutoDownload = value;
|
Crunchyroll.Instance.CrunOptions.AutoDownload = value;
|
||||||
if (value){
|
if (value){
|
||||||
UpdateListItems();
|
UpdateListItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnRemoveFinishedChanged(bool value){
|
||||||
|
Crunchyroll.Instance.CrunOptions.RemoveFinishedDownload = value;
|
||||||
|
}
|
||||||
|
|
||||||
public void Cleanup(){
|
public void Cleanup(){
|
||||||
Crunchyroll.Instance.Queue.CollectionChanged -= UpdateItemListOnRemove;
|
Crunchyroll.Instance.Queue.CollectionChanged -= UpdateItemListOnRemove;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +104,7 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
|
|
||||||
public CrunchyEpMeta epMeta{ get; set; }
|
public CrunchyEpMeta epMeta{ get; set; }
|
||||||
|
|
||||||
|
|
||||||
public bool Error{ get; set; }
|
public bool Error{ get; set; }
|
||||||
|
|
||||||
public DownloadItemModel(CrunchyEpMeta epMetaF){
|
public DownloadItemModel(CrunchyEpMeta epMetaF){
|
||||||
|
@ -107,20 +112,20 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
|
|
||||||
ImageUrl = epMeta.Image;
|
ImageUrl = epMeta.Image;
|
||||||
Title = epMeta.SeriesTitle + " - S" + epMeta.Season + "E" + (epMeta.EpisodeNumber != string.Empty ? epMeta.EpisodeNumber : epMeta.AbsolutEpisodeNumberE) + " - " + epMeta.EpisodeTitle;
|
Title = epMeta.SeriesTitle + " - S" + epMeta.Season + "E" + (epMeta.EpisodeNumber != string.Empty ? epMeta.EpisodeNumber : epMeta.AbsolutEpisodeNumberE) + " - " + epMeta.EpisodeTitle;
|
||||||
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
|
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
|
||||||
|
|
||||||
Done = epMeta.DownloadProgress.Done;
|
Done = epMeta.DownloadProgress.Done;
|
||||||
Percent = epMeta.DownloadProgress.Percent;
|
Percent = epMeta.DownloadProgress.Percent;
|
||||||
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time / 1000).ToString(@"hh\:mm\:ss");
|
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time / 1000).ToString(@"hh\:mm\:ss");
|
||||||
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
|
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
|
||||||
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
||||||
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
|
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
|
||||||
|
|
||||||
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
|
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
|
||||||
|
|
||||||
Error = epMeta.DownloadProgress.Error;
|
Error = epMeta.DownloadProgress.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDubString(){
|
private string GetDubString(){
|
||||||
var hardSubs = Crunchyroll.Instance.CrunOptions.Hslang != "none" ? "Hardsub: " + Crunchyroll.Instance.CrunOptions.Hslang : "";
|
var hardSubs = Crunchyroll.Instance.CrunOptions.Hslang != "none" ? "Hardsub: " + Crunchyroll.Instance.CrunOptions.Hslang : "";
|
||||||
if (hardSubs != string.Empty){
|
if (hardSubs != string.Empty){
|
||||||
|
@ -153,7 +158,7 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
|
|
||||||
return softSubs;
|
return softSubs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var crunOptionsDlSub in Crunchyroll.Instance.CrunOptions.DlSubs){
|
foreach (var crunOptionsDlSub in Crunchyroll.Instance.CrunOptions.DlSubs){
|
||||||
if (epMeta.AvailableSubs != null && epMeta.AvailableSubs.Contains(crunOptionsDlSub)){
|
if (epMeta.AvailableSubs != null && epMeta.AvailableSubs.Contains(crunOptionsDlSub)){
|
||||||
|
@ -165,19 +170,19 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Refresh(){
|
public void Refresh(){
|
||||||
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
|
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
|
||||||
Done = epMeta.DownloadProgress.Done;
|
Done = epMeta.DownloadProgress.Done;
|
||||||
Percent = epMeta.DownloadProgress.Percent;
|
Percent = epMeta.DownloadProgress.Percent;
|
||||||
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time / 1000).ToString(@"hh\:mm\:ss");
|
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time / 1000).ToString(@"hh\:mm\:ss");
|
||||||
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
|
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
|
||||||
|
|
||||||
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
||||||
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
|
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
|
||||||
|
|
||||||
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
|
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
|
||||||
|
|
||||||
Error = epMeta.DownloadProgress.Error;
|
Error = epMeta.DownloadProgress.Error;
|
||||||
|
|
||||||
if (PropertyChanged != null){
|
if (PropertyChanged != null){
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(isDownloading)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(isDownloading)));
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Percent)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Percent)));
|
||||||
|
@ -188,22 +193,18 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InfoText)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InfoText)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public void ToggleIsDownloading(){
|
public void ToggleIsDownloading(){
|
||||||
|
|
||||||
if (isDownloading){
|
if (isDownloading){
|
||||||
//StopDownload();
|
//StopDownload();
|
||||||
epMeta.Paused = !epMeta.Paused;
|
epMeta.Paused = !epMeta.Paused;
|
||||||
|
|
||||||
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
if (epMeta.Paused){
|
if (epMeta.Paused){
|
||||||
epMeta.Paused = false;
|
epMeta.Paused = false;
|
||||||
|
@ -213,12 +214,11 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
StartDownload();
|
StartDownload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (PropertyChanged != null){
|
if (PropertyChanged != null){
|
||||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("isDownloading"));
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("isDownloading"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void StartDownload(){
|
public async void StartDownload(){
|
||||||
|
@ -229,7 +229,6 @@ public partial class DownloadItemModel : INotifyPropertyChanged{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
|
||||||
await Crunchyroll.Instance.DownloadEpisode(epMeta, Crunchyroll.Instance.CrunOptions);
|
await Crunchyroll.Instance.DownloadEpisode(epMeta, Crunchyroll.Instance.CrunOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
<RowDefinition Height="*" /> <!-- For the ListBox to take remaining space -->
|
<RowDefinition Height="*" /> <!-- For the ListBox to take remaining space -->
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<StackPanel Grid.Row="0">
|
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
<!-- <Button Click="Button_OnClick">Test Download</Button> -->
|
<!-- <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>
|
<ToggleSwitch HorizontalAlignment="Right" Margin="0 0 10 0 " IsChecked="{Binding AutoDownload}" OffContent="Auto Download" OnContent="Auto Download"></ToggleSwitch>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue