mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
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:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user