From 55d04877f60d3ded537578832d9a518ea7b5ac78 Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Fri, 19 Sep 2025 14:05:41 -0400 Subject: [PATCH 1/2] feat: add additional download formats Formats are specified by the yt-dlp documentation: https://github.com/yt-dlp/yt-dlp#preset-aliases --- PantherByte/PantherByte.csproj | 8 ++ PantherByte/ViewModels/MainWindowViewModel.cs | 51 +++++++----- PantherByte/Views/MainWindow.axaml | 78 +++++++++---------- 3 files changed, 75 insertions(+), 62 deletions(-) diff --git a/PantherByte/PantherByte.csproj b/PantherByte/PantherByte.csproj index 5ead698..df443df 100644 --- a/PantherByte/PantherByte.csproj +++ b/PantherByte/PantherByte.csproj @@ -6,6 +6,14 @@ true app.manifest true + 0.1.0 + PantherByte + Region 15 Schools + https://github.com/R15-Software-Dev/PantherByte + https://github.com/R15-Software-Dev/PantherByte + Region 15 Schools + 0.0.1.0 + 0.0.1.0 diff --git a/PantherByte/ViewModels/MainWindowViewModel.cs b/PantherByte/ViewModels/MainWindowViewModel.cs index 42f1d08..7ade52c 100644 --- a/PantherByte/ViewModels/MainWindowViewModel.cs +++ b/PantherByte/ViewModels/MainWindowViewModel.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using CommunityToolkit.Mvvm.Input; using System.Threading.Tasks; +using Avalonia.Controls; using CommunityToolkit.Mvvm.Messaging; using DynamicData; using PantherByte.Messages; @@ -18,7 +20,7 @@ public partial class MainWindowViewModel : ViewModelBase { private string _link = string.Empty; private string _saveLocation = string.Empty; private string _format = "mp3"; - private bool _isDownloading = false; + private ObservableCollection _availableFormats = ["mp3", "mp4", "wav", "aac", "mkv"]; private bool _canDownload = true; /// @@ -37,24 +39,20 @@ public partial class MainWindowViewModel : ViewModelBase { get => _format; set => this.RaiseAndSetIfChanged(ref _format, value); } + + public ObservableCollection AvailableFormats { + get => _availableFormats; + set => this.RaiseAndSetIfChanged(ref _availableFormats, value); + } /// /// The folder to save the files in. This will become the argument passed to the "-P" argument in - /// . + /// . /// public string SaveLocation { get => _saveLocation; set => this.RaiseAndSetIfChanged(ref _saveLocation, value); } - - /// - /// Indicates if the command is currently running. When the command is running, the application - /// should disable all inputs and/or open a blocking modal window. - /// - public bool IsDownloading { - get => _isDownloading; - set => this.RaiseAndSetIfChanged(ref _isDownloading, value); - } /// /// Indicates if the file can be downloaded. If not, the download button is disabled. @@ -116,7 +114,7 @@ public partial class MainWindowViewModel : ViewModelBase { Console.WriteLine(ex.ToString()); } } - + /// /// Generates the arguments used for the main command string. /// @@ -126,16 +124,27 @@ public partial class MainWindowViewModel : ViewModelBase { // yt-dlp requires usage of ffmpeg as well. // Code will be executed when the button is clicked. - var fileName = ""; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - Console.WriteLine("Using Windows program."); - fileName = "Programs/yt-dlp-win64.exe"; - } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - Console.WriteLine("Using Linux program. May require additional run permissions."); - fileName = "Programs/yt-dlp-linux"; - } + return await Task.Run(() => { + var fileName = ""; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + Console.WriteLine("Using Windows program."); + fileName = "Programs/yt-dlp-win64.exe"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + Console.WriteLine("Using Linux program. May require additional run permissions."); + fileName = "Programs/yt-dlp-linux"; + } - return await Task.Run(() => new List([fileName, Link, "-t", Format, "-P", SaveLocation, "--no-playlist"])); + List args = [fileName, Link, "-P", SaveLocation, "--no-playlist"]; + + // WAV files require special command arguments + if (Format.Equals("wav")) { + args.AddRange(["--extract-audio", "--audio-format", Format]); + } else { + args.AddRange(["-t", Format]); + } + + return args; + }); } /// diff --git a/PantherByte/Views/MainWindow.axaml b/PantherByte/Views/MainWindow.axaml index 37ecb99..7217a99 100644 --- a/PantherByte/Views/MainWindow.axaml +++ b/PantherByte/Views/MainWindow.axaml @@ -33,52 +33,48 @@ - - - - - + + + + + - - -