aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-24 23:28:25 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-24 23:28:25 +0200
commit561d446e6871b7aa80c71357d8b2ccf78e4a6a7b (patch)
tree6f5041dc8bfd29658355cdc5f509865549f15af8 /src/plugins/Youtube.cpp
parent5a2bb738b05253287438df9f1a0bdb95fea92dd9 (diff)
Fix youtube copyrighted videos (revert back to watch?v= url)
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp58
1 files changed, 23 insertions, 35 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 4544a45..7e5bd7b 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -2274,29 +2274,7 @@ R"END(
return result;
}
- // TODO: Extract innertube_api_key from response?
- PluginResult YoutubeVideoPage::get_video_info(const std::string &video_id, Json::Value &json_root) {
- std::vector<CommandArg> additional_args = get_cookies();
-
- std::string response;
- DownloadResult download_result = download_to_string("https://www.youtube.com/get_video_info?html5=1&c=TVHTML5&cver=6.20180913&gl=US&hl=en&video_id=" + video_id + "&eurl=https://www.youtube.googleapis.com/v/" + video_id, response, std::move(additional_args), true);
- if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result);
-
- std::string player_response_param = url_extract_param(response, "player_response");
- player_response_param = url_param_decode(player_response_param);
-
- Json::CharReaderBuilder json_builder;
- std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader());
- std::string json_errors;
- if(!json_reader->parse(player_response_param.data(), player_response_param.data() + player_response_param.size(), &json_root, &json_errors)) {
- fprintf(stderr, "Failed to read param as json, error: %s\n", json_errors.c_str());
- return PluginResult::ERR;
- }
-
- return PluginResult::OK;
- }
-
- PluginResult YoutubeVideoPage::parse_video_response(Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters) {
+ PluginResult YoutubeVideoPage::parse_video_response(const Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters) {
livestream_url.clear();
video_formats.clear();
audio_formats.clear();
@@ -2409,24 +2387,34 @@ R"END(
return PluginResult::ERR;
}
- std::string request_data = key_api_request_data;
- string_replace_all(request_data, "%VIDEO_ID%", video_id);
-
std::vector<CommandArg> additional_args = {
- { "-H", "Content-Type: application/json" },
{ "-H", "x-youtube-client-name: 1" },
{ "-H", youtube_client_version },
- { "--data-raw", std::move(request_data) }
};
std::vector<CommandArg> cookies = get_cookies();
additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
+ // TODO: Remove this code completely and replace with existing player? api
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);
+ DownloadResult download_result = download_json(json_root, "https://www.youtube.com/watch?v=" + video_id + "&pbj=1&gl=US&hl=en", additional_args, true);
if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result);
- return parse_video_response(json_root, title, channel_url, chapters);
+ if(!json_root.isArray())
+ return PluginResult::ERR;
+
+ for(const Json::Value &json_item : json_root) {
+ if(!json_item.isObject())
+ continue;
+
+ const Json::Value &player_response_json = json_item["playerResponse"];
+ if(!player_response_json.isObject())
+ continue;
+
+ return parse_video_response(player_response_json, title, channel_url, chapters);
+ }
+
+ return PluginResult::ERR;
}
void YoutubeVideoPage::mark_watched() {
@@ -2462,7 +2450,7 @@ R"END(
cipher_params = http_params_parse(signature_cipher_json.asString());
}
- const std::string &url = cipher_params["url"];
+ std::string &url = cipher_params["url"];
if(url.empty())
return false;
@@ -2471,17 +2459,17 @@ R"END(
return true;
}
- std::string url_decoded = url_param_decode(url);
- url_decoded += "&alr=yes&cver=2.20210615.01.00&cpn=" + cpn;
+ //std::string url_decoded = url_param_decode(url);
+ //url_decoded += "&alr=yes&cver=2.20210615.01.00&cpn=" + cpn;
const std::string &s = cipher_params["s"];
const std::string &sp = cipher_params["sp"];
std::string sig_key;
std::string sig_value;
if(YoutubeSignatureDecryptor::get_instance().decrypt(s, sp, sig_key, sig_value))
- url_decoded += "&" + std::move(sig_key) + "=" + std::move(sig_value);
+ url += "&" + std::move(sig_key) + "=" + std::move(sig_value);
- youtube_format.url = std::move(url_decoded);
+ youtube_format.url = std::move(url);
return true;
}