Skip to content

Commit

Permalink
feat(wip): Support .mkv video format
Browse files Browse the repository at this point in the history
TODO:
- Allow user setting to record in .mkv
- Fix compressor and uploaders to be capable of using .mkv format
  • Loading branch information
lulzsun committed Apr 9, 2023
1 parent 3d8b070 commit 7c8f627
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Classes/Utils/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,32 @@ public static string GetAllVideos(string Game = "All Games", string SortBy = "La
}

public static VideoList GetAllVideos(string Game = "All Games", string SortBy = "Latest", bool isVideoList = true) {
var videoExtensions = new[] { ".mp4", ".mkv" };
List<string> allfiles = new();
switch (SortBy) {
case "Latest":
allfiles = new List<string>(Directory.GetFiles(GetPlaysFolder(), "*.mp4*", SearchOption.AllDirectories).OrderByDescending(d => new FileInfo(d).CreationTime));
allfiles = Directory.GetFiles(GetPlaysFolder(), "*.*", SearchOption.AllDirectories)
.Where(file => videoExtensions.Any(file.ToLower().EndsWith))
.OrderByDescending(d => new FileInfo(d).CreationTime)
.ToList();
break;
case "Oldest":
allfiles = new List<string>(Directory.GetFiles(GetPlaysFolder(), "*.mp4*", SearchOption.AllDirectories).OrderBy(d => new FileInfo(d).CreationTime));
allfiles = Directory.GetFiles(GetPlaysFolder(), "*.*", SearchOption.AllDirectories)
.Where(file => videoExtensions.Any(file.ToLower().EndsWith))
.OrderBy(d => new FileInfo(d).CreationTime)
.ToList();
break;
case "Smallest":
allfiles = new List<string>(Directory.GetFiles(GetPlaysFolder(), "*.mp4*", SearchOption.AllDirectories).OrderBy(d => new FileInfo(d).Length));
allfiles = Directory.GetFiles(GetPlaysFolder(), "*.*", SearchOption.AllDirectories)
.Where(file => videoExtensions.Any(file.ToLower().EndsWith))
.OrderBy(d => new FileInfo(d).Length)
.ToList();
break;
case "Largest":
allfiles = new List<string>(Directory.GetFiles(GetPlaysFolder(), "*.mp4*", SearchOption.AllDirectories).OrderByDescending(d => new FileInfo(d).Length));
allfiles = Directory.GetFiles(GetPlaysFolder(), "*.*", SearchOption.AllDirectories)
.Where(file => videoExtensions.Any(file.ToLower().EndsWith))
.OrderByDescending(d => new FileInfo(d).Length)
.ToList();
break;
default:
return null;
Expand All @@ -204,7 +217,8 @@ public static VideoList GetAllVideos(string Game = "All Games", string SortBy =
Logger.WriteLine($"Found '{allfiles.Count}' video files in {GetPlaysFolder()}");

foreach (string file in allfiles) {
if (!(file.EndsWith("-ses.mp4") || file.EndsWith("-man.mp4") || file.EndsWith("-clp.mp4")) || !File.Exists(file)) continue;
var fileWithoutExt = Path.GetFileNameWithoutExtension(file);
if (!(fileWithoutExt.EndsWith("-ses") || fileWithoutExt.EndsWith("-man") || fileWithoutExt.EndsWith("-clp")) || !File.Exists(file)) continue;

Video video = new();
video.size = new FileInfo(file).Length;
Expand All @@ -226,7 +240,7 @@ public static VideoList GetAllVideos(string Game = "All Games", string SortBy =
if (!File.Exists(thumb)) continue;
video.thumbnail = Path.GetFileName(thumb);

if (file.EndsWith("-ses.mp4") || file.EndsWith("-man.mp4")) {
if (fileWithoutExt.EndsWith("-ses") || fileWithoutExt.EndsWith("-man")) {
videoList.sessions.Add(video);
videoList.sessionsSize += video.size;
}
Expand Down

0 comments on commit 7c8f627

Please sign in to comment.