1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-22 14:32:40 +00:00

fix yt dl returning incorrect filename

This commit is contained in:
fiso64 2024-10-06 09:51:48 +02:00
parent d13b3307d8
commit f2867347fe
2 changed files with 18 additions and 7 deletions

View file

@ -672,13 +672,12 @@ namespace Extractors
return savePathNoExt + ".opus"; return savePathNoExt + ".opus";
string parentDirectory = Path.GetDirectoryName(savePathNoExt); string parentDirectory = Path.GetDirectoryName(savePathNoExt);
string[] musicFiles = Directory.GetFiles(parentDirectory, "*", SearchOption.TopDirectoryOnly) var musicFiles = Directory.GetFiles(parentDirectory, savePathNoExt + ".*", SearchOption.TopDirectoryOnly)
.Where(file => Utils.IsMusicFile(file)) .Where(file => Utils.IsMusicFile(file) || Utils.IsVideoFile(file))
.ToArray(); .OrderByDescending(file => Utils.IsMusicFile(file))
if (musicFiles.Length > 0) .ThenBy(file => Utils.IsVideoFile(file));
return musicFiles[0];
return ""; return musicFiles.FirstOrDefault() ?? "";
} }
} }
} }

View file

@ -5,7 +5,9 @@ using System.Text.RegularExpressions;
public static class Utils public static class Utils
{ {
public static readonly string[] musicExtensions = new string[] { ".mp3", ".flac", ".ogg", ".m4a", ".opus", ".wav", ".aac", ".alac" }; 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) public static bool IsMusicExtension(string extension)
{ {
@ -27,6 +29,16 @@ public static class Utils
return imageExtensions.Contains(Path.GetExtension(fileName).ToLower()); 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) public static bool IsInternetUrl(this string str)
{ {
str = str.TrimStart(); str = str.TrimStart();