From f2867347fed13bc5b404c8740abc1655fb0523f0 Mon Sep 17 00:00:00 2001 From: fiso64 Date: Sun, 6 Oct 2024 09:51:48 +0200 Subject: [PATCH] fix yt dl returning incorrect filename --- slsk-batchdl/Extractors/YouTube.cs | 11 +++++------ slsk-batchdl/Utilities/Utils.cs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/slsk-batchdl/Extractors/YouTube.cs b/slsk-batchdl/Extractors/YouTube.cs index 5a97070..8a6012d 100644 --- a/slsk-batchdl/Extractors/YouTube.cs +++ b/slsk-batchdl/Extractors/YouTube.cs @@ -672,13 +672,12 @@ namespace Extractors return savePathNoExt + ".opus"; string parentDirectory = Path.GetDirectoryName(savePathNoExt); - string[] musicFiles = Directory.GetFiles(parentDirectory, "*", SearchOption.TopDirectoryOnly) - .Where(file => Utils.IsMusicFile(file)) - .ToArray(); - if (musicFiles.Length > 0) - return musicFiles[0]; + var musicFiles = Directory.GetFiles(parentDirectory, savePathNoExt + ".*", SearchOption.TopDirectoryOnly) + .Where(file => Utils.IsMusicFile(file) || Utils.IsVideoFile(file)) + .OrderByDescending(file => Utils.IsMusicFile(file)) + .ThenBy(file => Utils.IsVideoFile(file)); - return ""; + return musicFiles.FirstOrDefault() ?? ""; } } } diff --git a/slsk-batchdl/Utilities/Utils.cs b/slsk-batchdl/Utilities/Utils.cs index bc902c3..24adda2 100644 --- a/slsk-batchdl/Utilities/Utils.cs +++ b/slsk-batchdl/Utilities/Utils.cs @@ -5,7 +5,9 @@ using System.Text.RegularExpressions; public static class Utils { public static readonly string[] musicExtensions = new string[] { ".mp3", ".flac", ".ogg", ".m4a", ".opus", ".wav", ".aac", ".alac" }; - public static readonly string[] imageExtensions = new string[] { ".jpg", ".png", ".jpeg" }; + public static readonly string[] imageExtensions = new string[] { ".jpg", ".png", ".jpeg", ".gif", ".webp" }; + public static readonly string[] videoExtensions = new string[] { ".mp4", ".mkv", ".avi", ".mov", ".webm", ".mpeg" }; + public static bool IsMusicExtension(string extension) { @@ -27,6 +29,16 @@ public static class Utils return imageExtensions.Contains(Path.GetExtension(fileName).ToLower()); } + public static bool IsVideoExtension(string extension) + { + return videoExtensions.Contains(extension.ToLower()); + } + + public static bool IsVideoFile(string fileName) + { + return videoExtensions.Contains(Path.GetExtension(fileName).ToLower()); + } + public static bool IsInternetUrl(this string str) { str = str.TrimStart();