commit d0b7e836099163852c2c5f782bd4920f9b215740 Author: Lucas Vas Date: Fri Sep 12 21:08:49 2025 -0400 feat: initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/PantherByte.sln b/PantherByte.sln new file mode 100644 index 0000000..6a0decc --- /dev/null +++ b/PantherByte.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PantherByte", "PantherByte\PantherByte.csproj", "{92A66B7A-D045-450D-AF19-1DC36FD599F7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {92A66B7A-D045-450D-AF19-1DC36FD599F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92A66B7A-D045-450D-AF19-1DC36FD599F7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92A66B7A-D045-450D-AF19-1DC36FD599F7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92A66B7A-D045-450D-AF19-1DC36FD599F7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/PantherByte/App.axaml b/PantherByte/App.axaml new file mode 100644 index 0000000..ad6d724 --- /dev/null +++ b/PantherByte/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PantherByte/App.axaml.cs b/PantherByte/App.axaml.cs new file mode 100644 index 0000000..c152059 --- /dev/null +++ b/PantherByte/App.axaml.cs @@ -0,0 +1,56 @@ +using System; +using System.ComponentModel.Design; +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using Microsoft.Extensions.DependencyInjection; +using PantherByte.Services; +using PantherByte.ViewModels; +using PantherByte.Views; + +namespace PantherByte; + +public partial class App : Application { + /// + /// The services that are available for the application. + /// + public IServiceProvider? Services { get; private set; } + + public new static App? Current => Application.Current as App; + + public override void Initialize() { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + // Avoid duplicate validations from both Avalonia and the CommunityToolkit. + // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = new MainWindow { + DataContext = new MainWindowViewModel(), + }; + + var services = new ServiceCollection(); + services.AddSingleton(x => new FileService(desktop.MainWindow)); + + Services = services.BuildServiceProvider(); + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/PantherByte/Assets/avalonia-logo.ico b/PantherByte/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/PantherByte/Assets/avalonia-logo.ico differ diff --git a/PantherByte/PantherByte.csproj b/PantherByte/PantherByte.csproj new file mode 100644 index 0000000..766b03c --- /dev/null +++ b/PantherByte/PantherByte.csproj @@ -0,0 +1,31 @@ + + + WinExe + net9.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + + None + All + + + + + + diff --git a/PantherByte/Program.cs b/PantherByte/Program.cs new file mode 100644 index 0000000..3cd29b9 --- /dev/null +++ b/PantherByte/Program.cs @@ -0,0 +1,20 @@ +using Avalonia; +using System; + +namespace PantherByte; + +sealed class Program { + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/PantherByte/Services/FileService.cs b/PantherByte/Services/FileService.cs new file mode 100644 index 0000000..866cf3e --- /dev/null +++ b/PantherByte/Services/FileService.cs @@ -0,0 +1,25 @@ +using System.Threading.Tasks; +using Avalonia.Controls; +using Avalonia.Platform.Storage; + +namespace PantherByte.Services; + +public class FileService : IFileSaveService { + private readonly Window _target; + + public FileService(Window target) { + _target = target; + } + + /// + /// Opens a file picker for the user and returns the path of the file they'd like to create. + /// + /// A filepath to the user's selected save location. + public async Task ChooseFolderAsync() { + var folderList = await _target.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions() { + Title = "Choose Download Location", + }); + + return folderList[0]; + } +} diff --git a/PantherByte/Services/Interfaces/IFileService.cs b/PantherByte/Services/Interfaces/IFileService.cs new file mode 100644 index 0000000..6265970 --- /dev/null +++ b/PantherByte/Services/Interfaces/IFileService.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Avalonia.Platform.Storage; + +namespace PantherByte; + +public interface IFileSaveService { + public Task ChooseFolderAsync(); +} diff --git a/PantherByte/ViewLocator.cs b/PantherByte/ViewLocator.cs new file mode 100644 index 0000000..0358217 --- /dev/null +++ b/PantherByte/ViewLocator.cs @@ -0,0 +1,26 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using PantherByte.ViewModels; + +namespace PantherByte; + +public class ViewLocator : IDataTemplate { + public Control? Build(object? param) { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/PantherByte/ViewModels/MainWindowViewModel.cs b/PantherByte/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..d8aac77 --- /dev/null +++ b/PantherByte/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.IO; +using CommunityToolkit.Mvvm.Input; +using System.Threading.Tasks; +using PantherByte.Services; +using ReactiveUI; + +namespace PantherByte.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase { + private string _link = string.Empty; + private string _saveLocation = string.Empty; + private string _format = "mp3"; + private bool _canDownload = true; + + /// + /// The link to the video to download. For now, only use YouTube links. + /// + public string Link { + get => _link; + set => this.RaiseAndSetIfChanged(ref _link, value); + } + + /// + /// The format to download the video in. Currently supported options are MP3, MP4, and WAV. This will become the + /// argument passed to the "-t" argument in . + /// + public string Format { + get => _format; + set => this.RaiseAndSetIfChanged(ref _format, 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 file can be downloaded. If not, the download button is disabled. + /// + public bool CanDownload { + get => _canDownload; + set => this.RaiseAndSetIfChanged(ref _canDownload, value); + } + + /// + /// Constructor. Mainly used for subscribing properties to the changes from other properties. + /// + public MainWindowViewModel() { + // Subscribe the CanDownload bool to the results of the Link, SaveLocation, and Format property changes. + this.WhenAnyValue( + x => x.Link, + x => x.SaveLocation, + x => x.Format, + (link, saveLocation, format) => !string.IsNullOrWhiteSpace(link) + && !string.IsNullOrWhiteSpace(format) + && !string.IsNullOrWhiteSpace(saveLocation) + ) + .Subscribe(value => CanDownload = value); + } + + /// + /// Gets the save location for the generated file. We are only allowing users to download one file at a time for now. + /// + /// + /// Thrown when there are no available services that implement , or when the + /// returned from the + /// method is null. + /// + /// + /// Thrown when the selected directory path does not exist in the current filesystem. + /// + [RelayCommand] + private async Task GetSaveLocationAsync() { + try { + var fileService = App.Current?.Services?.GetService(typeof(IFileSaveService)); + if (fileService is FileService service) { + var filePath = await service.ChooseFolderAsync(); + if (filePath is not null) { + var tempPath = filePath.Path.AbsolutePath; + if (Directory.Exists(tempPath)) { + SaveLocation = tempPath; + Console.WriteLine("Successfully set the file path."); + } else { + throw new DirectoryNotFoundException($"Directory does not exist: {tempPath}"); + } + } else { + throw new NullReferenceException("The resulting storage folder was null."); + } + } else { + throw new NullReferenceException("Missing a FileSaveService instance"); + } + } catch (Exception ex) { + // Exceptions are caught locally for now, but will eventually require a modal error window. + Console.WriteLine(ex.ToString()); + } + } + + /// + /// Generates the arguments used for the main command string. + /// + [RelayCommand] + private async Task> GenerateCmdArgsAsync() { + // The command string format to use: yt-dlp -t -P --no-playlist + // yt-dlp requires usage of ffmpeg as well. + // Code will be executed when the button is clicked. + return await Task.Run(() => new List([Link, "-t", Format, "-P", SaveLocation, "--no-playlist"])); + } + + /// + /// Handles the download process of the file. Generates the command and runs it. + /// + [RelayCommand] + private async Task DownloadFileAsync() { + // Build the command and run the yt-dlp program by using the generated string. + // Somehow we'll need to package the program in with the application during distribution. + var args = await GenerateCmdArgsAsync(); + // Run the command. + try { + System.Diagnostics.Process.Start("yt-dlp", args); + } catch (Exception ex) { + Console.WriteLine(ex.ToString()); + } + } +} diff --git a/PantherByte/ViewModels/ViewModelBase.cs b/PantherByte/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..6dbfcd9 --- /dev/null +++ b/PantherByte/ViewModels/ViewModelBase.cs @@ -0,0 +1,5 @@ +using ReactiveUI; + +namespace PantherByte.ViewModels; + +public class ViewModelBase : ReactiveObject { } \ No newline at end of file diff --git a/PantherByte/Views/MainWindow.axaml b/PantherByte/Views/MainWindow.axaml new file mode 100644 index 0000000..fef19c8 --- /dev/null +++ b/PantherByte/Views/MainWindow.axaml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +