aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-09-16 17:10:51 +0200
committerdec05eba <dec05eba@protonmail.com>2021-09-16 17:10:57 +0200
commit86d23983d8c9cd75af9c40f038f6b9a1f0b5fbb5 (patch)
tree1b40a6bc3a7cf7c08ccc56509eb77c6ed3461c5a
parent51bdadf793ab791e09bf1d355a84cd2c4e2ac42e (diff)
Youtube: fix videos that do not allow embedding
-rw-r--r--TODO3
-rw-r--r--src/plugins/Youtube.cpp62
2 files changed, 49 insertions, 16 deletions
diff --git a/TODO b/TODO
index c601886..a28ad42 100644
--- a/TODO
+++ b/TODO
@@ -197,4 +197,5 @@ Add option to play peertube video directly from url, along with timestamp. Shoul
Peertube urls should play directly in quickmedia.
Test peertube with live streams.
Peertube hls streams can be really slow to start up (especially for videos.autizmo.xyz). This is an issue in ffmpeg. Maybe use youtube proxy downloader for this? those videos are fragmented.
-Add keybindings for image control for 4chan. \ No newline at end of file
+Add keybindings for image control for 4chan.
+Fix youtube videos that are age restricted AND do not allow embedding. Is that even possible? \ No newline at end of file
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 74d0cbe..a289b65 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -2447,7 +2447,7 @@ namespace QuickMedia {
return PluginResult::ERR;
}
- std::string request_data =
+ std::string request_data[2] = {
R"END(
{
"context": {
@@ -2470,24 +2470,56 @@ R"END(
"contentCheckOk": true,
"racyCheckOk": true
}
-)END";
- string_replace_all(request_data, "%VIDEO_ID%", video_id);
-
- std::vector<CommandArg> additional_args = {
- { "-H", "Content-Type: application/json" },
- { "-H", "X-YouTube-Client-Name: 3" },
- { "-H", "X-YouTube-Client-Version: 16.20" },
- { "--data-raw", std::move(request_data) }
+)END",
+R"END(
+{
+ "context": {
+ "client": {
+ "clientName": "ANDROID",
+ "clientVersion": "16.20",
+ "hl": "en"
+ },
+ "thirdParty": {
+ "embedUrl": "https://google.com"
+ }
+ },
+ "videoId": "%VIDEO_ID%",
+ "playbackContext": {
+ "contentPlaybackContext": {
+ "html5Preference": "HTML5_PREF_WANTS"
+ }
+ },
+ "contentCheckOk": true,
+ "racyCheckOk": true
+}
+)END",
};
- std::vector<CommandArg> cookies = get_cookies();
- additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
+ for(int i = 0; i < 2; ++i) {
+ string_replace_all(request_data[i], "%VIDEO_ID%", video_id);
- Json::Value json_root;
- DownloadResult download_result = download_json(json_root, "https://www.youtube.com/youtubei/v1/player?key=" + api_key + "&gl=US&hl=en", additional_args, true);
- if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result);
+ std::vector<CommandArg> additional_args = {
+ { "-H", "Content-Type: application/json" },
+ { "-H", "X-YouTube-Client-Name: 3" },
+ { "-H", "X-YouTube-Client-Version: 16.20" },
+ { "--data-raw", std::move(request_data[i]) }
+ };
+
+ std::vector<CommandArg> cookies = get_cookies();
+ additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
+
+ Json::Value json_root;
+ DownloadResult download_result = download_json(json_root, "https://www.youtube.com/youtubei/v1/player?key=" + api_key + "&gl=US&hl=en", additional_args, true);
+ if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result);
+
+ PluginResult result = parse_video_response(json_root, title, channel_url, chapters, err_str);
+ if(result == PluginResult::OK) {
+ err_str.clear();
+ return PluginResult::OK;
+ }
+ }
- return parse_video_response(json_root, title, channel_url, chapters, err_str);
+ return PluginResult::ERR;
}
void YoutubeVideoPage::mark_watched() {