添加 Appid 字段,疑似用户看直播的应用id,按需使用;
进入直播间消息 添加 进入渠道字段`EnterTipType` 已知0为普通进入,6为通过分享进入; User字段新增 `IsAdmin` 和 `IsAnchor` 字段,用于区分是否为管理员或者主播的消息; web在中途监听弹幕,且直播间弹幕链接已降级为轮询的情况下,解决 webroomid 以及房间信息丢失问题; 优化部分已知问题;
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
<!--直播伴侣exe文件位置(除非程序找不到,否则请留空)-->
|
<!--直播伴侣exe文件位置(除非程序找不到,否则请留空)-->
|
||||||
<add key="liveCompanPath" value="" />
|
<add key="liveCompanPath" value="" />
|
||||||
<!--直播伴侣进程代理开关-->
|
<!--直播伴侣进程代理开关-->
|
||||||
<add key="liveCompanHookSwitch" value="true" />
|
<add key="liveCompanHookSwitch" value="false" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Net.Http;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BarrageGrab.Modles;
|
using BarrageGrab.Modles;
|
||||||
|
using BarrageGrab.Modles.ProtoEntity;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Org.BouncyCastle.Asn1.Cmp;
|
using Org.BouncyCastle.Asn1.Cmp;
|
||||||
using Org.BouncyCastle.Asn1.Crmf;
|
using Org.BouncyCastle.Asn1.Crmf;
|
||||||
@@ -55,5 +56,76 @@ namespace BarrageGrab
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取房间信息,通过原生接口
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="webRoomid">web直播间号</param>
|
||||||
|
/// <param name="user">账号凭据</param>
|
||||||
|
/// <param name="proxy">查询代理</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<RoomInfo> GetRoomInfoForApi(string webRoomid, string cookie)
|
||||||
|
{
|
||||||
|
string url = "https://live.douyin.com/webcast/room/web/enter/";
|
||||||
|
|
||||||
|
var client = new HttpClient();
|
||||||
|
|
||||||
|
|
||||||
|
var uri = new UriBuilder(url);
|
||||||
|
var dict = new Dictionary<string, string>();
|
||||||
|
dict.Set("aid", "6383");
|
||||||
|
dict.Set("live_id", "1");
|
||||||
|
dict.Set("app_name", "douyin_web");
|
||||||
|
dict.Set("device_platform", "web");
|
||||||
|
dict.Set("language", "zh-CN");
|
||||||
|
dict.Set("cookie_enabled", "true");
|
||||||
|
dict.Set("enter_from", "page_refresh");
|
||||||
|
dict.Set("web_rid", webRoomid);
|
||||||
|
//dict.Set("room_id_str", roomid);
|
||||||
|
dict.Set("enter_source", "");
|
||||||
|
dict.Set("is_need_double_stream", "false");
|
||||||
|
dict.Set("insert_task_id", "");
|
||||||
|
dict.Set("live_reason", "");
|
||||||
|
dict.Set("browser_language", "zh-CN");
|
||||||
|
dict.Set("browser_platform", "Win32");
|
||||||
|
dict.Set("browser_name", "Edge");
|
||||||
|
dict.Foreach(f => uri.AddQueryParam(f.Key, f.Value));
|
||||||
|
|
||||||
|
url = uri.Uri.ToString();
|
||||||
|
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
request.Headers.Add("Accept", "application/json, text/plain, */*");
|
||||||
|
request.Headers.Add("Cache-Control", "no-cache");
|
||||||
|
request.Headers.Add("Referer", $"https://live.douyin.com/{webRoomid}");
|
||||||
|
request.Headers.Add("Host", "live.douyin.com");
|
||||||
|
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0");
|
||||||
|
request.Headers.Add("Cookie", cookie);
|
||||||
|
|
||||||
|
var rsp = await client.SendAsync(request);
|
||||||
|
if (rsp == null || rsp.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var buff = rsp.Content.ReadAsByteArrayAsync();
|
||||||
|
var result = Encoding.UTF8.GetString(buff.Result);
|
||||||
|
|
||||||
|
var res = RoomInfo.TryParseRoomEnterResponse(result, out var dto);
|
||||||
|
int code = res.Item1;
|
||||||
|
string msg = res.Item2;
|
||||||
|
if (code == 0)
|
||||||
|
{
|
||||||
|
dto.LiveUrl = $"https://live.douyin.com/{webRoomid}";
|
||||||
|
dto.WebRoomId = webRoomid;
|
||||||
|
AppRuntime.RoomCaches.AddRoomInfoCache(dto);
|
||||||
|
Logger.LogInfo($"{dto.Owner.Nickname ?? dto.WebRoomId ?? dto.RoomId} 的直播间信息已添加到缓存");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,6 +194,16 @@ namespace BarrageGrab.Modles.JsonEntity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否是直播间管理员
|
||||||
|
/// </summary>
|
||||||
|
public bool IsAdmin { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否是主播自己
|
||||||
|
/// </summary>
|
||||||
|
public bool IsAnchor { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ShortId
|
/// ShortId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -477,11 +477,9 @@ namespace BarrageGrab.Modles.ProtoEntity
|
|||||||
public PublicAreaCommon publicAreaCommon { get; set; }
|
public PublicAreaCommon publicAreaCommon { get; set; }
|
||||||
|
|
||||||
[global::ProtoBuf.ProtoMember(20)]
|
[global::ProtoBuf.ProtoMember(20)]
|
||||||
[global::System.ComponentModel.DefaultValue("")]
|
|
||||||
public long userEnterTipType { get; set; }
|
public long userEnterTipType { get; set; }
|
||||||
|
|
||||||
[global::ProtoBuf.ProtoMember(21)]
|
[global::ProtoBuf.ProtoMember(21)]
|
||||||
[global::System.ComponentModel.DefaultValue("")]
|
|
||||||
public long anchorEnterTipType { get; set; }
|
public long anchorEnterTipType { get; set; }
|
||||||
|
|
||||||
[global::ProtoBuf.ProtoContract()]
|
[global::ProtoBuf.ProtoContract()]
|
||||||
|
|||||||
@@ -87,6 +87,29 @@ namespace BarrageGrab.Modles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Ttwid { get; set; }
|
public string Ttwid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否是匿名直播间
|
||||||
|
/// </summary>
|
||||||
|
public bool IsAnonymous { get; set; }
|
||||||
|
|
||||||
|
public void SetData(JObject room)
|
||||||
|
{
|
||||||
|
this.RoomId = room["id_str"]?.ToString() ?? "";
|
||||||
|
this.AdminUserIds = room["admin_user_ids_str"]?.Values<string>().ToList() ?? new List<string>();
|
||||||
|
this.IsLive = room["status"]?.Value<int>() == 2;
|
||||||
|
this.IsAnonymous = room["live_room_mode"]?.Value<int>() == 1;
|
||||||
|
this.Title = room["title"]?.ToString() ?? "";
|
||||||
|
this.UserCount = long.Parse(room["room_view_stats"]?["display_value"]?.Value<string>() ?? "0");
|
||||||
|
this.TotalUserCount = room["room_view_stats"]?["total_user_str"]?.Value<string>() ?? "0";
|
||||||
|
this.LikeCount = room["like_count"]?.Value<long>() ?? 0;
|
||||||
|
//this.QrcodeUrl = rootData["qrcode_url"]?.ToString() ?? "";
|
||||||
|
this.AuthInfo = room["room_auth"]?.ToObject<RoomInfo.RoomAuth>();
|
||||||
|
this.Cover = room["cover"]?["url_list"]?.Values<string>().FirstOrDefault() ?? "";//下播情况下没有cover字段
|
||||||
|
|
||||||
|
this.AuthInfo = room["room_auth"]?.ToObject<RoomInfo.RoomAuth>();
|
||||||
|
this.Cover = room["cover"]?["url_list"]?.Values<string>().FirstOrDefault() ?? "";//下播情况下没有cover字段
|
||||||
|
}
|
||||||
|
|
||||||
public class RoomAnchor
|
public class RoomAnchor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -641,5 +664,58 @@ namespace BarrageGrab.Modles
|
|||||||
|
|
||||||
return Tuple.Create(0, "succ");
|
return Tuple.Create(0, "succ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 EnterRoom Response 转为房间信息对象
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Tuple<int, string> TryParseRoomEnterResponse(string response, out RoomInfo info)
|
||||||
|
{
|
||||||
|
info = null;
|
||||||
|
JObject res;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res = JsonConvert.DeserializeObject<JObject>(response);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return Tuple.Create(4, "不是合法的json格式");
|
||||||
|
}
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
return Tuple.Create(1, "响应内容为空");
|
||||||
|
}
|
||||||
|
if (res["status_code"]?.Value<int>() != 0)
|
||||||
|
{
|
||||||
|
return Tuple.Create(2, (res["status_msg"]?.ToString() ?? "响应状态失败"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomInfos = res["data"]?["data"]?.Values<JToken>().ToArray();
|
||||||
|
if (roomInfos == null || roomInfos.Length == 0) return Tuple.Create(3, "房间信息列表为空");
|
||||||
|
var rootData = res["data"];
|
||||||
|
var room = roomInfos[0]?.ToObject<JObject>();
|
||||||
|
var roomOwner = rootData?["user"] ?? room?["owner"];
|
||||||
|
|
||||||
|
var dto = new RoomInfo();
|
||||||
|
dto.SetData(room);
|
||||||
|
dto.QrcodeUrl = rootData["qrcode_url"]?.ToString() ?? "";
|
||||||
|
if (roomOwner != null)
|
||||||
|
{
|
||||||
|
dto.Owner = new RoomInfo.RoomAnchor()
|
||||||
|
{
|
||||||
|
UserId = roomOwner["id_str"].ToString(),
|
||||||
|
Nickname = roomOwner["nickname"].ToString(),
|
||||||
|
SecUid = roomOwner["sec_uid"].ToString(),
|
||||||
|
HeadUrl = roomOwner["avatar_thumb"]["url_list"].Values<string>()?.FirstOrDefault() ?? "",
|
||||||
|
FollowStatus = roomOwner["follow_info"]["follow_status"].Value<int>()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
info = dto;
|
||||||
|
return Tuple.Create(0, "succ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,5 +319,44 @@ namespace BarrageGrab
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Uri查询参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uri"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
public static IDictionary<string, string> GetQueryParams(this Uri uri)
|
||||||
|
{
|
||||||
|
if (uri == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryParams = uri.Query.TrimStart('?');
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(queryParams))
|
||||||
|
{
|
||||||
|
return new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryParams
|
||||||
|
.Split('&')
|
||||||
|
.Select(param => param.Split('='))
|
||||||
|
.ToDictionary(
|
||||||
|
keyValuePair => Uri.UnescapeDataString(keyValuePair[0]),
|
||||||
|
keyValuePair => Uri.UnescapeDataString(keyValuePair.Length > 1 ? keyValuePair[1] : ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取Uri查询参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uri"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetQueryParam(this Uri uri, string key)
|
||||||
|
{
|
||||||
|
return uri.GetQueryParams().Where(w => w.Key == key).Select(s => s.Value).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ using System.Net.Http;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using BrotliSharpLib;
|
using BrotliSharpLib;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Security.Policy;
|
||||||
|
using NLog.LayoutRenderers;
|
||||||
|
|
||||||
namespace BarrageGrab.Proxy
|
namespace BarrageGrab.Proxy
|
||||||
{
|
{
|
||||||
@@ -31,6 +34,7 @@ namespace BarrageGrab.Proxy
|
|||||||
ProxyServer proxyServer = null;
|
ProxyServer proxyServer = null;
|
||||||
ExplicitProxyEndPoint explicitEndPoint = null;
|
ExplicitProxyEndPoint explicitEndPoint = null;
|
||||||
ExternalProxy upStreamProxy = null;
|
ExternalProxy upStreamProxy = null;
|
||||||
|
List<string> rinfoRequestings = new List<string>();
|
||||||
|
|
||||||
const string SCRIPT_HOST = "lf-cdn-tos.bytescm.com";
|
const string SCRIPT_HOST = "lf-cdn-tos.bytescm.com";
|
||||||
const string LIVE_HOST = "live.douyin.com";
|
const string LIVE_HOST = "live.douyin.com";
|
||||||
@@ -39,6 +43,7 @@ namespace BarrageGrab.Proxy
|
|||||||
const string BARRAGE_POOL_PATH = "/webcast/im/fetch";
|
const string BARRAGE_POOL_PATH = "/webcast/im/fetch";
|
||||||
const string LIVE_SCRIPT_PATH = "/obj/static/webcast/douyin_live";
|
const string LIVE_SCRIPT_PATH = "/obj/static/webcast/douyin_live";
|
||||||
const string WEBCAST_AMEMV_HOST = "webcast.amemv.com";
|
const string WEBCAST_AMEMV_HOST = "webcast.amemv.com";
|
||||||
|
private readonly Regex webcastBarrageReg = new Regex(@"webcast\d+-ws-web-\w+\.(douyin|amemv)\.com");
|
||||||
|
|
||||||
public override string HttpUpstreamProxy { get { return proxyServer?.UpStreamHttpProxy?.ToString() ?? ""; } }
|
public override string HttpUpstreamProxy { get { return proxyServer?.UpStreamHttpProxy?.ToString() ?? ""; } }
|
||||||
|
|
||||||
@@ -97,6 +102,7 @@ namespace BarrageGrab.Proxy
|
|||||||
proxyServer.CertificateManager.TrustRootCertificate(true);
|
proxyServer.CertificateManager.TrustRootCertificate(true);
|
||||||
|
|
||||||
proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback;
|
proxyServer.ServerCertificateValidationCallback += ProxyServer_ServerCertificateValidationCallback;
|
||||||
|
proxyServer.BeforeRequest += ProxyServer_BeforeRequest;
|
||||||
proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
|
proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
|
||||||
//proxyServer.AfterResponse += ProxyServer_AfterResponse;
|
//proxyServer.AfterResponse += ProxyServer_AfterResponse;
|
||||||
|
|
||||||
@@ -192,6 +198,24 @@ namespace BarrageGrab.Proxy
|
|||||||
return AppSetting.Current.ProcessFilter.Contains(processName) && processName != "直播伴侣" && processName != "douyin";
|
return AppSetting.Current.ProcessFilter.Contains(processName) && processName != "直播伴侣" && processName != "douyin";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
|
||||||
|
{
|
||||||
|
string uri = e.HttpClient.Request.RequestUri.ToString();
|
||||||
|
string hostname = e.HttpClient.Request.RequestUri.Host;
|
||||||
|
var processid = e.HttpClient.ProcessId.Value;
|
||||||
|
var processName = base.GetProcessName(processid);
|
||||||
|
var contentType = e.HttpClient.Response.ContentType ?? "";
|
||||||
|
|
||||||
|
//ws 方式
|
||||||
|
if (
|
||||||
|
e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket &&
|
||||||
|
webcastBarrageReg.IsMatch(uri)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e)
|
private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e)
|
||||||
{
|
{
|
||||||
string uri = e.HttpClient.Request.RequestUri.ToString();
|
string uri = e.HttpClient.Request.RequestUri.ToString();
|
||||||
@@ -266,20 +290,55 @@ namespace BarrageGrab.Proxy
|
|||||||
var processid = e.HttpClient.ProcessId.Value;
|
var processid = e.HttpClient.ProcessId.Value;
|
||||||
var processName = base.GetProcessName(processid);
|
var processName = base.GetProcessName(processid);
|
||||||
var contentType = e.HttpClient.Response.ContentType ?? "";
|
var contentType = e.HttpClient.Response.ContentType ?? "";
|
||||||
|
var isLiveCompan = processName == "直播伴侣";
|
||||||
|
|
||||||
//ws 方式
|
//ws 方式
|
||||||
if (
|
if (
|
||||||
e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket &&
|
e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket &&
|
||||||
hostname.StartsWith("webcast")
|
webcastBarrageReg.IsMatch(uri)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
e.DataReceived += WebSocket_DataReceived;
|
e.DataReceived += WebSocket_DataReceived;
|
||||||
|
var urix = new Uri(uri);
|
||||||
|
var roomid = urix.GetQueryParam("room_id");
|
||||||
|
Logger.LogInfo($"订阅到新的弹幕流地址,roomid:{roomid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
//轮询方式(当抖音ws连接断开后,客户端也会降级使用轮询模式获取弹幕)
|
//轮询方式(当抖音ws连接断开后,客户端也会降级使用轮询模式获取弹幕)
|
||||||
if (uri.Contains(BARRAGE_POOL_PATH) && contentType.Contains("application/protobuffer"))
|
if (uri.Contains(BARRAGE_POOL_PATH) && contentType.Contains("application/protobuffer"))
|
||||||
{
|
{
|
||||||
var payload = await e.GetResponseBody();
|
var payload = await e.GetResponseBody();
|
||||||
|
|
||||||
|
var referrer = e.HttpClient.Request.Headers.GetFirstHeader("Referer")?.Value;
|
||||||
|
//https://live.douyin.com/22404217360
|
||||||
|
|
||||||
|
//检查webroomid映射
|
||||||
|
if (!referrer.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
var webroomid = Regex.Match(referrer, @"(?<=live\.douyin\.com\/)\d+").Value;
|
||||||
|
var urix = new Uri(uri);
|
||||||
|
var roomid = urix.GetQueryParam("room_id");
|
||||||
|
var cookie = e.HttpClient.Request.Headers.GetFirstHeader("Cookie")?.Value;
|
||||||
|
|
||||||
|
var roomInfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(roomid);
|
||||||
|
if (roomInfo == null && cookie != null && !rinfoRequestings.Contains(webroomid))
|
||||||
|
{
|
||||||
|
lock (rinfoRequestings) rinfoRequestings.Add(webroomid);
|
||||||
|
//查询后会自动缓存
|
||||||
|
DyServer.GetRoomInfoForApi(webroomid, cookie).ContinueWith(t =>
|
||||||
|
{
|
||||||
|
var rinfo = t.Result;
|
||||||
|
//限制只尝试一次
|
||||||
|
if (rinfo != null)
|
||||||
|
{
|
||||||
|
lock (rinfoRequestings) rinfoRequestings.Remove(webroomid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AppRuntime.RoomCaches.SetRoomCache(roomid, webroomid);
|
||||||
|
}
|
||||||
|
|
||||||
base.FireOnFetchResponse(new HttpResponseEventArgs()
|
base.FireOnFetchResponse(new HttpResponseEventArgs()
|
||||||
{
|
{
|
||||||
HttpClient = e.HttpClient,
|
HttpClient = e.HttpClient,
|
||||||
@@ -358,7 +417,7 @@ namespace BarrageGrab.Proxy
|
|||||||
|
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
{
|
{
|
||||||
Logger.LogInfo($"直播页{webrid}房间信息已采集到缓存");
|
Logger.LogInfo($"直播页{webrid} [{roominfo.Owner.Nickname}]的直播间,房间信息已采集到缓存");
|
||||||
roominfo.WebRoomId = webrid;
|
roominfo.WebRoomId = webrid;
|
||||||
roominfo.LiveUrl = url;
|
roominfo.LiveUrl = url;
|
||||||
AppRuntime.RoomCaches.AddRoomInfoCache(roominfo);
|
AppRuntime.RoomCaches.AddRoomInfoCache(roominfo);
|
||||||
@@ -565,6 +624,16 @@ namespace BarrageGrab.Proxy
|
|||||||
string hostname = e.HttpClient.Request.RequestUri.Host;
|
string hostname = e.HttpClient.Request.RequestUri.Host;
|
||||||
|
|
||||||
e.DecryptSsl = CheckHost(hostname);
|
e.DecryptSsl = CheckHost(hostname);
|
||||||
|
|
||||||
|
|
||||||
|
//ws 方式
|
||||||
|
//if (
|
||||||
|
// e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Websocket &&
|
||||||
|
// webcastBarrageReg.IsMatch(url)
|
||||||
|
// )
|
||||||
|
//{
|
||||||
|
// e.HttpClient.Request.RequestUri = new Uri("wss:////localhost:8828");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
//检测域名白名单
|
//检测域名白名单
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ using BarrageGrab.Modles.JsonEntity;
|
|||||||
using BarrageGrab.Modles.ProtoEntity;
|
using BarrageGrab.Modles.ProtoEntity;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Dynamic;
|
||||||
|
using static BarrageGrab.Modles.ProtoEntity.Image;
|
||||||
|
using static BarrageGrab.Modles.WebCastGift;
|
||||||
|
|
||||||
namespace BarrageGrab
|
namespace BarrageGrab
|
||||||
{
|
{
|
||||||
@@ -163,13 +166,68 @@ namespace BarrageGrab
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检查属性定义
|
||||||
|
private bool HasProperty(dynamic obj, string propertyName)
|
||||||
|
{
|
||||||
|
if (obj is ExpandoObject)
|
||||||
|
{
|
||||||
|
return ((IDictionary<string, object>)obj).ContainsKey(propertyName);
|
||||||
|
}
|
||||||
|
return obj.GetType().GetProperty(propertyName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private T CreateMsg<T>(dynamic msg) where T : Msg, new()
|
||||||
|
{
|
||||||
|
var roomid = msg.Common.roomId.ToString();
|
||||||
|
RoomInfo roomInfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(roomid);
|
||||||
|
|
||||||
|
//判断 Common 属性是否存在
|
||||||
|
var hasUser = HasProperty(msg, nameof(msg.User));
|
||||||
|
|
||||||
|
var enty = new T()
|
||||||
|
{
|
||||||
|
MsgId = msg.Common?.msgId,
|
||||||
|
RoomId = roomid,
|
||||||
|
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(roomid),
|
||||||
|
Appid = msg.Common.appId.ToString(),
|
||||||
|
User = hasUser ? GetUser(msg.User) : null,
|
||||||
|
};
|
||||||
|
|
||||||
|
//判断是否是直播间管理员
|
||||||
|
if (enty.User != null && roomInfo != null && roomInfo.AdminUserIds.Any())
|
||||||
|
{
|
||||||
|
enty.User.IsAdmin = roomInfo.AdminUserIds.Contains(enty.User.Id.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否是主播
|
||||||
|
if (enty.User != null && roomInfo != null && roomInfo.Owner != null)
|
||||||
|
{
|
||||||
|
enty.User.IsAnchor = enty.User.Id.ToString() == roomInfo.Owner.UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return enty;
|
||||||
|
}
|
||||||
|
|
||||||
//打印消息
|
//打印消息
|
||||||
private void PrintMsg(Msg msg, PackMsgType barType)
|
private void PrintMsg(Msg msg, PackMsgType barType)
|
||||||
{
|
{
|
||||||
var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
var rinfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
||||||
var roomName = (rinfo?.Owner?.Nickname ?? ((msg.WebRoomId.IsNullOrWhiteSpace() ? msg.RoomId.ToString() : msg.WebRoomId)));
|
var roomName = (rinfo?.Owner?.Nickname ?? ((msg.WebRoomId.IsNullOrWhiteSpace() ? msg.RoomId.ToString() : msg.WebRoomId)));
|
||||||
|
var isAdmin = msg.User != null && msg.User.IsAdmin;
|
||||||
|
var isAnchor = msg.User != null && msg.User.IsAnchor;
|
||||||
|
|
||||||
var text = $"{DateTime.Now.ToString("HH:mm:ss")} [{roomName}] [{barType}]";
|
var text = $"{DateTime.Now.ToString("HH:mm:ss")} [{roomName}] [{barType}]";
|
||||||
|
|
||||||
|
if (isAdmin)
|
||||||
|
{
|
||||||
|
text+= " [管理员]";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isAnchor)
|
||||||
|
{
|
||||||
|
text += " [主播]";
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.User != null)
|
if (msg.User != null)
|
||||||
{
|
{
|
||||||
text += $" [{msg.User?.GenderToString()}] ";
|
text += $" [{msg.User?.GenderToString()}] ";
|
||||||
@@ -228,7 +286,7 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
if (msg == null) return;
|
if (msg == null) return;
|
||||||
var roomInfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
var roomInfo = AppRuntime.RoomCaches.GetCachedWebRoomInfo(msg.RoomId.ToString());
|
||||||
if (roomInfo != null)
|
if (roomInfo != null && roomInfo.Owner!=null)
|
||||||
{
|
{
|
||||||
msg.Onwer = new RoomAnchorInfo()
|
msg.Onwer = new RoomAnchorInfo()
|
||||||
{
|
{
|
||||||
@@ -247,16 +305,10 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
var enty = new FansclubMsg()
|
var enty = CreateMsg<FansclubMsg>(msg);
|
||||||
{
|
|
||||||
MsgId = msg.Common.msgId,
|
enty.Content = msg.Content;
|
||||||
Content = msg.Content,
|
enty.Type = msg.Type;
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
Appid = e.Message.Common.appId.ToString(),
|
|
||||||
Type = msg.Type,
|
|
||||||
User = GetUser(msg.User)
|
|
||||||
};
|
|
||||||
enty.Level = enty.User.FansClub.Level;
|
enty.Level = enty.User.FansClub.Level;
|
||||||
|
|
||||||
var msgType = PackMsgType.粉丝团消息;
|
var msgType = PackMsgType.粉丝团消息;
|
||||||
@@ -271,19 +323,13 @@ namespace BarrageGrab
|
|||||||
{
|
{
|
||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
var enty = new UserSeqMsg()
|
|
||||||
{
|
var enty = CreateMsg<UserSeqMsg>(msg);
|
||||||
MsgId = msg.Common.msgId,
|
enty.OnlineUserCount = msg.Total;
|
||||||
OnlineUserCount = msg.Total,
|
enty.TotalUserCount = msg.totalUser;
|
||||||
TotalUserCount = msg.totalUser,
|
enty.TotalUserCountStr = msg.totalPvForAnchor;
|
||||||
TotalUserCountStr = msg.totalPvForAnchor,
|
enty.OnlineUserCountStr = msg.onlineUserForAnchor;
|
||||||
OnlineUserCountStr = msg.onlineUserForAnchor,
|
enty.Content = $"当前直播间人数 {msg.onlineUserForAnchor},累计直播间人数 {msg.totalPvForAnchor}";
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
Content = $"当前直播间人数 {msg.onlineUserForAnchor},累计直播间人数 {msg.totalPvForAnchor}",
|
|
||||||
Appid = e.Message.Common.appId.ToString(),
|
|
||||||
User = null
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.直播间统计;
|
var msgType = PackMsgType.直播间统计;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
@@ -353,24 +399,17 @@ namespace BarrageGrab
|
|||||||
|
|
||||||
var count = currCount - lastCount;
|
var count = currCount - lastCount;
|
||||||
|
|
||||||
var enty = new GiftMsg()
|
var enty = CreateMsg<GiftMsg>(msg);
|
||||||
{
|
enty.Content = $"{msg.User.Nickname} 送出 {msg.Gift.Name}{(msg.Gift.Combo ? "(可连击)" : "")} x {msg.repeatCount}个,增量{count}个";
|
||||||
MsgId = msg.Common.msgId,
|
enty.DiamondCount = msg.Gift.diamondCount;
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
enty.RepeatCount = msg.repeatCount;
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
enty.GiftCount = count;
|
||||||
Content = $"{msg.User.Nickname} 送出 {msg.Gift.Name}{(msg.Gift.Combo ? "(可连击)" : "")} x {msg.repeatCount}个,增量{count}个",
|
enty.GroupId = msg.groupId;
|
||||||
DiamondCount = msg.Gift.diamondCount,
|
enty.GiftId = msg.giftId;
|
||||||
RepeatCount = msg.repeatCount,
|
enty.GiftName = msg.Gift.Name;
|
||||||
GiftCount = count,
|
enty.Combo = msg.Gift.Combo;
|
||||||
GroupId = msg.groupId,
|
enty.ImgUrl = msg.Gift.Image?.urlLists?.FirstOrDefault() ?? "";
|
||||||
GiftId = msg.giftId,
|
enty.ToUser = GetUser(msg.toUser);
|
||||||
GiftName = msg.Gift.Name,
|
|
||||||
Combo = msg.Gift.Combo,
|
|
||||||
ImgUrl = msg.Gift.Image?.urlLists?.FirstOrDefault() ?? "",
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
ToUser = GetUser(msg.toUser),
|
|
||||||
Appid = e.Message.Common.appId.ToString()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (enty.ToUser != null)
|
if (enty.ToUser != null)
|
||||||
{
|
{
|
||||||
@@ -391,15 +430,8 @@ namespace BarrageGrab
|
|||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
if (msg.Action != 1) return;
|
if (msg.Action != 1) return;
|
||||||
var enty = new Msg()
|
var enty = CreateMsg<Msg>(msg);
|
||||||
{
|
enty.Content = $"{msg.User.Nickname} 关注了主播";
|
||||||
MsgId = msg.Common.msgId,
|
|
||||||
Content = $"{msg.User.Nickname} 关注了主播",
|
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
Appid = e.Message.Common.appId.ToString()
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.关注消息;
|
var msgType = PackMsgType.关注消息;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
@@ -422,16 +454,9 @@ namespace BarrageGrab
|
|||||||
type = (ShareType)int.Parse(msg.shareTarget);
|
type = (ShareType)int.Parse(msg.shareTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
var enty = new ShareMessage()
|
var enty = CreateMsg<ShareMessage>(msg);
|
||||||
{
|
enty.Content = $"{msg.User.Nickname} 分享了直播间到{type}";
|
||||||
MsgId = msg.Common.msgId,
|
enty.ShareType = type;
|
||||||
Content = $"{msg.User.Nickname} 分享了直播间到{type}",
|
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
ShareType = type,
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
Appid = e.Message.Common.appId.ToString()
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.直播间分享;
|
var msgType = PackMsgType.直播间分享;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
@@ -450,17 +475,11 @@ namespace BarrageGrab
|
|||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
|
|
||||||
var enty = new Modles.JsonEntity.MemberMessage()
|
var enterType = e.Message.userEnterTipType;
|
||||||
{
|
var enty = CreateMsg<Modles.JsonEntity.MemberMessage>(msg);
|
||||||
MsgId = msg.Common.msgId,
|
enty.Content = $"{msg.User.Nickname} ${(enterType == 6 ? " 通过分享" : "")}来了 直播间人数:{msg.memberCount}";
|
||||||
Content = $"{msg.User.Nickname}${(e.Message.userEnterTipType==6?" 通过分享":"")} 来了 直播间人数:{msg.memberCount}",
|
enty.CurrentCount = msg.memberCount;
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
enty.EnterTipType = enterType;
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
CurrentCount = msg.memberCount,
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
Appid = e.Message.Common.appId.ToString(),
|
|
||||||
EnterTipType = e.Message.userEnterTipType,
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.进直播间;
|
var msgType = PackMsgType.进直播间;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
@@ -477,17 +496,10 @@ namespace BarrageGrab
|
|||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
|
|
||||||
var enty = new LikeMsg()
|
var enty = CreateMsg<LikeMsg>(msg);
|
||||||
{
|
enty.Total = msg.Total;
|
||||||
MsgId = msg.Common.msgId,
|
enty.Count = msg.Count;
|
||||||
Count = msg.Count,
|
enty.Content = $"{msg.User.Nickname} 为主播点了{msg.Count}个赞,总点赞{msg.Total}";
|
||||||
Content = $"{msg.User.Nickname} 为主播点了{msg.Count}个赞,总点赞{msg.Total}",
|
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
Total = msg.Total,
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
Appid = e.Message.Common.appId.ToString()
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.点赞消息;
|
var msgType = PackMsgType.点赞消息;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
@@ -503,15 +515,8 @@ namespace BarrageGrab
|
|||||||
var msg = e.Message;
|
var msg = e.Message;
|
||||||
if (!CheckRoomId(msg.Common.roomId)) return;
|
if (!CheckRoomId(msg.Common.roomId)) return;
|
||||||
|
|
||||||
var enty = new Msg()
|
var enty = CreateMsg<Msg>(msg);
|
||||||
{
|
enty.Content = msg.Content;
|
||||||
MsgId = msg.Common.msgId,
|
|
||||||
Content = msg.Content,
|
|
||||||
RoomId = msg.Common.roomId.ToString(),
|
|
||||||
WebRoomId = AppRuntime.RoomCaches.GetCachedWebRoomid(msg.Common.roomId.ToString()),
|
|
||||||
User = GetUser(msg.User),
|
|
||||||
Appid = e.Message.Common.appId.ToString()
|
|
||||||
};
|
|
||||||
|
|
||||||
var msgType = PackMsgType.弹幕消息;
|
var msgType = PackMsgType.弹幕消息;
|
||||||
AttachRoomInfo(enty);
|
AttachRoomInfo(enty);
|
||||||
|
|||||||
Reference in New Issue
Block a user