Skip to content

Commit

Permalink
增加漫游功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyaocz committed Apr 14, 2022
1 parent 1f27aa9 commit 4764cbd
Show file tree
Hide file tree
Showing 47 changed files with 543 additions and 14,188 deletions.
9 changes: 7 additions & 2 deletions BiliLite.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
# Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BiliLite", "BiliLite\BiliLite.csproj", "{8B90B3B3-844B-4610-9DCF-C9B250182AE3}"
EndProject
Expand All @@ -13,6 +13,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiTester", "ApiTester\ApiT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiliLite.gRPC", "BiliLite.gRPC\BiliLite.gRPC.csproj", "{AEE3DCAA-2C3C-4308-B602-4797994219D7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{30AD97ED-AD18-4F64-8D4C-D326B3AB100D}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions BiliLite/Api/AccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public ApiModel History(int pn=1,int ps=24)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = "https://api.bilibili.com/x/v2/history",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/history",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&pn={pn}&ps={ps}"
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidKey);
Expand All @@ -211,7 +211,7 @@ public ApiModel DelHistory(string id)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = "https://api.bilibili.com/x/v2/history/delete",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/history/delete",
body = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&kid={id}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidKey);
Expand Down
25 changes: 22 additions & 3 deletions BiliLite/Api/ApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ namespace BiliLite.Api
public static class ApiHelper
{
//public static string baseUrl = "http://localhost:5000";
public static string baseUrl = "http://biliapi.iliili.cn";
public const string IL_BASE_URL = "http://biliapi.iliili.cn";
public const string API_BASE_URL = "https://api.bilibili.com";
//漫游默认的服务器
public const string ROMAING_PROXY_URL = "https://bp.nsapps.cn";

// 详情页使用的代理
public static string[] DETAIL_PROXY_URL =new string[] { "https://bp.nsapps.cn", "https://biliproxy.iill.moe", "https://service-k02mde2w-1251411860.hk.apigw.tencentcs.com" };


public static ApiKeyInfo AndroidKey = new ApiKeyInfo("1d8b6e7d45233436", "560c52ccd288fed045859ed18bffd973");
public static ApiKeyInfo AndroidVideoKey = new ApiKeyInfo("iVGUTjsxvpLeuDCf", "aHRmhWMLkdeMuILqORnYZocwMBpMEOdt");
public static ApiKeyInfo WebVideoKey = new ApiKeyInfo("84956560bc028eb7", "94aba54af9065f71de72f5508f1cd42e");
Expand All @@ -20,7 +28,7 @@ public static class ApiHelper
private const string _mobi_app = "android";
private const string _platform = "android";
public static string deviceId = "";
public static string GetSign(string url, ApiKeyInfo apiKeyInfo,string par= "&sign=")
public static string GetSign(string url, ApiKeyInfo apiKeyInfo, string par = "&sign=")
{
string result;
string str = url.Substring(url.IndexOf("?", 4) + 1);
Expand All @@ -36,7 +44,7 @@ public static string GetSign(string url, ApiKeyInfo apiKeyInfo,string par= "&sig
result = Utils.ToMD5(stringBuilder.ToString()).ToLower();
return par + result;
}

public static string GetSign(IDictionary<string, string> pars, ApiKeyInfo apiKeyInfo)
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -77,6 +85,17 @@ public static IDictionary<string, string> GetDefaultHeaders()
headers.Add("Referer", "https://www.bilibili.com/");
return headers;
}

/// <summary>
/// 随机返回一个详情代理服务器
/// 伪负载均衡?
/// </summary>
/// <returns></returns>
public static string RandomProxyUrl()
{
var rnd=new Random().Next(0, DETAIL_PROXY_URL.Length);
return DETAIL_PROXY_URL[rnd];
}
}
public class ApiKeyInfo
{
Expand Down
12 changes: 6 additions & 6 deletions BiliLite/Api/CommentApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ApiModel Comment(string oid, commentSort sort,int pn, int type, int ps =
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/v2/reply",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&plat=2&pn={pn}&ps={ps}&sort={(int)sort}&type={type}"
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidKey);
Expand All @@ -48,7 +48,7 @@ public ApiModel Reply(string oid,string root, int pn, int type, int ps = 30)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/v2/reply/reply",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply/reply",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&plat=2&pn={pn}&ps={ps}&root={root}&type={type}"
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidKey);
Expand All @@ -60,7 +60,7 @@ public ApiModel Like(string oid, string root, int action, int type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/reply/action",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply/action",
body = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&rpid={root}&action={action}&type={type}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidKey);
Expand All @@ -72,7 +72,7 @@ public ApiModel ReplyComment(string oid, string root, string parent, string mess
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/reply/add",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply/add",
body = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&root={root}&parent={parent}&type={type}&message={message}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidKey);
Expand All @@ -83,7 +83,7 @@ public ApiModel DeleteComment(string oid, string rpid, int type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/reply/del",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply/del",
body = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&rpid={rpid}&type={type}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidKey);
Expand All @@ -94,7 +94,7 @@ public ApiModel AddComment(string oid, CommentType type,string message)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/reply/add",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/reply/add",
body = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&oid={oid}&type={(int)type}&message={Uri.EscapeDataString(message)}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidKey);
Expand Down
2 changes: 1 addition & 1 deletion BiliLite/Api/EmoteApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ApiModel UserEmote(EmoteBusiness business)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/emote/user/panel/web",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/emote/user/panel/web",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&business={type}"
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidKey);
Expand Down
8 changes: 4 additions & 4 deletions BiliLite/Api/Home/AnimeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ApiModel BangumiHome()
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/anime/bangumi"
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/anime/bangumi"
};
return api;
}
Expand All @@ -25,7 +25,7 @@ public ApiModel GuochuangHome()
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/anime/guochuang"
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/anime/guochuang"
};
return api;
}
Expand All @@ -34,7 +34,7 @@ public ApiModel Timeline(int type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/anime/timeline",
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/anime/timeline",
parameter="type="+ type
};
return api;
Expand All @@ -44,7 +44,7 @@ public ApiModel AnimeFallMore(int wid, long cursor = 0)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/anime/bangumiFalls",
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/anime/bangumiFalls",
parameter= $"wid={wid}&cursor={cursor}"
};
return api;
Expand Down
4 changes: 2 additions & 2 deletions BiliLite/Api/Home/CinemaAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ApiModel CinemaHome()
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/cinema/home"
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/cinema/home"
};
return api;
}
Expand All @@ -22,7 +22,7 @@ public ApiModel CinemaFallMore(int wid, long cursor = 0)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"{ApiHelper.baseUrl}/api/cinema/falls",
baseUrl = $"{ApiHelper.IL_BASE_URL}/api/cinema/falls",
parameter = $"wid={wid}&cursor={cursor}"
};
return api;
Expand Down
37 changes: 24 additions & 13 deletions BiliLite/Api/PlayerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ namespace BiliLite.Api
{
public class PlayerAPI
{
public ApiModel VideoPlayUrl(string aid, string cid, int qn,bool dash)
public ApiModel VideoPlayUrl(string aid, string cid, int qn,bool dash,bool proxy=false)
{
var baseUrl = ApiHelper.API_BASE_URL;
var proxyUrl = SettingHelper.GetValue(SettingHelper.Roaming.CUSTOM_SERVER_URL, ApiHelper.ROMAING_PROXY_URL);
if (proxy)
{
baseUrl = proxyUrl;
}
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/player/playurl",
baseUrl = $"{baseUrl}/x/player/playurl",
parameter = ApiHelper.MustParameter(ApiHelper.WebVideoKey, true) + $"&avid={aid}&cid={cid}&qn={qn}&type=&otype=json&mid={(SettingHelper.Account.Logined? SettingHelper.Account.Profile.mid.ToString():"")}"
};
if (dash)
Expand All @@ -24,13 +30,18 @@ public ApiModel VideoPlayUrl(string aid, string cid, int qn,bool dash)
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.WebVideoKey);
return api;
}
public ApiModel SeasonPlayUrl(string aid, string cid, int qn,int season_type, bool dash)
public ApiModel SeasonPlayUrl(string aid, string cid, int qn,int season_type, bool dash, bool proxy = false)
{
var baseUrl = ApiHelper.API_BASE_URL;
var proxyUrl = SettingHelper.GetValue(SettingHelper.Roaming.CUSTOM_SERVER_URL, ApiHelper.ROMAING_PROXY_URL);
if (proxy)
{
baseUrl = proxyUrl;
}
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
//baseUrl = $"https://bangumi.bilibili.com/player/web_api/v2/playurl",
baseUrl = $"https://api.bilibili.com/pgc/player/web/playurl",
baseUrl = $"{baseUrl}/pgc/player/web/playurl",
parameter = $"appkey={ApiHelper.WebVideoKey.Appkey}&cid={cid}&qn={qn}&type=&otype=json&module=bangumi&season_type={season_type}"
};
if (SettingHelper.Account.Logined)
Expand All @@ -44,12 +55,12 @@ public ApiModel SeasonPlayUrl(string aid, string cid, int qn,int season_type, bo
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.WebVideoKey);
return api;
}
public ApiModel SeasonAdnroidPlayUrl(string aid, string cid, int qn, int season_type, bool dash)
public ApiModel SeasonAndroidPlayUrl(string aid, string cid, int qn, int season_type, bool dash)
{
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/pgc/player/web/playurl",
baseUrl = $"{ApiHelper.API_BASE_URL}/pgc/player/web/playurl",
parameter = $"appkey={ApiHelper.AndroidKey.Appkey}&cid={cid}&qn={qn}&type=&otype=json&module=bangumi&season_type={season_type}"
};
if (SettingHelper.Account.Logined)
Expand Down Expand Up @@ -118,7 +129,7 @@ public ApiModel InteractionEdgeInfo(string aid,int graph_version,int edge_id=0)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/stein/edgeinfo_v2",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/stein/edgeinfo_v2",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidKey, true) + $"&aid={aid}&graph_version={graph_version}&edge_id={edge_id}"
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidKey);
Expand All @@ -140,7 +151,7 @@ public ApiModel SeasonHistoryReport(string aid,string cid, int progress, int sid
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/history/report",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/history/report",
body = ApiHelper.MustParameter(ApiHelper.AndroidVideoKey, true) + $"&aid={aid}&cid={cid}&epid={epid}&sid={sid}&progress={progress}&realtime={progress}&sub_type=1&type={type}"
};
api.body += ApiHelper.GetSign(api.body, ApiHelper.AndroidVideoKey);
Expand All @@ -162,7 +173,7 @@ public ApiModel SendDanmu(string aid,string cid,string color,string msg,int posi
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/v2/dm/post",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/v2/dm/post",
parameter= ApiHelper.MustParameter(ApiHelper.AndroidVideoKey, true)+$"&aid={aid}",
body = $"msg={Uri.EscapeDataString(msg)}&mode={mode}&screen_state=1&color={color}&pool=0&progress={Convert.ToInt32(position*1000)}&fontsize=25&rnd={Utils.GetTimestampS()}&from=7&oid={cid}&plat={plat}&type=1"
};
Expand All @@ -180,7 +191,7 @@ public ApiModel GetPlayerInfo(string aid, string cid,string bvid)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = "https://api.bilibili.com/x/player/v2",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/player/v2",
parameter = $"cid={cid}&aid={aid}&bvid={bvid}",
};
return api;
Expand All @@ -195,7 +206,7 @@ public ApiModel GetDanmuFilterWords()
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/dm/filter/user",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/dm/filter/user",
parameter = ApiHelper.MustParameter(ApiHelper.AndroidVideoKey, true)
};
api.parameter += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidVideoKey);
Expand All @@ -212,7 +223,7 @@ public ApiModel AddDanmuFilterWord(string word,int type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Post,
baseUrl = $"https://api.bilibili.com/x/dm/filter/user/add",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/dm/filter/user/add",
body = ApiHelper.MustParameter(ApiHelper.AndroidVideoKey, true)+ $"&filter={Uri.EscapeDataString(word)}&type={type}"
};
api.body += ApiHelper.GetSign(api.parameter, ApiHelper.AndroidVideoKey);
Expand Down
4 changes: 2 additions & 2 deletions BiliLite/Api/RankAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ApiModel Rank(int rid,string type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/x/web-interface/ranking/v2",
baseUrl = $"{ApiHelper.API_BASE_URL}/x/web-interface/ranking/v2",
parameter = $"rid={rid}&type={type}"
};
return api;
Expand All @@ -45,7 +45,7 @@ public ApiModel SeasonRank(int type)
ApiModel api = new ApiModel()
{
method = RestSharp.Method.Get,
baseUrl = $"https://api.bilibili.com/pgc/season/rank/list",
baseUrl = $"{ApiHelper.API_BASE_URL}/pgc/season/rank/list",
parameter = $"season_type={type}"
};
return api;
Expand Down
Loading

0 comments on commit 4764cbd

Please sign in to comment.