mirror of
https://github.com/Crunchy-DL/Crunchy-Downloader.git
synced 2026-01-11 20:10:26 +00:00
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
190 lines
No EOL
7.2 KiB
C#
190 lines
No EOL
7.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Avalonia.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CRD.Utils;
|
|
using CRD.Utils.Ffmpeg_Encoding;
|
|
using CRD.Utils.Structs;
|
|
using CRD.Views;
|
|
using DynamicData;
|
|
using FluentAvalonia.UI.Controls;
|
|
using ReactiveUI;
|
|
|
|
namespace CRD.ViewModels.Utils;
|
|
|
|
public partial class ContentDialogEncodingPresetViewModel : ViewModelBase{
|
|
private readonly ContentDialog dialog;
|
|
|
|
[ObservableProperty]
|
|
private bool _editMode;
|
|
|
|
[ObservableProperty]
|
|
private string _presetName;
|
|
|
|
[ObservableProperty]
|
|
private string _codec;
|
|
|
|
[ObservableProperty]
|
|
private ComboBoxItem _selectedResolution = new();
|
|
|
|
[ObservableProperty]
|
|
private double? _crf = 23;
|
|
|
|
[ObservableProperty]
|
|
private double? _frameRate = 30;
|
|
|
|
[ObservableProperty]
|
|
private string _additionalParametersString = "";
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<StringItem> _additionalParameters = new();
|
|
|
|
[ObservableProperty]
|
|
private VideoPreset? _selectedCustomPreset;
|
|
|
|
[ObservableProperty]
|
|
private bool _fileExists;
|
|
|
|
public ObservableCollection<VideoPreset> CustomPresetsList{ get; } = new(){ };
|
|
|
|
public ObservableCollection<ComboBoxItem> ResolutionList{ get; } = new(){
|
|
new ComboBoxItem(){ Content = "3840:2160" }, // 4K UHD
|
|
new ComboBoxItem(){ Content = "3440:1440" }, // Ultra-Wide Quad HD
|
|
new ComboBoxItem(){ Content = "2560:1440" }, // 1440p
|
|
new ComboBoxItem(){ Content = "2560:1080" }, // Ultra-Wide Full HD
|
|
new ComboBoxItem(){ Content = "2160:1080" }, // 2:1 Aspect Ratio
|
|
new ComboBoxItem(){ Content = "1920:1080" }, // 1080p Full HD
|
|
new ComboBoxItem(){ Content = "1920:800" }, // Cinematic 2.40:1
|
|
new ComboBoxItem(){ Content = "1600:900" }, // 900p
|
|
new ComboBoxItem(){ Content = "1366:768" }, // 768p
|
|
new ComboBoxItem(){ Content = "1280:960" }, // SXGA 4:3
|
|
new ComboBoxItem(){ Content = "1280:720" }, // 720p HD
|
|
new ComboBoxItem(){ Content = "1024:576" }, // 576p
|
|
new ComboBoxItem(){ Content = "960:540" }, // 540p qHD
|
|
new ComboBoxItem(){ Content = "854:480" }, // 480p
|
|
new ComboBoxItem(){ Content = "800:600" }, // SVGA
|
|
new ComboBoxItem(){ Content = "768:432" }, // 432p
|
|
new ComboBoxItem(){ Content = "720:480" }, // NTSC SD
|
|
new ComboBoxItem(){ Content = "704:576" }, // PAL SD
|
|
new ComboBoxItem(){ Content = "640:360" }, // 360p
|
|
new ComboBoxItem(){ Content = "426:240" }, // 240p
|
|
new ComboBoxItem(){ Content = "320:240" }, // QVGA
|
|
new ComboBoxItem(){ Content = "320:180" }, // 180p
|
|
new ComboBoxItem(){ Content = "256:144" }, // 144p
|
|
};
|
|
|
|
public ContentDialogEncodingPresetViewModel(ContentDialog dialog, bool editMode){
|
|
this.dialog = dialog;
|
|
|
|
if (dialog is null){
|
|
throw new ArgumentNullException(nameof(dialog));
|
|
}
|
|
|
|
if (editMode){
|
|
EditMode = true;
|
|
CustomPresetsList.AddRange(FfmpegEncoding.presets.Skip(15));
|
|
|
|
this.dialog.Title = "Edit Encoding Preset";
|
|
|
|
if (CustomPresetsList.Count == 0){
|
|
MessageBus.Current.SendMessage(new ToastMessage($"There are no presets to be edited", ToastType.Warning, 5));
|
|
EditMode = false;
|
|
} else{
|
|
SelectedCustomPreset = CustomPresetsList.First();
|
|
}
|
|
}
|
|
|
|
|
|
dialog.Closed += DialogOnClosed;
|
|
dialog.PrimaryButtonClick += SaveButton;
|
|
}
|
|
|
|
partial void OnSelectedCustomPresetChanged(VideoPreset value){
|
|
PresetName = value.PresetName ?? "";
|
|
Codec = value.Codec ?? "";
|
|
Crf = value.Crf;
|
|
FrameRate = double.Parse(value.FrameRate ?? "0");
|
|
|
|
SelectedResolution = ResolutionList.FirstOrDefault(e => e.Content?.ToString() == value.Resolution) ?? ResolutionList.First();
|
|
AdditionalParameters.Clear();
|
|
|
|
foreach (var valueAdditionalParameter in value.AdditionalParameters){
|
|
AdditionalParameters.Add(new StringItem(){ stringValue = valueAdditionalParameter });
|
|
}
|
|
|
|
AdditionalParametersString = "";
|
|
}
|
|
|
|
partial void OnPresetNameChanged(string value){
|
|
var path = Path.Combine(CfgManager.PathENCODING_PRESETS_DIR, value + ".json");
|
|
var fileExists = File.Exists(path);
|
|
|
|
dialog.IsPrimaryButtonEnabled = !fileExists || EditMode && value == SelectedCustomPreset?.PresetName;
|
|
|
|
FileExists = !dialog.IsPrimaryButtonEnabled;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddAdditionalParam(){
|
|
AdditionalParameters.Add(new StringItem(){ stringValue = AdditionalParametersString });
|
|
AdditionalParametersString = "";
|
|
RaisePropertyChanged(nameof(AdditionalParametersString));
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void RemoveAdditionalParam(StringItem param){
|
|
AdditionalParameters.Remove(param);
|
|
RaisePropertyChanged(nameof(AdditionalParameters));
|
|
}
|
|
|
|
private void SaveButton(ContentDialog sender, ContentDialogButtonClickEventArgs args){
|
|
dialog.PrimaryButtonClick -= SaveButton;
|
|
|
|
if (EditMode){
|
|
if (SelectedCustomPreset != null){
|
|
var oldName = SelectedCustomPreset.PresetName;
|
|
|
|
SelectedCustomPreset.PresetName = PresetName;
|
|
SelectedCustomPreset.Codec = Codec;
|
|
SelectedCustomPreset.FrameRate = Math.Clamp((int)(FrameRate ?? 1), 1, 999).ToString();
|
|
SelectedCustomPreset.Crf = Math.Clamp((int)(Crf ?? 0), 0, 51);
|
|
SelectedCustomPreset.Resolution = SelectedResolution.Content?.ToString() ?? "1920:1080";
|
|
SelectedCustomPreset.AdditionalParameters = AdditionalParameters.Select(additionalParameter => additionalParameter.stringValue).ToList();
|
|
|
|
try{
|
|
var oldPath = Path.Combine(CfgManager.PathENCODING_PRESETS_DIR, oldName + ".json");
|
|
var path = Path.Combine(CfgManager.PathENCODING_PRESETS_DIR, SelectedCustomPreset.PresetName + ".json");
|
|
|
|
if (File.Exists(oldPath)){
|
|
File.Delete(oldPath);
|
|
}
|
|
|
|
CfgManager.WriteJsonToFile(path, SelectedCustomPreset);
|
|
} catch (Exception e){
|
|
Console.Error.WriteLine("Error saving preset: " + e);
|
|
}
|
|
}
|
|
} else{
|
|
VideoPreset newPreset = new VideoPreset(){
|
|
PresetName = PresetName,
|
|
Codec = Codec,
|
|
FrameRate = Math.Clamp((int)(FrameRate ?? 1), 1, 999).ToString(),
|
|
Crf = Math.Clamp((int)(Crf ?? 0), 0, 51),
|
|
Resolution = SelectedResolution.Content?.ToString() ?? "1920:1080",
|
|
AdditionalParameters = AdditionalParameters.Select(additionalParameter => additionalParameter.stringValue).ToList()
|
|
};
|
|
|
|
CfgManager.WriteJsonToFile(Path.Combine(CfgManager.PathENCODING_PRESETS_DIR, newPreset.PresetName + ".json"), newPreset);
|
|
|
|
FfmpegEncoding.AddPreset(newPreset);
|
|
}
|
|
}
|
|
|
|
private void DialogOnClosed(ContentDialog sender, ContentDialogClosedEventArgs args){
|
|
dialog.Closed -= DialogOnClosed;
|
|
}
|
|
} |