Added a stream capture locking feature due to DLive spuriously reporting a streamer as not live when they are and causing duplicate captures.

It works by having the capture script touch a file before it begins capturing, then remove the file when the capture is complete.

The bot will check if this file is present before checking if a DLive streamer is actually live which will reduce the amount of API hits and prevent it from going live twice.
This commit is contained in:
barelyprofessional
2025-11-08 09:01:38 -06:00
parent 3ca9e1278b
commit ccf26d24a2
3 changed files with 43 additions and 6 deletions

View File

@@ -33,9 +33,11 @@ public class DLive(ChatBot kfChatBot) : IDisposable
await using var db = new ApplicationDbContext();
var streams = await db.Streams.Where(s => s.Service == StreamService.DLive).Include(s => s.User).ToListAsync(ct);
var settings = await SettingsProvider.GetMultipleValuesAsync([
BuiltIn.Keys.DLivePersistedCurrentlyLiveStreams, BuiltIn.Keys.CaptureEnabled
BuiltIn.Keys.DLivePersistedCurrentlyLiveStreams, BuiltIn.Keys.CaptureEnabled,
BuiltIn.Keys.CaptureLockTable
]);
var currentlyLive = settings[BuiltIn.Keys.DLivePersistedCurrentlyLiveStreams].JsonDeserialize<List<string>>() ?? [];
var locks = settings[BuiltIn.Keys.CaptureLockTable].JsonDeserialize<Dictionary<string, string>>() ?? new Dictionary<string, string>();
foreach (var stream in streams)
{
var username = stream.StreamUrl.Split('/').LastOrDefault();
@@ -45,6 +47,15 @@ public class DLive(ChatBot kfChatBot) : IDisposable
continue;
}
if (locks.ContainsKey(stream.StreamUrl))
{
if (File.Exists(locks[stream.StreamUrl]))
{
_logger.Debug($"{stream.StreamUrl} has an existing lock at {locks[stream.StreamUrl]}, ignoring");
continue;
}
}
DLiveIsLiveModel status;
try
{