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();