diff options
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 49 |
2 files changed, 25 insertions, 27 deletions
@@ -173,4 +173,5 @@ PgUp/PgDown shouldn't move body by the number of visible items. It should instea Add option to view dead link in 4chan with 4chan archive and navigate to crossboard links. Show latest message before sync is done for a room when the latest message is an edit. Right now it has to fetch previous messages until the first non-edit message. Allow resuming downloads. -Support downloading live youtube videos.
\ No newline at end of file +Support downloading live youtube videos. +Youtube broke age restricted video again. Need to find a fix. It kinda works in yt-dlp, but not always.
\ No newline at end of file diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index cd3fddd..167b201 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2307,6 +2307,15 @@ R"END( if(!json_root.isObject()) return PluginResult::ERR; + const Json::Value &playability_status_json = json_root["playabilityStatus"]; + if(playability_status_json.isObject()) { + const Json::Value &status_json = playability_status_json["status"]; + if(status_json.isString() && (strcmp(status_json.asCString(), "UNPLAYABLE") == 0 || strcmp(status_json.asCString(), "LOGIN_REQUIRED") == 0)) { + const Json::Value &reason_json = playability_status_json["reason"]; + fprintf(stderr, "Unable to play video, status: %s, reason: %s\n", status_json.asCString(), reason_json.isString() ? reason_json.asCString() : "Unknown"); + } + } + const Json::Value *streaming_data_json = &json_root["streamingData"]; if(!streaming_data_json->isObject()) return PluginResult::ERR; @@ -2400,36 +2409,24 @@ R"END( return PluginResult::ERR; } - Json::Value json_root; - PluginResult result = get_video_info(video_id, json_root); - if(result != PluginResult::OK) - return result; - - // Getting streams might fail for some videos that do not allow videos to be embedded when using get_video_info endpoint. - // TODO: Does that means for videos that do not allow to be embedded and are age restricted wont work? - result = parse_video_response(json_root, title, channel_url, chapters); - if(result == PluginResult::OK) { - return PluginResult::OK; - } else { - std::string request_data = key_api_request_data; - string_replace_all(request_data, "%VIDEO_ID%", video_id); + 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> 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()); + 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); + 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); - return parse_video_response(json_root, title, channel_url, chapters); - } + return parse_video_response(json_root, title, channel_url, chapters); } void YoutubeVideoPage::mark_watched() { |