emby-toolbox/EmbyToolbox/Services/TrackExtractionFormats.cs
Emby Toolbox 6264b487fe Initial commit: Emby Toolbox (conversion scroll fix, bulk Del for tracks).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 21:33:47 +05:00

56 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
namespace EmbyToolbox.Services;
/// <summary>Разрешённые контейнеры для извлечения дорожек.</summary>
public static class TrackExtractionFormats
{
private static readonly HashSet<string> Extensions = new(StringComparer.OrdinalIgnoreCase)
{
".mkv", ".mp4",
};
public static bool IsSupportedPath(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
}
var ext = Path.GetExtension(path);
return !string.IsNullOrWhiteSpace(ext) && Extensions.Contains(ext);
}
public static string BuildOpenFileFilter() => "MKV и MP4|*.mkv;*.mp4|Все файлы|*.*";
public static IReadOnlyList<string> EnumerateMediaFilesRecursive(string rootDirectory)
{
if (string.IsNullOrWhiteSpace(rootDirectory) || !Directory.Exists(rootDirectory))
{
return Array.Empty<string>();
}
var bag = new List<string>();
try
{
foreach (var file in Directory.EnumerateFiles(rootDirectory, "*.*", SearchOption.AllDirectories))
{
if (IsSupportedPath(file))
{
bag.Add(Path.GetFullPath(file));
}
}
}
catch (UnauthorizedAccessException)
{
// игнорируем недоступные подкаталоги
}
catch (IOException)
{
}
bag.Sort(StringComparer.OrdinalIgnoreCase);
return bag;
}
}