aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-21 05:01:35 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-21 05:01:35 +0100
commitfab3bb7f8af92b47ce2e7be7c5b58c4ea5aee48c (patch)
treeedb12fedbdceec8594d33200ffdf557f196e4f0c /src/plugins/Youtube.cpp
parent2beeddb325ecbc03ddd6c741449fabd527a3c8cc (diff)
Revert back to recommending youtube videos based on related videos
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp184
1 files changed, 0 insertions, 184 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index a4212ae..e0d79c3 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -1775,190 +1775,6 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult YoutubeRecommendedPage::get_page(const std::string&, int page, BodyItems &result_items) {
- while(current_page < page) {
- PluginResult plugin_result = search_get_continuation(continuation_token, result_items);
- if(plugin_result != PluginResult::OK) return plugin_result;
- ++current_page;
- }
- return PluginResult::OK;
- }
-
- PluginResult YoutubeRecommendedPage::search_get_continuation(const std::string &current_continuation_token, BodyItems &result_items) {
- if(current_continuation_token.empty())
- return PluginResult::OK;
-
- std::string next_url = "https://www.youtube.com/?pbj=1&gl=US&hl=en&ctoken=" + current_continuation_token;
-
- std::vector<CommandArg> additional_args = {
- { "-H", "x-spf-referer: https://www.youtube.com/" },
- { "-H", "x-youtube-client-name: 1" },
- { "-H", "x-spf-previous: https://www.youtube.com/" },
- { "-H", youtube_client_version },
- { "-H", "referer: https://www.youtube.com/" }
- };
-
- std::vector<CommandArg> cookies = get_cookies();
- additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
-
- Json::Value json_root;
- DownloadResult result = download_json(json_root, next_url, std::move(additional_args), true);
- if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
-
- if(!json_root.isArray())
- return PluginResult::ERR;
-
- std::string new_continuation_token;
- for(const Json::Value &json_item : json_root) {
- if(!json_item.isObject())
- continue;
-
- const Json::Value &response_json = json_item["response"];
- if(!response_json.isObject())
- continue;
-
- const Json::Value &on_response_received_actions_json = response_json["onResponseReceivedActions"];
- if(!on_response_received_actions_json.isArray())
- continue;
-
- for(const Json::Value &response_received_command : on_response_received_actions_json) {
- if(!response_received_command.isObject())
- continue;
-
- const Json::Value &append_continuation_items_action_json = response_received_command["appendContinuationItemsAction"];
- if(!append_continuation_items_action_json.isObject())
- continue;
-
- const Json::Value &continuation_items_json = append_continuation_items_action_json["continuationItems"];
- if(!continuation_items_json.isArray())
- continue;
-
- for(const Json::Value &content_item_json : continuation_items_json) {
- if(!content_item_json.isObject())
- continue;
-
- if(new_continuation_token.empty())
- new_continuation_token = item_section_renderer_get_continuation_token(content_item_json);
-
- const Json::Value &rich_item_renderer_json = content_item_json["richItemRenderer"];
- if(!rich_item_renderer_json.isObject())
- continue;
-
- const Json::Value &item_content_json = rich_item_renderer_json["content"];
- if(!item_content_json.isObject())
- continue;
-
- const Json::Value &video_renderer_json = item_content_json["videoRenderer"];
- if(!video_renderer_json.isObject())
- continue;
-
- auto body_item = parse_common_video_item(video_renderer_json, added_videos);
- if(body_item)
- result_items.push_back(std::move(body_item));
- }
- }
- }
-
- continuation_token = std::move(new_continuation_token);
- return PluginResult::OK;
- }
-
- PluginResult YoutubeRecommendedPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
- result_tabs.push_back(Tab{nullptr, std::make_unique<YoutubeVideoPage>(program, args.url), nullptr});
- return PluginResult::OK;
- }
-
- PluginResult YoutubeRecommendedPage::lazy_fetch(BodyItems &result_items) {
- current_page = 0;
- continuation_token.clear();
- added_videos.clear();
-
- std::vector<CommandArg> additional_args = {
- { "-H", "x-youtube-client-name: 1" },
- { "-H", youtube_client_version }
- };
-
- std::vector<CommandArg> cookies = get_cookies();
- additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
-
- Json::Value json_root;
- DownloadResult result = download_json(json_root, "https://www.youtube.com/?pbj=1&gl=US&hl=en", std::move(additional_args), true);
- if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
-
- if(!json_root.isArray())
- return PluginResult::ERR;
-
- std::string new_continuation_token;
- for(const Json::Value &json_item : json_root) {
- if(!json_item.isObject())
- continue;
-
- const Json::Value &response_json = json_item["response"];
- if(!response_json.isObject())
- continue;
-
- const Json::Value &contents_json = response_json["contents"];
- if(!contents_json.isObject())
- continue;
-
- const Json::Value &tcbrr_json = contents_json["twoColumnBrowseResultsRenderer"];
- if(!tcbrr_json.isObject())
- continue;
-
- const Json::Value &tabs_json = tcbrr_json["tabs"];
- if(!tabs_json.isArray())
- continue;
-
- for(const Json::Value &tab_json : tabs_json) {
- if(!tab_json.isObject())
- continue;
-
- const Json::Value &tab_renderer_json = tab_json["tabRenderer"];
- if(!tab_renderer_json.isObject())
- continue;
-
- const Json::Value &content_json = tab_renderer_json["content"];
- if(!content_json.isObject())
- continue;
-
- const Json::Value &rich_grid_renderer_json = content_json["richGridRenderer"];
- if(!rich_grid_renderer_json.isObject())
- continue;
-
- const Json::Value &contents2_json = rich_grid_renderer_json["contents"];
- if(!contents2_json.isArray())
- continue;
-
- for(const Json::Value &content_item_json : contents2_json) {
- if(!content_item_json.isObject())
- continue;
-
- if(new_continuation_token.empty())
- new_continuation_token = item_section_renderer_get_continuation_token(content_item_json);
-
- const Json::Value &rich_item_renderer_json = content_item_json["richItemRenderer"];
- if(!rich_item_renderer_json.isObject())
- continue;
-
- const Json::Value &item_content_json = rich_item_renderer_json["content"];
- if(!item_content_json.isObject())
- continue;
-
- const Json::Value &video_renderer_json = item_content_json["videoRenderer"];
- if(!video_renderer_json.isObject())
- continue;
-
- auto body_item = parse_common_video_item(video_renderer_json, added_videos);
- if(body_item)
- result_items.push_back(std::move(body_item));
- }
- }
- }
-
- continuation_token = std::move(new_continuation_token);
- return PluginResult::OK;
- }
-
PluginResult YoutubeRelatedVideosPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
result_tabs.push_back(Tab{nullptr, std::make_unique<YoutubeVideoPage>(program, args.url), nullptr});
return PluginResult::OK;