feat: add additional download formats

Formats are specified by the yt-dlp documentation: https://github.com/yt-dlp/yt-dlp#preset-aliases
This commit is contained in:
alphafetus committed 2025-09-19 14:05:41 -04:00
1 parent 650948eb7b
commit 55d04877f6
3 files changed
+51 -38

No files matched your search

+8
View File
@@ -6,6 +6,14 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<Version>0.1.0</Version>
<Title>PantherByte</Title>
<Authors>Region 15 Schools</Authors>
<PackageProjectUrl>https://github.com/R15-Software-Dev/PantherByte</PackageProjectUrl>
<RepositoryUrl>https://github.com/R15-Software-Dev/PantherByte</RepositoryUrl>
<Company>Region 15 Schools</Company>
<AssemblyVersion>0.0.1.0</AssemblyVersion>
<FileVersion>0.0.1.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
+21 -12
View File
@@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
using DynamicData; using DynamicData;
using PantherByte.Messages; using PantherByte.Messages;
@@ -18,7 +20,7 @@ public partial class MainWindowViewModel : ViewModelBase {
private string _link = string.Empty; private string _link = string.Empty;
private string _saveLocation = string.Empty; private string _saveLocation = string.Empty;
private string _format = "mp3"; private string _format = "mp3";
private bool _isDownloading = false; private ObservableCollection<string> _availableFormats = ["mp3", "mp4", "wav", "aac", "mkv"];
private bool _canDownload = true; private bool _canDownload = true;
/// <summary> /// <summary>
@@ -38,24 +40,20 @@ public partial class MainWindowViewModel : ViewModelBase {
set => this.RaiseAndSetIfChanged(ref _format, value); set => this.RaiseAndSetIfChanged(ref _format, value);
} }
public ObservableCollection<string> AvailableFormats {
get => _availableFormats;
set => this.RaiseAndSetIfChanged(ref _availableFormats, value);
}
/// <summary> /// <summary>
/// The folder to save the files in. This will become the argument passed to the "-P" argument in /// The folder to save the files in. This will become the argument passed to the "-P" argument in
/// <see cref="GenerateCmdStringAsync"/>. /// <see cref="GenerateCmdArgsAsync"/>.
/// </summary> /// </summary>
public string SaveLocation { public string SaveLocation {
get => _saveLocation; get => _saveLocation;
set => this.RaiseAndSetIfChanged(ref _saveLocation, value); set => this.RaiseAndSetIfChanged(ref _saveLocation, value);
} }
/// <summary>
/// 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.
/// </summary>
public bool IsDownloading {
get => _isDownloading;
set => this.RaiseAndSetIfChanged(ref _isDownloading, value);
}
/// <summary> /// <summary>
/// Indicates if the file can be downloaded. If not, the download button is disabled. /// Indicates if the file can be downloaded. If not, the download button is disabled.
/// </summary> /// </summary>
@@ -126,6 +124,7 @@ public partial class MainWindowViewModel : ViewModelBase {
// yt-dlp requires usage of ffmpeg as well. // yt-dlp requires usage of ffmpeg as well.
// Code will be executed when the button is clicked. // Code will be executed when the button is clicked.
return await Task.Run(() => {
var fileName = ""; var fileName = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
Console.WriteLine("Using Windows program."); Console.WriteLine("Using Windows program.");
@@ -135,7 +134,17 @@ public partial class MainWindowViewModel : ViewModelBase {
fileName = "Programs/yt-dlp-linux"; fileName = "Programs/yt-dlp-linux";
} }
return await Task.Run(() => new List<string>([fileName, Link, "-t", Format, "-P", SaveLocation, "--no-playlist"])); List<string> 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;
});
} }
/// <summary> /// <summary>
+22 -26
View File
@@ -33,52 +33,48 @@
</ExperimentalAcrylicBorder.Material> </ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder> </ExperimentalAcrylicBorder>
<Grid <StackPanel Margin="20 35 20 20"
Margin="20 35 20 20"
ShowGridLines="False"
Width="500" Width="500"
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto" Spacing="10"
RowSpacing="10"> HorizontalAlignment="Stretch">
<TextBlock <TextBlock Text="Youtube Video Downloads"
Grid.Row="0"
Text="Youtube Video Downloads"
FontSize="30"/> FontSize="30"/>
<TextBlock <TextBlock Text="Enter your video link and save location."
Grid.Row="1"
Text="Enter your video link and save location."
FontSize="20"></TextBlock> FontSize="20"></TextBlock>
<Border Grid.Row="2" BorderBrush="White" BorderThickness="0,0,0,1"/> <Border BorderBrush="White" BorderThickness="0,0,0,1"/>
<StackPanel Grid.Row="3" Spacing="5"> <StackPanel Spacing="5">
<TextBlock Text="Save location:"/> <TextBlock Text="Save location:"/>
<Grid <Grid ColumnDefinitions="*, 30"
ColumnDefinitions="*, 30"
ColumnSpacing="5"> ColumnSpacing="5">
<TextBox <TextBox Grid.Column="0"
Grid.Column="0"
Text="{Binding SaveLocation}" Text="{Binding SaveLocation}"
Watermark="Choose a folder..."/> Watermark="Choose a folder..."/>
<Button <Button Grid.Column="1"
Grid.Column="1"
Content=">" Content=">"
HorizontalContentAlignment="Center" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
Command="{Binding GetSaveLocationCommand}"/> Command="{Binding GetSaveLocationCommand}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="4" Spacing="5"> <StackPanel Spacing="5">
<TextBlock Text="Video link:"/> <TextBlock Text="Video link:"/>
<TextBox <TextBox Text="{Binding Link}"
Text="{Binding Link}"
Watermark="Paste link here..."/> Watermark="Paste link here..."/>
</StackPanel> </StackPanel>
<Button <StackPanel Spacing="5"
Grid.Row="5" HorizontalAlignment="Stretch">
Content="Download" <TextBlock Text="Format:"/>
<ComboBox HorizontalAlignment="Stretch"
ItemsSource="{Binding AvailableFormats}"
SelectedItem="{Binding Format, Mode=TwoWay}">
</ComboBox>
</StackPanel>
<Button Content="Download"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
IsEnabled="{Binding CanDownload}" IsEnabled="{Binding CanDownload}"
Command="{Binding DownloadFileCommand}"/> Command="{Binding DownloadFileCommand}"/>
</Grid> </StackPanel>
</Panel> </Panel>
</Window> </Window>