mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
parent
b267d6493b
commit
bcbd1597c6
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
|
@ -39,6 +40,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
private int partIndex = 0;
|
||||
|
||||
protected string? streamHost;
|
||||
protected string? streamHostFull;
|
||||
protected bool started = false;
|
||||
protected bool timeoutTriggered = false;
|
||||
protected int qn;
|
||||
|
@ -284,6 +286,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
{
|
||||
var client = this.CreateHttpClient();
|
||||
|
||||
var streamHostInfoBuilder = new StringBuilder();
|
||||
|
||||
while (true)
|
||||
{
|
||||
var allowedAddressFamily = this.room.RoomConfig.NetworkTransportAllowedAddressFamily;
|
||||
|
@ -299,6 +303,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
fullUrl = scriptUrl;
|
||||
originalUri = new Uri(fullUrl);
|
||||
|
||||
|
||||
if (scriptIp is not null)
|
||||
{
|
||||
this.logger.Debug("用户脚本指定了服务器 IP {IP}", scriptIp);
|
||||
|
@ -312,6 +317,11 @@ namespace BililiveRecorder.Core.Recording
|
|||
request = new HttpRequestMessage(HttpMethod.Get, builder.Uri);
|
||||
request.Headers.Host = uri.IsDefaultPort ? uri.Host : uri.Host + ":" + uri.Port;
|
||||
|
||||
streamHostInfoBuilder.Append(originalUri.Host);
|
||||
streamHostInfoBuilder.Append(" [");
|
||||
streamHostInfoBuilder.Append(scriptIp);
|
||||
streamHostInfoBuilder.Append("]");
|
||||
|
||||
goto sendRequest;
|
||||
}
|
||||
}
|
||||
|
@ -324,6 +334,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
{
|
||||
this.logger.Debug("NetworkTransportAllowedAddressFamily is System");
|
||||
request = new HttpRequestMessage(HttpMethod.Get, originalUri);
|
||||
|
||||
streamHostInfoBuilder.Append(originalUri.Host);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -341,6 +353,11 @@ namespace BililiveRecorder.Core.Recording
|
|||
|
||||
this.logger.Debug("指定直播服务器地址 {DnsHost}: {SelectedIp}, Allowed: {AllowedAddressFamily}, {IPAddresses}", originalUri.DnsSafeHost, selected, allowedAddressFamily, ips);
|
||||
|
||||
streamHostInfoBuilder.Append(originalUri.Host);
|
||||
streamHostInfoBuilder.Append(" [");
|
||||
streamHostInfoBuilder.Append(selected);
|
||||
streamHostInfoBuilder.Append("]");
|
||||
|
||||
if (selected is null)
|
||||
{
|
||||
throw new Exception("DNS 没有返回符合要求的 IP 地址");
|
||||
|
@ -358,15 +375,16 @@ namespace BililiveRecorder.Core.Recording
|
|||
sendRequest:
|
||||
|
||||
var resp = await client.SendAsync(request,
|
||||
HttpCompletionOption.ResponseHeadersRead,
|
||||
new CancellationTokenSource(timeout).Token)
|
||||
.ConfigureAwait(false);
|
||||
HttpCompletionOption.ResponseHeadersRead,
|
||||
new CancellationTokenSource(timeout).Token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
switch (resp.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.OK:
|
||||
{
|
||||
this.logger.Information("开始接收直播流");
|
||||
this.streamHostFull = streamHostInfoBuilder.ToString();
|
||||
var stream = await resp.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||
return stream;
|
||||
}
|
||||
|
@ -376,6 +394,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
fullUrl = new Uri(originalUri, resp.Headers.Location).ToString();
|
||||
this.logger.Debug("跳转到 {Url}, 原文本 {Location}", fullUrl, resp.Headers.Location.OriginalString);
|
||||
resp.Dispose();
|
||||
streamHostInfoBuilder.Append('\n');
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -233,7 +233,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
$"直播标题: {this.room.Title}\n" +
|
||||
$"直播分区: {this.room.AreaNameParent}·{this.room.AreaNameChild}\n" +
|
||||
$"录制时间: {now:O}\n" +
|
||||
$"服务器: {this.streamHost}\n" +
|
||||
$"直播服务器:\n" +
|
||||
$"{this.streamHostFull}\n" +
|
||||
$"\n" +
|
||||
$"使用 B站录播姬 录制 https://rec.danmuji.org\n" +
|
||||
$"录播姬版本: {GitVersionInformation.FullSemVer}");
|
||||
|
@ -241,6 +242,7 @@ namespace BililiveRecorder.Core.Recording
|
|||
{
|
||||
["RecordedBy"] = (ScriptDataString)"BililiveRecorder B站录播姬",
|
||||
["RecordedFrom"] = (ScriptDataString)(this.streamHost ?? string.Empty),
|
||||
["StreamServers"] = (ScriptDataString)(this.streamHostFull ?? string.Empty),
|
||||
["RecorderVersion"] = (ScriptDataString)GitVersionInformation.InformationalVersion,
|
||||
["StartTime"] = (ScriptDataDate)now,
|
||||
["RoomId"] = (ScriptDataString)this.room.RoomConfig.RoomId.ToString(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user