mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 19:57:27 +08:00
Core: Implement watchdog, use api host in config
This commit is contained in:
parent
c6eae11f95
commit
ec58a3c5b9
|
@ -95,7 +95,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
if (this.disposedValue)
|
||||
throw new ObjectDisposedException(nameof(HttpApiClient));
|
||||
|
||||
var url = $@"https://api.live.bilibili.com/room/v1/Room/get_info?id={roomid}";
|
||||
var url = $@"{this.config.LiveApiHost}/room/v1/Room/get_info?id={roomid}";
|
||||
return FetchAsync<RoomInfo>(this.mainClient, url);
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
if (this.disposedValue)
|
||||
throw new ObjectDisposedException(nameof(HttpApiClient));
|
||||
|
||||
var url = $@"https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid={roomid}";
|
||||
var url = $@"{this.config.LiveApiHost}/live_user/v1/UserInfo/get_anchor_in_room?roomid={roomid}";
|
||||
return FetchAsync<UserInfo>(this.mainClient, url);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
if (this.disposedValue)
|
||||
throw new ObjectDisposedException(nameof(HttpApiClient));
|
||||
|
||||
var url = $@"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id={roomid}&protocol=0%2C1&format=0%2C2&codec=0%2C1&qn=10000&platform=web&ptype=16";
|
||||
var url = $@"{this.config.LiveApiHost}/xlive/web-room/v2/index/getRoomPlayInfo?room_id={roomid}&protocol=0%2C1&format=0%2C2&codec=0%2C1&qn=10000&platform=web&ptype=16";
|
||||
return FetchAsync<RoomPlayInfo>(this.mainClient, url);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
if (this.disposedValue)
|
||||
throw new ObjectDisposedException(nameof(HttpApiClient));
|
||||
|
||||
var url = $@"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id={roomid}&type=0";
|
||||
var url = $@"{this.config.LiveApiHost}/xlive/web-room/v1/index/getDanmuInfo?id={roomid}&type=0";
|
||||
return FetchAsync<DanmuInfo>(this.anonClient, url);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,9 @@ namespace BililiveRecorder.Core.Recording
|
|||
private const string HttpHeaderReferer = "https://live.bilibili.com/";
|
||||
private const string HttpHeaderUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36";
|
||||
|
||||
private const int timer_inverval = 2;
|
||||
private readonly Timer timer = new Timer(1000 * timer_inverval);
|
||||
private readonly Random random = new Random();
|
||||
private readonly Timer timer = new Timer(1000 * 2);
|
||||
private readonly CancellationTokenSource cts = new CancellationTokenSource();
|
||||
private readonly CancellationToken ct;
|
||||
|
||||
|
@ -52,7 +53,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
|
||||
private readonly object fillerStatsLock = new object();
|
||||
private int fillerDownloadedBytes;
|
||||
private DateTimeOffset fillerLastStatsTrigger;
|
||||
private DateTimeOffset fillerStatsLastTrigger;
|
||||
private TimeSpan durationSinceNoDataReceived;
|
||||
|
||||
public RecordTask(IRoom room,
|
||||
ILogger logger,
|
||||
|
@ -149,7 +151,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
});
|
||||
};
|
||||
|
||||
this.fillerLastStatsTrigger = DateTimeOffset.UtcNow;
|
||||
this.fillerStatsLastTrigger = DateTimeOffset.UtcNow;
|
||||
this.durationSinceNoDataReceived = TimeSpan.Zero;
|
||||
this.filler = Task.Run(async () => await this.FillPipeAsync(stream, pipe.Writer).ConfigureAwait(false));
|
||||
|
||||
_ = Task.Run(this.RecordingLoopAsync);
|
||||
|
@ -202,9 +205,11 @@ namespace BililiveRecorder.Core.Recording
|
|||
{
|
||||
bytes = Interlocked.Exchange(ref this.fillerDownloadedBytes, 0);
|
||||
end = DateTimeOffset.UtcNow;
|
||||
start = this.fillerLastStatsTrigger;
|
||||
this.fillerLastStatsTrigger = end;
|
||||
start = this.fillerStatsLastTrigger;
|
||||
this.fillerStatsLastTrigger = end;
|
||||
diff = end - start;
|
||||
|
||||
this.durationSinceNoDataReceived = bytes > 0 ? TimeSpan.Zero : this.durationSinceNoDataReceived + diff;
|
||||
}
|
||||
|
||||
var mbps = bytes * 8d / 1024d / 1024d / diff.TotalSeconds;
|
||||
|
@ -217,6 +222,12 @@ namespace BililiveRecorder.Core.Recording
|
|||
EndTime = end,
|
||||
Mbps = mbps
|
||||
});
|
||||
|
||||
if (this.durationSinceNoDataReceived.TotalMilliseconds > this.room.RoomConfig.TimingWatchdogTimeout)
|
||||
{
|
||||
this.logger.Warning("直播服务器未断开连接但停止发送直播数据,将会主动断开连接");
|
||||
this.RequestStop();
|
||||
}
|
||||
}
|
||||
|
||||
private void Writer_BeforeScriptTagWrite(ScriptTagBody scriptTagBody)
|
||||
|
|
Loading…
Reference in New Issue
Block a user