From b6b972e2dae816a8f0686f4986029a5ed50e592c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 4 Nov 2020 01:30:38 +0100 Subject: Add channels page to related videos menu, fix related videos menu broken after video failing to load --- src/plugins/Youtube.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/plugins/Youtube.cpp') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 1ca25a3..2418073 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -647,9 +647,33 @@ namespace QuickMedia { return PluginResult::OK; } + PluginResult YoutubeChannelPage::lazy_fetch(BodyItems &result_items) { + std::vector additional_args = { + { "-H", "x-spf-referer: " + url }, + { "-H", "x-youtube-client-name: 1" }, + { "-H", "x-spf-previous: " + url }, + { "-H", "x-youtube-client-version: 2.20200626.03.00" }, + { "-H", "referer: " + url } + }; + + //std::vector cookies = get_cookies(); + //additional_args.insert(additional_args.end(), cookies.begin(), cookies.end()); + + Json::Value json_root; + DownloadResult result = download_json(json_root, url + "/videos?pbj=1", std::move(additional_args), true); + if(result != DownloadResult::OK) return download_result_to_plugin_result(result); + result_items = parse_channel_videos(json_root, continuation_token, added_videos); + return PluginResult::OK; + } + + PluginResult YoutubeRelatedVideosPage::submit(const std::string&, const std::string&, std::vector &result_tabs) { + result_tabs.push_back(Tab{nullptr, std::make_unique(program), nullptr}); + return PluginResult::OK; + } + // TODO: Make this faster by using string search instead of parsing html. // TODO: If the result is a play - BodyItems YoutubeVideoPage::get_related_media(const std::string &url) { + BodyItems YoutubeVideoPage::get_related_media(const std::string &url, std::string &channel_url) { BodyItems result_items; std::string modified_url = remove_index_from_playlist_url(url); @@ -677,6 +701,18 @@ namespace QuickMedia { if(!json_item.isObject()) continue; + if(channel_url.empty()) { + const Json::Value &player_response_json = json_item["playerResponse"]; + if(player_response_json.isObject()) { + const Json::Value &video_details_json = player_response_json["videoDetails"]; + if(video_details_json.isObject()) { + const Json::Value &channel_id_json = video_details_json["channelId"]; + if(channel_id_json.isString()) + channel_url = "https://www.youtube.com/channel/" + channel_id_json.asString(); + } + } + } + const Json::Value &response_json = json_item["response"]; if(!response_json.isObject()) continue; @@ -730,4 +766,17 @@ namespace QuickMedia { return result_items; } + + std::unique_ptr YoutubeVideoPage::create_search_page(Program *program, int &search_delay) { + search_delay = 350; + return std::make_unique(program); + } + + std::unique_ptr YoutubeVideoPage::create_related_videos_page(Program *program, const std::string&, const std::string&) { + return std::make_unique(program); + } + + std::unique_ptr YoutubeVideoPage::create_channels_page(Program *program, const std::string &channel_url) { + return std::make_unique(program, channel_url, "", "Channel videos"); + } } \ No newline at end of file -- cgit v1.2.3