56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
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;
|
||
}
|
||
}
|