diff --git a/Media/PlayParse/MediaPlayParse - Bilibili.as b/Media/PlayParse/MediaPlayParse - Bilibili.as index ab0ac53..542a871 100644 --- a/Media/PlayParse/MediaPlayParse - Bilibili.as +++ b/Media/PlayParse/MediaPlayParse - Bilibili.as @@ -104,8 +104,7 @@ string ServerLogin(string User, string Pass) } ConfigData = ReadConfigFile(User); if (ConfigData.debug) { - HostOpenConsole(); - } + } return "配置文件读取成功,修改完配置文件后需要重启 PotPlayer 才能生效"; } @@ -1660,58 +1659,73 @@ string Live(string id, const string &in path, dictionary &MetaData, array 0) { flv_url = d[0]["url"].asString(); stream_name = HostRegExpParse(flv_url, "(live_[^_]+_[^_]+_[^_]+)"); } } } + int best_qn = 10000; + string v2 = post("https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id=" + room_id + "&no_playurl=0&mask=1&platform=web&qn=0&web_location=444.8"); + { JsonReader R; JsonValue V; if (R.parse(v2, V) && V.isObject() && V["code"].asInt() == 0) { + JsonValue gqn = V["data"]["playurl_info"]["playurl"]["g_qn_desc"]; + if (gqn.isArray()) { + for (int i2 = gqn.size() - 1; i2 >= 0; i2--) { + int q = gqn[i2]["qn"].asInt(); + if (q > best_qn && q <= 30000) { best_qn = q; } + } } - JsonValue data = Root["data"]["durl"]; - if (data.isArray()) { - url = data[0]["url"].asString(); - JsonValue qualities = Root["data"]["quality_description"]; - if (@QualityList !is null) { - for (int i = 0; i < qualities.size(); i++) { - int quality = qualities[i]["qn"].asInt(); - dictionary qualityitem; - dictionary qualityitem2; - string backup_url; - if (quality == qn) { - qualityitem["url"] = url; - if (data.size() > 1) { - qualityitem2["url"] = data[1]["url"].asString(); - } - } else { - string quality_res = post("https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=" + room_id + "&platform=web&qn=" + quality + "&https_url_req=1&ptype=16"); - JsonValue temp; - if (Reader.parse(quality_res, temp) && temp.isObject()) { - if (temp["code"].asInt() != 0) { - continue; - } - JsonValue qyality_data = temp["data"]["durl"]; - if (qyality_data.isArray()) { - qualityitem["url"] = qyality_data[0]["url"].asString(); - if (qyality_data.size() > 1) { - qualityitem2["url"] = qyality_data[1]["url"].asString(); - } - } - } - } - int itag = getItag(quality); - qualityitem["quality"] = qualities[i]["desc"].asString(); - qualityitem["qualityDetail"] = qualityitem["quality"]; - qualityitem["itag"] = itag; - QualityList.insertLast(qualityitem); - - qualityitem2["quality"] = "- " + qualities[i]["desc"].asString() + " 备份"; - qualityitem2["qualityDetail"] = qualityitem2["quality"]; - qualityitem2["itag"] = itag + 20; - QualityList.insertLast(qualityitem2); + } } + string gw = post("https://api.live.bilibili.com/xlive/play-gateway/master/url?cid=" + room_id + "&mid=37527999&pt=web&p2p_type=1&net=0&free_type=0&build=0&feature=0&qn=" + best_qn + "&drm_type=0,1,2,3&cam_id=0&stream_name=" + stream_name); + if (!gw.empty() && gw.find("#EXTM3U") >= 0) { + array mlines = gw.split("\n"); + array seen_qn = {}; + for (uint i2 = 0; i2 < mlines.length(); i2++) { + if (mlines[i2].find("#EXT-X-STREAM-INF:") >= 0) { + int qn_val = parseInt(HostRegExpParse(mlines[i2], "BILI-QN=([0-9]+)")); + if (seen_qn.find(qn_val) >= 0) { continue; } + seen_qn.insertLast(qn_val); + string s_url = ""; + for (uint j2 = i2+1; j2 < mlines.length(); j2++) { + string t = mlines[j2]; + if (!t.empty() && t.find("#") != 0) { s_url = t; break; } + } + if (url.empty()) { url = "" + s_url; } + string dn = ""; + if (qn_val == 30000) { dn = "杜比"; } + else if (qn_val == 25000) { dn = "原画真彩"; } + else if (qn_val == 20000) { dn = "4K"; } + else if (qn_val == 15000) { dn = "2K"; } + else if (qn_val == 10000) { dn = "原画"; } + else if (qn_val == 400) { dn = "蓝光"; } + else if (qn_val == 250) { dn = "超清"; } + else if (qn_val == 150) { dn = "高清"; } + else if (qn_val == 80) { dn = "流畅"; } + else { dn = HostRegExpParse(mlines[i2], "BILI-DISPLAY=\"([^\"]+)\""); } + if (dn.empty()) { dn = "qn" + qn_val; } + if (@QualityList !is null && !s_url.empty()) { + dictionary qitem; qitem["url"] = s_url; qitem["quality"] = dn; + qitem["qualityDetail"] = qitem["quality"]; qitem["itag"] = qn_val; + QualityList.insertLast(qitem); } } } } + if (url.empty() && !flv_url.empty()) { url = flv_url; } + if (@QualityList !is null && QualityList.length() == 0) { + array qns = {30000, 25000, 20000, 15000, 10000, 400, 250, 150, 80}; + array qnames = {"杜比", "原画真彩", "4K", "2K", "原画", "蓝光", "超清", "高清", "流畅"}; + for (uint i2 = 0; i2 < qns.length(); i2++) { + dictionary qitem; qitem["url"] = url; qitem["quality"] = qnames[i2]; + qitem["qualityDetail"] = qitem["quality"]; qitem["itag"] = i2; + QualityList.insertLast(qitem); + } + } return url; }