From 7977ebd924db2ab9a8f8fd741ef2d1ca42b84dd2 Mon Sep 17 00:00:00 2001 From: DeltaNeverUsed Date: Sat, 2 Nov 2024 16:03:10 +0100 Subject: [PATCH] fix: linux support --- .../Runtime/DownloadManager.cs | 21 ++++++++++--------- .../Runtime/OpenSyncDance.cs | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Packages/befuddledlabs.opensyncdance/Runtime/DownloadManager.cs b/Packages/befuddledlabs.opensyncdance/Runtime/DownloadManager.cs index 55b1f9f..fb78f31 100644 --- a/Packages/befuddledlabs.opensyncdance/Runtime/DownloadManager.cs +++ b/Packages/befuddledlabs.opensyncdance/Runtime/DownloadManager.cs @@ -8,34 +8,35 @@ using System.IO.Compression; using System.Linq; using System.Net; +using System.Runtime.InteropServices; using System.Threading; using UnityEditor; using UnityEngine; -using Debug = UnityEngine.Debug; -namespace BefuddledLabs.OpenSyncDance -{ +namespace BefuddledLabs.OpenSyncDance { public static class DownloadManager { + + private static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Path to where we should have or are going to download FFmpeg /// - public static string FFmpegPath => BinariesPath + "/ffmpegBinaries/ffmpeg.exe"; + public static string FFmpegPath => IsLinux ? "ffmpeg" : BinariesPath + "/ffmpegBinaries/ffmpeg.exe"; /// /// Path to where we expect to find yt-dlp /// - public static string ytdlpPath => BinariesPath + "/yt-dlp.exe"; + public static string ytdlpPath => IsLinux ? "yt-dlp" : BinariesPath + "/yt-dlp.exe"; /// /// If we can find FFmpeg, otherwise we should download it /// - public static bool HasFFmpeg => File.Exists(FFmpegPath); + public static bool HasFFmpeg => File.Exists(FFmpegPath) || IsLinux; // Just assume you have it if you're running linux /// /// If we can find yt-dlp /// - public static bool Hasytdlp => File.Exists(ytdlpPath); + public static bool Hasytdlp => File.Exists(ytdlpPath) || IsLinux; // Just assume you have it if you're running linux /// /// Path to the root of the unity project @@ -56,7 +57,7 @@ public static class DownloadManager { /// 2: end timestamp /// 3: output file /// - private static string ytdlpParams = $"--ffmpeg-location \"{FFmpegPath}\" " // Use this ffmpeg + private static string ytdlpParams = (IsLinux ? "" : $"--ffmpeg-location \"{FFmpegPath}\" ") // Use this ffmpeg + "-f bestaudio --audio-quality 0 -x --audio-format wav " // Convert to audio file + "--force-keyframes-at-cuts -i {0} --download-sections \"*{1}-{2}\" " // Download specific section of song + "--force-overwrites --no-mtime -v -o \"{3}\" " // Overwrite file and use curret date time @@ -265,9 +266,9 @@ public static void DownloadYouTubeLink(string youtubeLink, TimeSpan start, TimeS TimeSpanToYtdlpString(end + TimeSpan.FromSeconds(1)), tempSongPath), UseShellExecute = false, - CreateNoWindow = true, + CreateNoWindow = true }; - + var downloadAttempts = 3; // Retry the download command a couple of times in case it fails.. for (int i = 0; i < downloadAttempts; i++) { var ytdlpProcess = Process.Start(ytdlpStartInfo); diff --git a/Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs b/Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs index 181eb10..75b4130 100644 --- a/Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs +++ b/Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs @@ -903,7 +903,6 @@ public override void OnInspectorGUI() DownloadManager.DownloadYouTubeLink(animObject); } } - if (EditorGUI.EndChangeCheck()) EditorUtility.SetDirty(_self); }