-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLimelightProcessing.cs
More file actions
94 lines (80 loc) · 3.67 KB
/
Copy pathLimelightProcessing.cs
File metadata and controls
94 lines (80 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using LimelightClasses;
using Raphdf201.FileUtils;
using static TechLogManager.Utils;
namespace TechLogManager;
public static class LimelightProcessing
{
public static async Task<List<LogEntry>> GetLogs(ClientManager conn)
{
Log("Processing Limelight logs...");
var entries = new List<LogEntry>();
try
{
var limelightsJson = await conn.RunCommandAsync("cat /home/lvuser/limelights.json");
var limelights = ParseJsonStringList(limelightsJson) ??
throw new FileNotFoundException("Failed to get limelight list");
Log($"Found {limelights.Count} Limelight(s): {string.Join(", ", limelights)}");
foreach (var llname in limelights)
entries.AddRange(await ProcessSingleLimelight(llname, conn));
}
catch (Exception ex)
{
Log($"Limelight error: {ex.Message}");
throw;
}
return entries;
}
private static async Task<List<LogEntry>> ProcessSingleLimelight(string llname, ClientManager conn)
{
Log($"Processing {llname}");
var recs = await LimelightUtils.GetRecordingsAsync(llname);
return recs.Select(rec =>
{
rec.GetLinks(); // Convert file names to full URLs
return new LogEntry(rec.Name, LogSource.Limelight, async (dest, action) =>
{
if (action.IsDownload())
{
if (!string.IsNullOrEmpty(rec.Video))
await conn.DownloadFileHttpAsync(rec.Video, dest
.Combine(llname).CreateDirectory().Combine("video.avi"));
if (!string.IsNullOrEmpty(rec.Manifest))
await conn.DownloadFileHttpAsync(rec.Manifest, dest
.Combine(llname).CreateDirectory().Combine("manifest.jsonl"));
if (!string.IsNullOrEmpty(rec.Bootlog))
await conn.DownloadFileHttpAsync(rec.Bootlog, dest
.Combine(llname).CreateDirectory().Combine("bootlog.txt.gz"));
}
if (action.IsDelete())
await rec.Delete();
});
}).ToList().Reversed();
}
public static async Task DownloadAll(string dest, ClientManager conn)
{
var limelightsJson = await conn.RunCommandAsync("cat /home/lvuser/limelights.json");
var limelights = ParseJsonStringList(limelightsJson);
if (limelights == null) return;
foreach (var llname in limelights)
foreach (RecordingDetail rec in await LimelightUtils.GetRecordingsAsync(llname))
{
if (!string.IsNullOrEmpty(rec.Video))
await conn.DownloadFileHttpAsync(rec.Video, dest
.Combine(llname + "-" + rec.Name).CreateDirectory().Combine("video.avi"));
if (!string.IsNullOrEmpty(rec.Manifest))
await conn.DownloadFileHttpAsync(rec.Manifest, dest
.Combine(llname + "-" + rec.Name).CreateDirectory().Combine("manifest.jsonl"));
if (!string.IsNullOrEmpty(rec.Bootlog))
await conn.DownloadFileHttpAsync(rec.Bootlog, dest
.Combine(llname + "-" + rec.Name).CreateDirectory().Combine("bootlog.txt.gz"));
}
}
public static async Task DeleteAll(ClientManager conn)
{
var limelightsJson = await conn.RunCommandAsync("cat /home/lvuser/limelights.json");
var limelights = ParseJsonStringList(limelightsJson);
if (limelights == null) return;
foreach (var limelight in limelights)
await LimelightUtils.DeleteAllVideosAsync(limelight);
}
}