Skip to content

Commit

Permalink
Make the app x-platform (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Apr 28, 2024
1 parent 7ba94a2 commit d0dd3d4
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 34 deletions.
67 changes: 56 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ jobs:
--configuration Release
pack:
strategy:
matrix:
rid:
- win-arm64
- win-x86
- win-x64
- linux-x64
- osx-arm64
- osx-x64

# Need to run on Windows because of DotnetRuntimeBootstrapper's dependency on Ressy
runs-on: windows-latest
timeout-minutes: 10

Expand All @@ -63,16 +74,17 @@ jobs:
-p:CSharpier_Bypass=true
--output YoutubeDownloader/bin/publish
--configuration Release
--use-current-runtime
--runtime ${{ matrix.rid }}
--no-self-contained
- name: Upload artifacts
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: YoutubeDownloader
name: YoutubeDownloader.${{ matrix.rid }}
path: YoutubeDownloader/bin/publish
if-no-files-found: error

deploy:
release:
if: ${{ github.ref_type == 'tag' }}

needs:
Expand All @@ -82,6 +94,36 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10

permissions:
contents: write

steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release create ${{ github.ref_name }}
--repo ${{ github.event.repository.full_name }}
--title ${{ github.ref_name }}
--generate-notes
--verify-tag
deploy:
needs: release

strategy:
matrix:
rid:
- win-arm64
- win-x86
- win-x64
- linux-x64
- osx-arm64
- osx-x64

runs-on: ubuntu-latest
timeout-minutes: 10

permissions:
actions: read
contents: write
Expand All @@ -90,24 +132,27 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
with:
name: YoutubeDownloader
name: YoutubeDownloader.${{ matrix.rid }}
path: YoutubeDownloader/

- name: Set permissions
if: ${{ !startsWith(matrix.rid, 'win') }}
run: |
chmod +x YoutubeDownloader/YoutubeDownloader
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.zip .
run: zip -r ../YoutubeDownloader.${{ matrix.rid }}.zip .

- name: Create release
- name: Upload release asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release create ${{ github.ref_name }}
YoutubeDownloader.zip
gh release upload ${{ github.ref_name }}
YoutubeDownloader.${{ matrix.rid }}.zip
--repo ${{ github.event.repository.full_name }}
--title ${{ github.ref_name }}
--generate-notes
--verify-tag
notify:
needs: deploy
Expand Down
10 changes: 10 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ To learn more about the war and how you can help, [click here](https://tyrrrz.me
- 🟢 **[Stable release](https://github.com/Tyrrrz/YoutubeDownloader/releases/latest)**
- 🟠 [CI build](https://github.com/Tyrrrz/YoutubeDownloader/actions/workflows/main.yml)

> **Important**:
> To run **YoutubeDownloader**, you need to make sure that the **.NET 8.0 Runtime** is installed.
> You can download it here:
>
> - [.NET 8.0 Runtime for **macOS x64**](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-8.0.0-macos-x64-installer)
> - [.NET 8.0 Runtime for **macOS arm64**](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-8.0.0-macos-arm64-installer)
> - [.NET 8.0 Runtime for **Linux**](https://learn.microsoft.com/dotnet/core/install/linux) (find the correct download for your distro)
> - On **Windows**, the runtime should be installed automatically when you run the application for the first time
## Features

- Fully cross-platform graphical user interface
- Download videos by URL
- Download videos from playlists or channels
- Download videos by search query
Expand Down
2 changes: 1 addition & 1 deletion YoutubeDownloader/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/ffmpeg.exe
/ffmpeg*
29 changes: 15 additions & 14 deletions YoutubeDownloader/DownloadFFmpeg.ps1
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
param (
[string]$platform,
[string]$outputPath
)

$ErrorActionPreference = "Stop"
$ffmpegFilePath = "$PSScriptRoot/ffmpeg.exe"

# Normalize platform identifier
$platform = $platform.ToLower().Replace("win-", "windows-")

# Check if already exists
if (Test-Path $ffmpegFilePath) {
if (Test-Path $outputPath) {
Write-Host "Skipped downloading FFmpeg, file already exists."
exit
}

Write-Host "Downloading FFmpeg..."

# Download the archive
Write-Host "Downloading FFmpeg..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$http = New-Object System.Net.WebClient
try {
$http.DownloadFile("https://github.com/Tyrrrz/FFmpegBin/releases/download/6.1/ffmpeg-windows-x64.zip", "$ffmpegFilePath.zip")
$http.DownloadFile("https://github.com/Tyrrrz/FFmpegBin/releases/download/6.1.1/ffmpeg-$platform.zip", "$outputPath.zip")
} finally {
$http.Dispose()
}

try {
Import-Module "$PSHOME/Modules/Microsoft.PowerShell.Utility" -Function Get-FileHash
$hashResult = Get-FileHash "$ffmpegFilePath.zip" -Algorithm SHA256
if ($hashResult.Hash -ne "48130a80aebffb61d06913350c3ad3187efd85096f898045fd65001bf89d7d7f") {
throw "Failed to verify the hash of the FFmpeg archive."
}

# Extract FFmpeg
Add-Type -Assembly System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead("$ffmpegFilePath.zip")
$zip = [IO.Compression.ZipFile]::OpenRead("$outputPath.zip")
try {
[IO.Compression.ZipFileExtensions]::ExtractToFile($zip.GetEntry("ffmpeg.exe"), $ffmpegFilePath)
$fileName = If ($platform.Contains("windows-")) { "ffmpeg.exe" } Else { "ffmpeg" }
[IO.Compression.ZipFileExtensions]::ExtractToFile($zip.GetEntry($fileName), $outputPath)
} finally {
$zip.Dispose()
}

Write-Host "Done downloading FFmpeg."
} finally {
# Clean up
Remove-Item "$ffmpegFilePath.zip" -Force
Remove-Item "$outputPath.zip" -Force
}
11 changes: 10 additions & 1 deletion YoutubeDownloader/Services/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Onova;
using Onova.Exceptions;
Expand All @@ -9,7 +10,15 @@ namespace YoutubeDownloader.Services;
public class UpdateService(SettingsService settingsService) : IDisposable
{
private readonly IUpdateManager _updateManager = new UpdateManager(
new GithubPackageResolver("Tyrrrz", "YoutubeDownloader", "YoutubeDownloader.zip"),
new GithubPackageResolver(
"Tyrrrz",
"YoutubeDownloader",
// Examples:
// YoutubeDownloader.win-arm64.zip
// YoutubeDownloader.win-x64.zip
// YoutubeDownloader.linux-x64.zip
$"YoutubeDownloader.{RuntimeInformation.RuntimeIdentifier}.zip"
),
new ZipPackageExtractor()
);

Expand Down
5 changes: 4 additions & 1 deletion YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ private void Cancel()
_cancellationTokenSource.Cancel();
}

private bool CanShowFile() => Status == DownloadStatus.Completed;
private bool CanShowFile() =>
Status == DownloadStatus.Completed
// This only works on Windows currently
&& OperatingSystem.IsWindows();

[RelayCommand(CanExecute = nameof(CanShowFile))]
private async Task ShowFileAsync()
Expand Down
2 changes: 2 additions & 0 deletions YoutubeDownloader/Views/Components/DashboardView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
VerticalAlignment="Center"
Command="{Binding ShowAuthSetupCommand}"
Foreground="{DynamicResource MaterialDarkForegroundBrush}"
IsVisible="{OnPlatform False,
Windows=True}"
Theme="{DynamicResource MaterialFlatButton}"
ToolTip.Tip="Authentication">
<materialIcons:MaterialIcon
Expand Down
6 changes: 5 additions & 1 deletion YoutubeDownloader/Views/Dialogs/SettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@
</DockPanel>

<!-- Persist authentication -->
<DockPanel LastChildFill="False" ToolTip.Tip="Save authentication cookies to a file so that they can be persisted between sessions">
<DockPanel
IsVisible="{OnPlatform False,
Windows=True}"
LastChildFill="False"
ToolTip.Tip="Save authentication cookies to a file so that they can be persisted between sessions">
<TextBlock
Margin="16,8"
DockPanel.Dock="Left"
Expand Down
24 changes: 19 additions & 5 deletions YoutubeDownloader/YoutubeDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,29 @@
<ProjectReference Include="..\YoutubeDownloader.Core\YoutubeDownloader.Core.csproj" />
</ItemGroup>

<!-- This downloads FFmpeg and copies it to the output directory-->
<!-- Download FFmpeg and copy it to the output directory-->
<PropertyGroup>
<FFmpegPlatform>$(RuntimeIdentifier)</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">win-x86</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">win-x64</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">linux-arm64</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">linux-x86</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">linux-x64</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('OSX')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">osx-arm64</FFmpegPlatform>
<FFmpegPlatform Condition="'$(FFmpegPlatform)' == '' AND $([MSBuild]::IsOsPlatform('OSX')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">osx-x64</FFmpegPlatform>
<FFmpegFileName Condition="$(FFmpegPlatform.StartsWith('win'))">ffmpeg.exe</FFmpegFileName>
<FFmpegFileName Condition="'$(FFmpegFileName)' == ''">ffmpeg</FFmpegFileName>
</PropertyGroup>

<Target Name="Download FFmpeg before build" BeforeTargets="PreBuildEvent">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadFFmpeg.ps1&quot;" />
<Copy SourceFiles="$(ProjectDir)/ffmpeg.exe" DestinationFiles="$(OutDir)/ffmpeg.exe" SkipUnchangedFiles="true" />
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadFFmpeg.ps1&quot; -Platform $(FFmpegPlatform) -OutputPath &quot;$(ProjectDir)/$(FFmpegFileName)&quot;" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/$(FFmpegFileName)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
</Target>

<Target Name="Download FFmpeg before publish" BeforeTargets="PrepareForPublish">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadFFmpeg.ps1&quot;" />
<Copy SourceFiles="$(ProjectDir)/ffmpeg.exe" DestinationFiles="$(PublishDir)/ffmpeg.exe" SkipUnchangedFiles="true" />
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadFFmpeg.ps1&quot; -Platform $(FFmpegPlatform) -OutputPath &quot;$(ProjectDir)/$(FFmpegFileName)&quot;" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/$(FFmpegFileName)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
</Target>

</Project>

0 comments on commit d0dd3d4

Please sign in to comment.