Skip to content

Commit

Permalink
直播间点赞Api相关参数修改,待测试有效性
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris-cn10086 committed Jul 29, 2024
1 parent 6161d06 commit 03b869e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,32 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Live
{
public class LikeLiveRoomRequest
{
public LikeLiveRoomRequest(long roomid, string csrf)
public LikeLiveRoomRequest(long roomid, string csrf, int clickTime, long anchorId, string uid)
{
Roomid = roomid;
Csrf= csrf;
Csrf = csrf;
Click_Time = clickTime;
Anchor_Id = anchorId;
Uid = uid;
}

public long Roomid { get; set; }

public string Csrf { get; set; }

public string Csrf_token => Csrf;
public string Csrf_Token => Csrf;

public int Click_Time { get; set; }

public long Anchor_Id { get; set; }

public string Uid { get; set; }


public string RawTextBuild()
{
return
$"click_time={Click_Time.ToString()}&room_id={Roomid.ToString()}&uid={Uid}&anchor_id={Anchor_Id}&csrf_token={Csrf_Token}&csrf={Csrf}";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public interface ILiveApi : IBiliBiliApi
/// <summary>
/// 点赞直播间
/// </summary>
[HttpPost("/xlive/web-ucenter/v1/interact/likeInteract")]
[HttpPost("/xlive/app-ucenter/v1/like_info_v3/like/likeReportV3")]
[Header("Referer", "https://live.bilibili.com/")]
[Header("Origin", "https://live.bilibili.com")]
Task<BiliApiResponse> LikeLiveRoom([FormContent] LikeLiveRoomRequest request);
}
Task<BiliApiResponse> LikeLiveRoom([RawFormContent] string request);
}
10 changes: 3 additions & 7 deletions src/Ray.BiliBiliTool.Config/Options/LiveFansMedalTaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@ public class LiveFansMedalTaskOptions
/// <summary>
/// 点赞次数
/// </summary>
public int LikeNumber { get; set; } = 55;

/// <summary>
/// 点赞发送失败多少次时放弃
/// </summary>
public int LikeGiveUpThreshold { get; set; } = 5;
public int LikeNumber { get; set; } = 50;

/// <summary>
/// 发送弹幕次数
/// </summary>
public int SendDanmakuNumber { get; set; } = 15;

/// <summary>
/// 弹幕发送失败多少次时放弃
/// </summary>
public int SendDanmakugiveUpThreshold { get; set; } = 5;
}
}
}
47 changes: 23 additions & 24 deletions src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ public async Task SendDanmakuToFansMedalLive()
while (successCount < _liveFansMedalTaskOptions.SendDanmakuNumber &&
failedCount < _liveFansMedalTaskOptions.SendDanmakugiveUpThreshold)
{
await Task.Delay(2000);

var sendResult = await _liveApi.SendLiveDanmuku(new SendLiveDanmukuRequest(
_biliCookie.BiliJct,
spaceInfo.Data.Live_room.Roomid,
Expand All @@ -447,6 +445,9 @@ public async Task SendDanmakuToFansMedalLive()
}
else
successCount++;

var delay = new Random().Next(2000, 4000);
await Task.Delay(delay);
}


Expand Down Expand Up @@ -559,38 +560,36 @@ public async Task SendHeartBeatToFansMedalLive()
_logger.LogInformation("【直播观看时长】完成情况:{success}/{total} ", successCount, infoList.Count);
}

/// <summary>
/// 点赞直播间
/// </summary>
public async Task LikeFansMedalLive()
{
if (!await CheckLiveCookie()) return;

var infoList = await GetFansMedalInfoList();
infoList = infoList.FindAll(info => info.LiveRoomInfo.Live_Status != 1);

infoList = infoList.FindAll(info => info.LiveRoomInfo.Live_Status != 0);
_logger.LogInformation("当前开播直播间数量:{num}", infoList.Count);
foreach (var info in infoList)
{
var successCount = 0;
var failedCount = 0;
while (successCount < _liveFansMedalTaskOptions.LikeNumber &&
failedCount < _liveFansMedalTaskOptions.LikeGiveUpThreshold)
{
var result = await _liveApi.LikeLiveRoom(new LikeLiveRoomRequest(info.RoomId, _biliCookie.BiliJct));
if (result.Code == 0)
{
// _logger.LogInformation("【点赞直播间】{roomId} 完成", info.RoomId);
successCount++;
}
else
{
_logger.LogError("【点赞直播间】{roomId} 时候出现错误", info.RoomId);
_logger.LogError("【原因】{message}", result.Message);
failedCount++;
}
// Clike_Time 暂时设置为等于设置的LikeNumber,不清楚是否会被风控,我自己抓包最大值为10
var request = new LikeLiveRoomRequest(info.RoomId, _biliCookie.BiliJct,
_liveFansMedalTaskOptions.LikeNumber,
info.LiveRoomInfo.Uid, _biliCookie.UserId);

await Task.Delay(500);
var result = await _liveApi.LikeLiveRoom(request.RawTextBuild());
if (result.Code == 0)
{
_logger.LogInformation("【点赞直播间】{roomId} 完成", info.RoomId);
}
else
{
_logger.LogError("【点赞直播间】{roomId} 时候出现错误", info.RoomId);
_logger.LogError("【原因】{message}", result.Message);
}

_logger.LogInformation("【点赞直播间】{romeId}完成情况:{success}/{total}", info.RoomId, successCount,
failedCount + successCount);
var delay = new Random().Next(5000, 8000);
await Task.Delay(delay);
}
}

Expand Down

0 comments on commit 03b869e

Please sign in to comment.