Crunchy-Downloader/CRD/ViewModels/DownloadsPageViewModel.cs
Elwador 5d94025fcc Add - Added encoding option to muxing settings
Add - Added Custom encoding presets
Add - Added Skip Muxing to muxing settings
Add - Added Dubs to file name settings
Add - IP check in settings to check if VPN is being used
Add - Dubs to "Add Downloads" Tab
Add - Series folder link to history series if it finds the folder
Add - Added command line arguments
Add - Added proxy settings to the Settings tab (changes require a restart to take effect)
Add - Added option to set "Sign" subs forced flag
Add - Added option to set "CC" subs "hearing-impaired" flag
Add - Added encoding presets editing
Add - Added CC subtitles font option to the settings
Add - Added available dubs to history episodes

Chg - Defaults to system accent color when no color is selected in the settings
Chg - Audio only mux to only copy and not encode
Chg - Update dialog
Chg - Light mode color adjustments
Chg - Http Connection change to detect proxy (Clash)
Chg - Settings filename description
Chg - Changed FPS on encoding presets to 24fps
Chg - Adjusted encoding to allow h264_nvenc & hevc_nvenc
Chg - Moved sync timing folders from the Windows temp folder to the application root's temp folder
Chg - The temp folder will now be deleted automatically when empty

Fix - Locale not correctly applied to Urls in the "Add Downloads" Tab
Fix - Locale not correctly applied to Search in the "Add Downloads" Tab
Fix - Scrolling issue in settings
Fix - Fix crash when removing streaming tokens (TOO_MANY_ACTIVE_STREAMS)
Fix - Search didn't reset correctly
Fix - Clash proxy didn't work
Fix - Chapters were always taken from the original version (mainly JP)
Fix - Connection issue
Fix - Fixed an issue where proxy settings were only available when history was enabled
Fix - Fixed scrolling issues with certain series in the "Add Downloads" tab
Fix - Fixed an issue where History Series appeared incomplete after being added then deleted and re-added
Fix - Fixed a crash related to sync timing
2024-09-30 20:08:37 +02:00

202 lines
No EOL
7.6 KiB
C#

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CRD.Downloader;
using CRD.Downloader.Crunchyroll;
using CRD.Utils;
using CRD.Utils.Structs;
namespace CRD.ViewModels;
public partial class DownloadsPageViewModel : ViewModelBase{
public ObservableCollection<DownloadItemModel> Items{ get; }
[ObservableProperty]
private bool _autoDownload;
[ObservableProperty]
private bool _removeFinished;
public DownloadsPageViewModel(){
QueueManager.Instance.UpdateDownloadListItems();
Items = QueueManager.Instance.DownloadItemModels;
AutoDownload = CrunchyrollManager.Instance.CrunOptions.AutoDownload;
RemoveFinished = CrunchyrollManager.Instance.CrunOptions.RemoveFinishedDownload;
}
partial void OnAutoDownloadChanged(bool value){
CrunchyrollManager.Instance.CrunOptions.AutoDownload = value;
if (value){
QueueManager.Instance.UpdateDownloadListItems();
}
CfgManager.WriteSettingsToFile();
}
partial void OnRemoveFinishedChanged(bool value){
CrunchyrollManager.Instance.CrunOptions.RemoveFinishedDownload = value;
CfgManager.WriteSettingsToFile();
}
}
public partial class DownloadItemModel : INotifyPropertyChanged{
public string ImageUrl{ get; set; }
public Bitmap? ImageBitmap{ get; set; }
public string Title{ get; set; }
public bool isDownloading{ get; set; }
public bool Done{ get; set; }
public bool Paused{ get; set; }
public double Percent{ get; set; }
public string Time{ get; set; }
public string DoingWhat{ get; set; }
public string DownloadSpeed{ get; set; }
public string InfoText{ get; set; }
public CrunchyEpMeta epMeta{ get; set; }
public bool Error{ get; set; }
public DownloadItemModel(CrunchyEpMeta epMetaF){
epMeta = epMetaF;
ImageUrl = epMeta.Image;
Title = epMeta.SeriesTitle + (!string.IsNullOrEmpty(epMeta.Season) ? " - S" + epMeta.Season + "E" + (epMeta.EpisodeNumber != string.Empty ? epMeta.EpisodeNumber : epMeta.AbsolutEpisodeNumberE) : "") + " - " +
epMeta.EpisodeTitle;
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
Done = epMeta.DownloadProgress.Done;
Percent = epMeta.DownloadProgress.Percent;
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time).ToString(@"hh\:mm\:ss");
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
Error = epMeta.DownloadProgress.Error;
}
private string GetDubString(){
if (epMeta.SelectedDubs == null || epMeta.SelectedDubs.Count < 1){
return "";
}
return epMeta.SelectedDubs.Aggregate("Dub: ", (current, crunOptionsDlDub) => current + (crunOptionsDlDub + " "));
}
private string GetSubtitleString(){
var hardSubs = CrunchyrollManager.Instance.CrunOptions.Hslang != "none" ? "Hardsub: " : "";
if (hardSubs != string.Empty){
var locale = Languages.Locale2language(CrunchyrollManager.Instance.CrunOptions.Hslang).CrLocale;
if (epMeta.AvailableSubs != null && epMeta.AvailableSubs.Contains(locale)){
hardSubs += locale + " ";
}
return hardSubs;
}
if (epMeta.DownloadSubs.Count < 1){
return "";
}
var softSubs = "Softsub: ";
if (epMeta.DownloadSubs.Contains("all")){
if (epMeta.AvailableSubs != null){
return epMeta.AvailableSubs.Aggregate(softSubs, (current, epMetaAvailableSub) => current + (epMetaAvailableSub + " "));
}
}
foreach (var crunOptionsDlSub in epMeta.DownloadSubs){
if (epMeta.AvailableSubs != null && epMeta.AvailableSubs.Contains(crunOptionsDlSub)){
softSubs += crunOptionsDlSub + " ";
}
}
return softSubs;
}
public void Refresh(){
isDownloading = epMeta.DownloadProgress.IsDownloading || Done;
Done = epMeta.DownloadProgress.Done;
Percent = epMeta.DownloadProgress.Percent;
Time = "Estimated Time: " + TimeSpan.FromSeconds(epMeta.DownloadProgress.Time).ToString(@"hh\:mm\:ss");
DownloadSpeed = $"{epMeta.DownloadProgress.DownloadSpeed / 1000000.0:F2}Mb/s";
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
DoingWhat = epMeta.Paused ? "Paused" : Done ? "Done" : epMeta.DownloadProgress.Doing != string.Empty ? epMeta.DownloadProgress.Doing : "Waiting";
if (epMeta.Data != null) InfoText = GetDubString() + " - " + GetSubtitleString();
Error = epMeta.DownloadProgress.Error;
if (PropertyChanged != null){
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(isDownloading)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Percent)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Time)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DownloadSpeed)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DoingWhat)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Error)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InfoText)));
}
}
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;
Paused = epMeta.Paused || !isDownloading && !epMeta.Paused;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
} else{
StartDownload();
}
}
if (PropertyChanged != null){
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("isDownloading"));
}
}
public async void StartDownload(){
if (!isDownloading){
isDownloading = true;
epMeta.DownloadProgress.IsDownloading = true;
Paused = !epMeta.Paused && !isDownloading || epMeta.Paused;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Paused)));
await CrunchyrollManager.Instance.DownloadEpisode(epMeta, CrunchyrollManager.Instance.CrunOptions);
}
}
[RelayCommand]
public void RemoveFromQueue(){
CrunchyEpMeta? downloadItem = QueueManager.Instance.Queue.FirstOrDefault(e => e.Equals(epMeta)) ?? null;
if (downloadItem != null){
QueueManager.Instance.Queue.Remove(downloadItem);
}
}
public async Task LoadImage(){
ImageBitmap = await Helpers.LoadImage(ImageUrl, 208, 117);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImageBitmap)));
}
}