Skip to content

Commit

Permalink
Merge pull request #298 from hjkl950217/main
Browse files Browse the repository at this point in the history
为HttpClient添加代理并优化部分代码
  • Loading branch information
RayWangQvQ authored Dec 15, 2020
2 parents 8b2eb90 + 92d99e7 commit 41d8fc2
Show file tree
Hide file tree
Showing 38 changed files with 698 additions and 238 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bilibili-daily-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ jobs:
Ray_Serilog:WriteTo:0:Args:restrictedToMinimumLevel: ${{secrets.CONSOLELOGLEVEL}}
Ray_Serilog:WriteTo:0:Args:outputTemplate: ${{secrets.CONSOLELOGTEMPLATE}}
ASPNETCORE_ENVIRONMENT: ${{secrets.ENV}} # 方便切换不同的appsettings文件 也可以在不同的action yml文件中配置来同时运行多个任务
Ray_WebProxy: ${{secrets.PROXY}} # 代理
run: dotnet run -p ./src/Ray.BiliBiliTool.Console -closeConsoleWhenEnd=1 ${{secrets.OTHERCONFIGS}}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,10 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/


#
.idea/
.idea/

/src/Ray.BiliBiliTool.Console/Properties/launchSettings.json
/src/Ray.BiliBiliTool.Console/appsettings.PRD.json

14 changes: 7 additions & 7 deletions Ray.BiliBiliTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastru
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DailyTaskTest", "test\DailyTaskTest\DailyTaskTest.csproj", "{ECDB59B8-DD28-4C0D-8145-13629C3EA3B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetLastDayOfMonthTest", "test\GetLastDayOfMonthTest\GetLastDayOfMonthTest.csproj", "{EF77962E-CE7B-4A12-A4D1-58E70126DE0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ray.BiliBiliTool.Infrastructure", "src\Ray.BiliBiliTool.Infrastructure\Ray.BiliBiliTool.Infrastructure.csproj", "{7188698C-0A9A-43B2-B3E2-5136B14FDE13}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ray.BiliBiliTool.Application", "src\Ray.BiliBiliTool.Application\Ray.BiliBiliTool.Application.csproj", "{3388A58D-91CC-4875-A29F-3E6FC3B44BF5}"
Expand All @@ -46,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InfrastructureTest", "test\InfrastructureTest\InfrastructureTest.csproj", "{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -72,10 +72,6 @@ Global
{ECDB59B8-DD28-4C0D-8145-13629C3EA3B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECDB59B8-DD28-4C0D-8145-13629C3EA3B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECDB59B8-DD28-4C0D-8145-13629C3EA3B1}.Release|Any CPU.Build.0 = Release|Any CPU
{EF77962E-CE7B-4A12-A4D1-58E70126DE0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF77962E-CE7B-4A12-A4D1-58E70126DE0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF77962E-CE7B-4A12-A4D1-58E70126DE0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF77962E-CE7B-4A12-A4D1-58E70126DE0F}.Release|Any CPU.Build.0 = Release|Any CPU
{7188698C-0A9A-43B2-B3E2-5136B14FDE13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7188698C-0A9A-43B2-B3E2-5136B14FDE13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7188698C-0A9A-43B2-B3E2-5136B14FDE13}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -104,6 +100,10 @@ Global
{ECEEFE3F-F39F-44EE-8FA2-D5CDBB25397F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECEEFE3F-F39F-44EE-8FA2-D5CDBB25397F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECEEFE3F-F39F-44EE-8FA2-D5CDBB25397F}.Release|Any CPU.Build.0 = Release|Any CPU
{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -118,14 +118,14 @@ Global
{2039BF6A-5EC4-439C-8D2E-77313075843A} = {E9BDDCBE-A57D-4E3B-8252-708088386ADF}
{110D3D21-8E9B-45AB-9667-6DA1DB3862AC} = {AF21E067-3307-4E7F-8CE8-C695E6B61876}
{ECDB59B8-DD28-4C0D-8145-13629C3EA3B1} = {E9BDDCBE-A57D-4E3B-8252-708088386ADF}
{EF77962E-CE7B-4A12-A4D1-58E70126DE0F} = {E9BDDCBE-A57D-4E3B-8252-708088386ADF}
{7188698C-0A9A-43B2-B3E2-5136B14FDE13} = {110D3D21-8E9B-45AB-9667-6DA1DB3862AC}
{3388A58D-91CC-4875-A29F-3E6FC3B44BF5} = {98051127-2868-4F5C-9B2C-2150975E05F3}
{B6AEDD60-9C06-4391-9171-65EBD5E9D77A} = {98051127-2868-4F5C-9B2C-2150975E05F3}
{D5F9FBCE-31BE-4E80-93E2-183CF029431F} = {120917DC-474C-448B-9EBB-1B3BA3A20B9D}
{191C48BD-5CB5-42CA-B394-7A4A9BFA6275} = {120917DC-474C-448B-9EBB-1B3BA3A20B9D}
{7105652A-B1C1-4F9E-BA38-8034BC8B26B4} = {120917DC-474C-448B-9EBB-1B3BA3A20B9D}
{ECEEFE3F-F39F-44EE-8FA2-D5CDBB25397F} = {E9BDDCBE-A57D-4E3B-8252-708088386ADF}
{AE6A5DBE-E9EA-49C1-AB6C-7F01B2F19A8B} = {E9BDDCBE-A57D-4E3B-8252-708088386ADF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {197319DA-1148-4A99-847C-8B270B6A29AB}
Expand Down
49 changes: 37 additions & 12 deletions src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Dtos/UseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos
/// </summary>
public class UseInfo
{
/// <summary>
/// 是否登录
/// </summary>
public bool IsLogin { get; set; }

/// <summary>
/// 等级信息
/// </summary>
public LevelInfo Level_info { get; set; }

public decimal? Money { get; set; }
Expand All @@ -17,6 +23,10 @@ public class UseInfo

public Wallet Wallet { get; set; }

/// <summary>
/// 会员状态
/// <para>只有VipStatus为1的时候获取到VipType才是有效的</para>
/// </summary>
public int VipStatus { get; set; }

public int VipType { get; set; }//todo:是否可以改为枚举
Expand All @@ -28,8 +38,9 @@ public class UseInfo
public string GetFuzzyUname()
{
StringBuilder sb = new StringBuilder();
int s1 = Uname.Length / 2, s2 = (s1 + 1) / 2;
for (int i = 0; i < Uname.Length; i++)
int s1 = Uname.Length / 2;
int s2 = (s1 + 1) / 2;
for (int i = 0 ; i < Uname.Length ; i++)
{
if (i >= s2 && i < s1 + s2) sb.Append("*");
else sb.Append(Uname[i]);
Expand All @@ -41,15 +52,17 @@ public string GetFuzzyUname()
/// <summary>
/// 返回会员类型
/// </summary>
/// <returns>0:无会员(会员过期、当前不是会员);
/// 1:月会员
/// 2:年会员</returns>
/// <returns>
/// <para> 0:无会员(会员过期、当前不是会员)</para>
/// <para>1:月会员</para>
/// <para>2:年会员</para>
/// </returns>
public int GetVipType()
{
if (this.VipStatus == 1)
if (VipStatus == 1)
{
//只有VipStatus为1的时候获取到VipType才是有效的。
return this.VipType;
return VipType;
}
else
{
Expand All @@ -63,6 +76,9 @@ public int GetVipType()
/// </summary>
public class LevelInfo
{
/// <summary>
/// 当前等级
/// </summary>
public int Current_level { get; set; }

//public long Current_min { get; set; }
Expand All @@ -72,21 +88,30 @@ public class LevelInfo
/// </summary>
public long Current_exp { get; set; }

private string _next_exp;
private long _next_exp;

/// <summary>
/// 下一升级经验值(因为Lv6的大佬会返回字符串“--”,所以这里只能用string接收)
/// 下一升级经验值(因为Lv6的带佬会返回字符串“--”,所以这里只能用string接收)
/// </summary>
public object Next_exp
{
get { return _next_exp; }
set { _next_exp = value.ToString(); }
set
{
bool isLong = long.TryParse(value.ToString(), out long exp);
if (isLong) { _next_exp = exp; }
else _next_exp = long.MinValue;
}
}

/// <summary>
/// 获取下一升级经验值
/// </summary>
/// <returns></returns>
public long GetNext_expLong()
{
if (Current_level == 6) return long.MaxValue;
if (long.TryParse(Next_exp.ToString(), out long result)) return result;
return long.MinValue;
else return _next_exp;
}
}

Expand Down
120 changes: 71 additions & 49 deletions src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Interfaces/IDailyTaskApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,109 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces
/// <summary>
/// BiliBili每日任务相关接口
/// </summary>
public interface IDailyTaskApi : IBiliBiliApi
public interface IDailyTaskApi : IBiliBiliApi, IUserInfoApi, IUserOperationApi
{
//todo:考虑根据领域拆分该接口

/// <summary>
/// 登录
/// 获取某分区下X日内排行榜
/// </summary>
/// <param name="rid"></param>
/// <param name="day"></param>
/// <returns></returns>
[Get("/x/web-interface/nav")]
Task<BiliApiResponse<UseInfo>> LoginByCookie();
[Get("/x/web-interface/ranking/region?rid={rid}&day={day}")]
Task<BiliApiResponse<List<RankingInfo>>> GetRegionRankingVideos(int rid, int day);

/// <summary>
/// 获取每日任务的完成情况
/// 获取指定Up的视频
/// </summary>
/// <param name="upId"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
[Get("/x/member/web/exp/reward")]
Task<BiliApiResponse<DailyTaskInfo>> GetDailyTaskRewardInfo();
[Get("/x/v2/medialist/resource/list?type=1&biz_id={upId}&bvid=&mobi_app=web&ps={pageSize}&direction=false")]
Task<BiliApiResponse<GetVideosResponse>> GetVideosByUpId(long upId, int pageSize);

/// <summary>
/// 获取某分区下X日内排行榜
/// 获取指定Up的视频
/// </summary>
/// <param name="rid"></param>
/// <param name="day"></param>
/// <param name="upId"></param>
/// <param name="pageSize">[1,100]验证不通过接口会报异常</param>
/// <param name="pageNumber"></param>
/// <param name="keyword"></param>
/// <returns></returns>
[Get("/x/web-interface/ranking/region?rid={rid}&day={day}")]
Task<BiliApiResponse<List<RankingInfo>>> GetRegionRankingVideos(int rid, int day);
[Get("/x/space/arc/search?mid={upId}&ps={pageSize}&tid=0&pn={pageNumber}&keyword={keyword}&order=pubdate&jsonp=jsonp")]
Task<BiliApiResponse<SearchUpVideosResponse>> SearchVideosByUpId(long upId, int pageSize = 20, int pageNumber = 1, string keyword = "");

#region 用户信息

/// <summary>
/// 上传视频观看进度
/// 获取每日任务的完成情况
/// </summary>
/// <returns></returns>
[Post("/x/click-interface/web/heartbeat?aid={aid}&played_time={playedTime}")]
Task<BiliApiResponse> UploadVideoHeartbeat(string aid, int playedTime);
[Get("/x/member/web/exp/reward")]
Task<BiliApiResponse<DailyTaskInfo>> GetDailyTaskRewardInfo();

/// <summary>
/// 分享视频
/// 获取通过投币已获取的经验值
/// </summary>
/// <param name="aid"></param>
/// <returns></returns>
[Get("/x/web-interface/coin/today/exp")]
Task<BiliApiResponse<int>> GetDonateCoinExp();

/// <summary>
/// 获取VIP特权
/// </summary>
/// <param name="type"></param>
/// <param name="csrf"></param>
/// <returns></returns>
[Post("/x/web-interface/share/add?aid={aid}&csrf={csrf}")]
Task<BiliApiResponse> ShareVideo(string aid, string csrf);
[Post("/x/vip/privilege/receive?type={type}&csrf={csrf}")]
Task<BiliApiResponse> ReceiveVipPrivilege(int type, string csrf);

/// <summary>
/// 分享视频
/// 获取当前用户对<paramref name="aid"/>视频的投币信息
/// </summary>
/// <param name="aid"></param>
/// <returns></returns>
[Get("/x/web-interface/archive/coins?aid={aid}")]
Task<BiliApiResponse<DonatedCoinsForVideo>> GetDonatedCoinsForVideo(string aid);

#endregion 用户信息

#region 用户操作

/// <summary>
/// 为视频投币
/// </summary>
/// <param name="aid"></param>
/// <param name="multiply"></param>
/// <param name="select_like"></param>
/// <param name="csrf"></param>
/// <returns></returns>
[Post("/x/web-interface/coin/add?aid={aid}&multiply={multiply}&select_like={select_like}&cross_domain=true&csrf={csrf}")]
Task<BiliApiResponse> AddCoinForVideo(string aid, int multiply, int select_like, string csrf);

[Post("/x/vip/privilege/receive?type={type}&csrf={csrf}")]
Task<BiliApiResponse> ReceiveVipPrivilege(int type, string csrf);
/// <summary>
/// 登录
/// </summary>
/// <returns></returns>
[Get("/x/web-interface/nav")]
Task<BiliApiResponse<UseInfo>> LoginByCookie();

/// <summary>
/// 分享视频
/// </summary>
/// <param name="aid"></param>
/// <param name="csrf"></param>
/// <returns></returns>
[Post("/x/web-interface/share/add?aid={aid}&csrf={csrf}")]
Task<BiliApiResponse> ShareVideo(string aid, string csrf);

/// <summary>
/// 上传视频观看进度
/// </summary>
/// <returns></returns>
[Post("/x/click-interface/web/heartbeat?aid={aid}&played_time={playedTime}")]
Task<BiliApiResponse> UploadVideoHeartbeat(string aid, int playedTime);

/// <summary>
/// 充电
Expand All @@ -77,7 +124,7 @@ public interface IDailyTaskApi : IBiliBiliApi
Task<BiliApiResponse<ChargeResponse>> Charge(decimal elec_num, string up_mid, string oid, string csrf);

/// <summary>
/// 充电
/// 充电后留言
/// </summary>
/// <param name="elec_num"></param>
/// <param name="up_mid"></param>
Expand All @@ -87,31 +134,6 @@ public interface IDailyTaskApi : IBiliBiliApi
[Post("/x/ugcpay/trade/elec/message?order_id={order_id}&message={message}&csrf={csrf}")]
Task<BiliApiResponse<ChargeResponse>> ChargeComment(string order_id, string message, string csrf);

/// <summary>
/// 获取指定Up的视频
/// </summary>
/// <param name="upId"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
[Get("/x/v2/medialist/resource/list?type=1&biz_id={upId}&bvid=&mobi_app=web&ps={pageSize}&direction=false")]
Task<BiliApiResponse<GetVideosResponse>> GetVideosByUpId(long upId, int pageSize);

/// <summary>
/// 获取指定Up的视频
/// </summary>
/// <param name="upId"></param>
/// <param name="pageSize">[1,100]验证不通过接口会报异常</param>
/// <param name="pageNumber"></param>
/// <param name="keyword"></param>
/// <returns></returns>
[Get("/x/space/arc/search?mid={upId}&ps={pageSize}&tid=0&pn={pageNumber}&keyword={keyword}&order=pubdate&jsonp=jsonp")]
Task<BiliApiResponse<SearchUpVideosResponse>> SearchVideosByUpId(long upId, int pageSize = 20, int pageNumber = 1, string keyword = "");

/// <summary>
/// 获取通过投币已获取的经验值
/// </summary>
/// <returns></returns>
[Get("/x/web-interface/coin/today/exp")]
Task<BiliApiResponse<int>> GetDonateCoinExp();
#endregion 用户操作
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces
{
/// <summary>
/// 用户信息接口API
/// </summary>
public interface IUserInfoApi
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces
{
/// <summary>
/// 用户操作API
/// </summary>
public interface IUserOperationApi
{
}
}
Loading

0 comments on commit 41d8fc2

Please sign in to comment.