From 86d23983d8c9cd75af9c40f038f6b9a1f0b5fbb5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 16 Sep 2021 17:10:51 +0200 Subject: Youtube: fix videos that do not allow embedding --- src/plugins/Youtube.cpp | 62 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'src/plugins') 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 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 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 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 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() { -- cgit v1.2.3