From 9762753c58e92f53be7a81befac16943ae446fed Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 21 Aug 2024 02:57:01 +0300 Subject: [PATCH] Provide FFmpeg-less builds for convenience (#486) --- .github/workflows/main.yml | 30 +++++++++++++++---- Readme.md | 4 +++ YoutubeDownloader.Core/Downloading/FFmpeg.cs | 20 ++++++++----- YoutubeDownloader/DownloadFFmpeg.ps1 | 9 ++---- YoutubeDownloader/Services/UpdateService.cs | 7 ++++- YoutubeDownloader/ViewModels/MainViewModel.cs | 6 ++-- YoutubeDownloader/YoutubeDownloader.csproj | 13 ++++---- 7 files changed, 60 insertions(+), 29 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d8c4daf0..ba8989f42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,9 +46,17 @@ jobs: - win-arm64 - win-x86 - win-x64 + - linux-arm64 - linux-x64 - osx-arm64 - osx-x64 + bundle-ffmpeg: + - true + - false + exclude: + # FFmpeg builds for these platforms are not easily available + - bundle-ffmpeg: true + rid: linux-arm64 runs-on: ${{ startsWith(matrix.rid, 'win-') && 'windows-latest' || startsWith(matrix.rid, 'osx-') && 'macos-latest' || 'ubuntu-latest' }} timeout-minutes: 10 @@ -66,6 +74,10 @@ jobs: with: dotnet-version: 8.0.x + - name: Download FFmpeg + if: ${{ matrix.bundle-ffmpeg }} + run: dotnet build YoutubeDownloader -t:DownloadFFmpeg + - name: Publish app run: > dotnet publish YoutubeDownloader @@ -79,7 +91,7 @@ jobs: - name: Upload artifacts uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 with: - name: YoutubeDownloader.${{ matrix.rid }} + name: ${{ matrix.bundle-ffmpeg && 'YoutubeDownloader' || 'YoutubeDownloader.Bare' }}.${{ matrix.rid }} path: YoutubeDownloader/bin/publish if-no-files-found: error @@ -116,9 +128,17 @@ jobs: - win-arm64 - win-x86 - win-x64 + - linux-arm64 - linux-x64 - osx-arm64 - osx-x64 + bundle-ffmpeg: + - true + - false + exclude: + # FFmpeg builds for these platforms are not easily available + - bundle-ffmpeg: true + rid: linux-arm64 runs-on: ubuntu-latest timeout-minutes: 10 @@ -131,26 +151,26 @@ jobs: - name: Download artifacts uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: - name: YoutubeDownloader.${{ matrix.rid }} + name: ${{ matrix.bundle-ffmpeg && 'YoutubeDownloader' || 'YoutubeDownloader.Bare' }}.${{ matrix.rid }} path: YoutubeDownloader/ - name: Set permissions if: ${{ !startsWith(matrix.rid, 'win-') }} run: | chmod +x YoutubeDownloader/YoutubeDownloader - chmod +x YoutubeDownloader/ffmpeg + ${{ matrix.bundle-ffmpeg && 'chmod +x YoutubeDownloader/ffmpeg' || '' }} - name: Create package # Change into the artifacts directory to avoid including the directory itself in the zip archive working-directory: YoutubeDownloader/ - run: zip -r ../YoutubeDownloader.${{ matrix.rid }}.zip . + run: zip -r ../${{ matrix.bundle-ffmpeg && 'YoutubeDownloader' || 'YoutubeDownloader.Bare' }}.${{ matrix.rid }}.zip . - name: Upload release asset env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: > gh release upload ${{ github.ref_name }} - YoutubeDownloader.${{ matrix.rid }}.zip + ${{ matrix.bundle-ffmpeg && 'YoutubeDownloader' || 'YoutubeDownloader.Bare' }}.${{ matrix.rid }}.zip --repo ${{ github.event.repository.full_name }} notify: diff --git a/Readme.md b/Readme.md index c14a4061b..e9adca5bf 100644 --- a/Readme.md +++ b/Readme.md @@ -45,6 +45,10 @@ To learn more about the war and how you can help, [click here](https://tyrrrz.me > **Note**: > If you're unsure which build is right for your system, consult with [this page](https://useragent.cc) to determine your OS and CPU architecture. +> **Note**: +> **YoutubeDownloader** comes bundled with [FFmpeg](https://ffmpeg.org) which is used for processing videos. +> You can also download a version of **YoutubeDownloader** that doesn't include FFmpeg (`YoutubeDownloader.Bare.*` builds) if you prefer to use your own installation. + ## Features - Cross-platform graphical user interface diff --git a/YoutubeDownloader.Core/Downloading/FFmpeg.cs b/YoutubeDownloader.Core/Downloading/FFmpeg.cs index 6d4cf2316..2376cf805 100644 --- a/YoutubeDownloader.Core/Downloading/FFmpeg.cs +++ b/YoutubeDownloader.Core/Downloading/FFmpeg.cs @@ -7,6 +7,9 @@ namespace YoutubeDownloader.Core.Downloading; public static class FFmpeg { + private static string CliFileName { get; } = + OperatingSystem.IsWindows() ? "ffmpeg.exe" : "ffmpeg"; + public static string? TryGetCliFilePath() { static IEnumerable GetProbeDirectoryPaths() @@ -14,19 +17,20 @@ static IEnumerable GetProbeDirectoryPaths() yield return AppContext.BaseDirectory; yield return Directory.GetCurrentDirectory(); - foreach ( - var path in Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) - ?? Enumerable.Empty() - ) + if (Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) is { } paths) { - yield return path; + foreach (var path in paths) + yield return path; } } return GetProbeDirectoryPaths() - .Select(dirPath => - Path.Combine(dirPath, OperatingSystem.IsWindows() ? "ffmpeg.exe" : "ffmpeg") - ) + .Select(dirPath => Path.Combine(dirPath, CliFileName)) .FirstOrDefault(File.Exists); } + + public static bool IsBundled() => + File.Exists(Path.Combine(AppContext.BaseDirectory, CliFileName)); + + public static bool IsAvailable() => !string.IsNullOrWhiteSpace(TryGetCliFilePath()); } diff --git a/YoutubeDownloader/DownloadFFmpeg.ps1 b/YoutubeDownloader/DownloadFFmpeg.ps1 index e2e63bc64..20d8021d1 100644 --- a/YoutubeDownloader/DownloadFFmpeg.ps1 +++ b/YoutubeDownloader/DownloadFFmpeg.ps1 @@ -1,3 +1,6 @@ +# This script is called from inside an MSBuild task to download FFmpeg binaries: +# dotnet build -t:DownloadFFmpeg + param ( [string]$platform, [string]$outputPath @@ -8,12 +11,6 @@ $ErrorActionPreference = "Stop" # Normalize platform identifier $platform = $platform.ToLower().Replace("win-", "windows-") -# Check if already exists -if (Test-Path $outputPath) { - Write-Host "Skipped downloading FFmpeg, file already exists." - exit -} - # Download the archive Write-Host "Downloading FFmpeg..." [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 diff --git a/YoutubeDownloader/Services/UpdateService.cs b/YoutubeDownloader/Services/UpdateService.cs index f5881af6c..c9b933299 100644 --- a/YoutubeDownloader/Services/UpdateService.cs +++ b/YoutubeDownloader/Services/UpdateService.cs @@ -1,9 +1,11 @@ using System; +using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; using Onova; using Onova.Exceptions; using Onova.Services; +using YoutubeDownloader.Core.Downloading; namespace YoutubeDownloader.Services; @@ -18,7 +20,10 @@ public class UpdateService(SettingsService settingsService) : IDisposable // YoutubeDownloader.win-arm64.zip // YoutubeDownloader.win-x64.zip // YoutubeDownloader.linux-x64.zip - $"YoutubeDownloader.{RuntimeInformation.RuntimeIdentifier}.zip" + // YoutubeDownloader.Bare.linux-x64.zip + FFmpeg.IsBundled() + ? $"YoutubeDownloader.{RuntimeInformation.RuntimeIdentifier}.zip" + : $"YoutubeDownloader.Bare.{RuntimeInformation.RuntimeIdentifier}.zip" ), new ZipPackageExtractor() ) diff --git a/YoutubeDownloader/ViewModels/MainViewModel.cs b/YoutubeDownloader/ViewModels/MainViewModel.cs index caddf8ff3..4c76ae1da 100644 --- a/YoutubeDownloader/ViewModels/MainViewModel.cs +++ b/YoutubeDownloader/ViewModels/MainViewModel.cs @@ -75,7 +75,7 @@ private async Task ShowDevelopmentBuildMessageAsync() private async Task ShowFFmpegMessageAsync() { - if (!string.IsNullOrWhiteSpace(FFmpeg.TryGetCliFilePath())) + if (FFmpeg.IsAvailable()) return; var dialog = viewModelManager.CreateMessageBoxViewModel( @@ -83,7 +83,9 @@ private async Task ShowFFmpegMessageAsync() $""" FFmpeg is required for {Program.Name} to work. Please download it and make it available in the application directory or on the system PATH. - Click DOWNLOAD to go to the FFmpeg download page. You can also install FFmpeg using a package manager instead. + Alternatively, you can also download a version of {Program.Name} that has FFmpeg bundled with it. + + Click DOWNLOAD to go to the FFmpeg download page. """, "DOWNLOAD", "CLOSE" diff --git a/YoutubeDownloader/YoutubeDownloader.csproj b/YoutubeDownloader/YoutubeDownloader.csproj index fbe16e8b7..01e286a6a 100644 --- a/YoutubeDownloader/YoutubeDownloader.csproj +++ b/YoutubeDownloader/YoutubeDownloader.csproj @@ -53,7 +53,7 @@ - + $(RuntimeIdentifier) win-arm64 @@ -68,14 +68,13 @@ ffmpeg - + - - - - - + + + + \ No newline at end of file