diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Youtube.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index e5e721c..a8c58cb 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1221,6 +1221,9 @@ R"END( } PluginResult YoutubeChannelPage::search_get_continuation(const std::string &url, const std::string ¤t_continuation_token, BodyItems &result_items) { + if(current_continuation_token.empty()) + return PluginResult::OK; + std::vector<CommandArg> cookies = get_cookies(); std::string next_url = "https://www.youtube.com/youtubei/v1/browse?key=" + url_param_encode(api_key) + "&gl=US&hl=en"; @@ -2027,29 +2030,38 @@ 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 = get_cookies(); - 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::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::vector<CommandArg> cookies = get_cookies(); - additional_args.insert(additional_args.end(), cookies.begin(), cookies.end()); + std::string player_response_param = url_extract_param(response, "player_response"); + player_response_param = url_param_decode(player_response_param); 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); + 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; + } if(!json_root.isObject()) return PluginResult::ERR; const Json::Value &streaming_data_json = json_root["streamingData"]; - if(!streaming_data_json.isObject()) + if(!streaming_data_json.isObject()) { + const Json::Value &playability_status_json = json_root["playabilityStatus"]; + if(playability_status_json.isObject()) { + const Json::Value &status_json = playability_status_json["status"]; + const Json::Value &reason_json = playability_status_json["reason"]; + if(status_json.isString()) + fprintf(stderr, "Youtube video loading failed, reason: (status: %s, reason: %s)\n", status_json.asCString(), reason_json.isString() ? reason_json.asCString() : "unknown"); + } return PluginResult::ERR; + } // TODO: Verify if this always works (what about copyrighted live streams?), also what about choosing video quality for live stream? Maybe use mpv --hls-bitrate option? const Json::Value &hls_manifest_url_json = streaming_data_json["hlsManifestUrl"]; |