diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-09-16 17:10:51 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-09-16 17:10:57 +0200 |
commit | 86d23983d8c9cd75af9c40f038f6b9a1f0b5fbb5 (patch) | |
tree | 1b40a6bc3a7cf7c08ccc56509eb77c6ed3461c5a /src/plugins | |
parent | 51bdadf793ab791e09bf1d355a84cd2c4e2ac42e (diff) |
Youtube: fix videos that do not allow embedding
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Youtube.cpp | 62 |
1 files changed, 47 insertions, 15 deletions
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() { |