Implement new download format options #1

Merged
BobdaFett merged 2 commits from feature/format-options into master 2025-09-19 18:14:25 +00:00
3 changed files with 75 additions and 62 deletions
Showing only changes of commit 55d04877f6 - Show all commits

No files matched your search

+8
View File
@@ -6,6 +6,14 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<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>
<ItemGroup>
+30 -21
View File
@@ -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<string> _availableFormats = ["mp3", "mp4", "wav", "aac", "mkv"];
private bool _canDownload = true;
/// <summary>
@@ -37,24 +39,20 @@ public partial class MainWindowViewModel : ViewModelBase {
get => _format;
set => this.RaiseAndSetIfChanged(ref _format, value);
}
public ObservableCollection<string> AvailableFormats {
get => _availableFormats;
set => this.RaiseAndSetIfChanged(ref _availableFormats, value);
}
/// <summary>
/// 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>
public string SaveLocation {
get => _saveLocation;
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>
/// 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());
}
}
/// <summary>
/// Generates the arguments used for the main command string.
/// </summary>
@@ -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<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>
+37 -41
View File
@@ -33,52 +33,48 @@
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<Grid
Margin="20 35 20 20"
ShowGridLines="False"
Width="500"
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto"
RowSpacing="10">
<TextBlock
Grid.Row="0"
Text="Youtube Video Downloads"
FontSize="30"/>
<TextBlock
Grid.Row="1"
Text="Enter your video link and save location."
FontSize="20"></TextBlock>
<Border Grid.Row="2" BorderBrush="White" BorderThickness="0,0,0,1"/>
<StackPanel Grid.Row="3" Spacing="5">
<StackPanel Margin="20 35 20 20"
Width="500"
Spacing="10"
HorizontalAlignment="Stretch">
<TextBlock Text="Youtube Video Downloads"
FontSize="30"/>
<TextBlock Text="Enter your video link and save location."
FontSize="20"></TextBlock>
<Border BorderBrush="White" BorderThickness="0,0,0,1"/>
<StackPanel Spacing="5">
<TextBlock Text="Save location:"/>
<Grid
ColumnDefinitions="*, 30"
ColumnSpacing="5">
<TextBox
Grid.Column="0"
Text="{Binding SaveLocation}"
Watermark="Choose a folder..."/>
<Button
Grid.Column="1"
Content=">"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Command="{Binding GetSaveLocationCommand}"/>
<Grid ColumnDefinitions="*, 30"
ColumnSpacing="5">
<TextBox Grid.Column="0"
Text="{Binding SaveLocation}"
Watermark="Choose a folder..."/>
<Button Grid.Column="1"
Content=">"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Command="{Binding GetSaveLocationCommand}"/>
</Grid>
</StackPanel>
<StackPanel Grid.Row="4" Spacing="5">
<StackPanel Spacing="5">
<TextBlock Text="Video link:"/>
<TextBox
Text="{Binding Link}"
Watermark="Paste link here..."/>
<TextBox Text="{Binding Link}"
Watermark="Paste link here..."/>
</StackPanel>
<Button
Grid.Row="5"
Content="Download"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding CanDownload}"
Command="{Binding DownloadFileCommand}"/>
</Grid>
<StackPanel Spacing="5"
HorizontalAlignment="Stretch">
<TextBlock Text="Format:"/>
<ComboBox HorizontalAlignment="Stretch"
ItemsSource="{Binding AvailableFormats}"
SelectedItem="{Binding Format, Mode=TwoWay}">
</ComboBox>
</StackPanel>
<Button Content="Download"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding CanDownload}"
Command="{Binding DownloadFileCommand}"/>
</StackPanel>
</Panel>
</Window>