BilibiliPotPlayer icon indicating copy to clipboard operation
BilibiliPotPlayer copied to clipboard

上次联系了potplayer作者,可以直接解析B站字幕json

Open hellpeak opened this issue 11 months ago • 5 comments

res = apiPost("/x/player/wbi/v2?bvid=" + bvid + "&cid=" + cid); if (res.empty()) { return url; } if (reader.parse(res, root) && root.isObject()) { if (root["code"].asInt() == 0) { JsonValue data = root["data"]; if (ConfigData.danmakuEnable) { JsonValue subs; subs = root["data"]["subtitle"]["subtitles"]; if (subs.isArray()) { for (int i = 0; i < subs.size(); i++) { JsonValue sub = subs[i];//JsonValue sub = subs[i]; dictionary dic; dic["name"] = sub["lan_doc"].asString(); dic["langCode"] = sub["lan"].asString(); //dic["kind"] = "srt"; //if (sub["subtitle_url"].asString().find("http") == 0) { // res = apiPost(sub["subtitle_url"].asString()); // dic["url"] = //} else { //res = apiPost("https:" + sub["subtitle_url_v2"].asString()); // dic["url"] = //} JsonValue subroot; //if (false && reader.parse(res, subroot) && subroot.isObject()) { //JsonValue subbodys = subroot["body"]; //string srtsub = "test"; //for (int j = 0; j < subbodys.size(); j++) { //JsonValue subbody = subbodys[j]; //srtsub += ( j + 1 ) + "\n"; //srtsub += Dec2hms(subbody["from"].asFloat()) + " --> " + Dec2hms(subbody["to"].asFloat()) + "\n"; //srtsub += subbody["content"].asString() + "\n"; //srtsub += srtsub + "\n"; //} //dic["fileContent"] = srtsub; // dic["url"] = srtsub; //} //string srtsub = "1\n00:00:44,840 --> 00:00:57,190\n(産屋敷)健一 秀樹 実\n"; dic["url"] = "https:" + sub["subtitle_url"].asString(); subtitle.insertLast(dic); }

			}
			
			//if (!subtitle.empty()) {
			//	MetaData["subtitle"] = subtitle;
			//}
			//dictionary dic;
			//dic["name"] = "sub"; //+ sub["lan_doc"].asString();
			//dic["langCode"] = "en";//sub["lan"].asString();
			//dic["url"] = "1\n00:00:44,840 --> 00:00:57,190\n test123456\n";
			//subtitle.insertLast(dic);
			MetaData["subtitle"] = subtitle;
		}
		JsonValue points = data["view_points"];
		if (points.isArray()) {
			array<dictionary> chapt;
			for (int i = 0; i < points.size(); i++) {
				JsonValue point = points[i];
				dictionary item;
				item["title"] = point["content"].asString();
				item["time"] = formatUInt(point["from"].asInt() * 1000);
				chapt.insertLast(item);
			}
			if (!chapt.empty() && (@QualityList !is null)) {
				MetaData["chapter"] = chapt;
			}
		}
	} else {
		return url;
	}
}

是能直接处理B站的json链接,不是json对象,是直接传网址url: dic["url"] = "https:" + sub["subtitle_url"].asString(); 让potplayer额外加了处理的代码,有点不好意思,之前忘记讲了。 注释部分 是当时说 dic["fileContent"] = srtsub; 赋值处理完的srt/vtt字符串 可能也行,当时作者说是与dic["url"]的兼容性没写完,我也忘了测试,有兴趣可以试试

hellpeak avatar May 18 '25 12:05 hellpeak

至于为什么晚发,当时给我的是一个内测版本,后来更新版本后也ok,忘了说

hellpeak avatar May 18 '25 12:05 hellpeak

额外使用的时间转换方法 string Dec2hms(float timeInSeconds){ int hours = int(timeInSeconds) / 3600; // 每小时有 3600 秒 int minutes = (int(timeInSeconds) % 3600) / 60; // 剩余秒数除以 60 得到分钟 int seconds = int(timeInSeconds) % 60; // 剩余秒数为秒部分 int milliseconds = int((timeInSeconds - int(timeInSeconds)) * 1000); // 小数部分转为毫秒

// 格式化为字符串,确保每部分是两位或三位
string timeString = format("{:02}:{:02}:{:02},{:03}", hours, minutes, seconds, milliseconds);

return timeString;

}

hellpeak avatar May 19 '25 07:05 hellpeak

@yiqifengba 测试了一下,直接传入Json格式的字幕url的确可行。直接将弹幕文本内容传入 dic["fileContent"] = assSub 同样可以显示弹幕,这样的话或许可以用potplayer插件调用python程序获取弹幕内容,再将弹幕文本传回插件中赋值到dic["fileContent"]。不知道这个改动是从哪个版本生效的

chen310 avatar May 22 '25 16:05 chen310

@chen310 一月份联系的,当时拿到的内测版本,后面没注意

hellpeak avatar May 22 '25 17:05 hellpeak

@chen310 一月份联系的,当时拿到的内测版本,后面没注意

怎么用?

2367907737 avatar May 23 '25 15:05 2367907737