diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-11-04 01:30:38 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-11-04 01:30:38 +0100 |
commit | b6b972e2dae816a8f0686f4986029a5ed50e592c (patch) | |
tree | b7966625b8ad02628f053a7436c0dd39d8de8abd /src/plugins | |
parent | ae6fb457ca385540e0f9b1347ef9c3c84815b16d (diff) |
Add channels page to related videos menu, fix related videos menu broken after video failing to load
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/ImageBoard.cpp | 6 | ||||
-rw-r--r-- | src/plugins/Page.cpp | 5 | ||||
-rw-r--r-- | src/plugins/Pornhub.cpp | 20 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 51 |
4 files changed, 71 insertions, 11 deletions
diff --git a/src/plugins/ImageBoard.cpp b/src/plugins/ImageBoard.cpp index ac05f80..6f97082 100644 --- a/src/plugins/ImageBoard.cpp +++ b/src/plugins/ImageBoard.cpp @@ -1,7 +1,7 @@ #include "../../plugins/ImageBoard.hpp" namespace QuickMedia { - BodyItems ImageBoardThreadPage::get_related_media(const std::string &url) { + BodyItems ImageBoardThreadPage::get_related_media(const std::string &url, std::string&) { BodyItems body_items; auto it = std::find(cached_media_urls.begin(), cached_media_urls.end(), url); if(it == cached_media_urls.end()) @@ -16,6 +16,10 @@ namespace QuickMedia { return body_items; } + std::unique_ptr<RelatedVideosPage> ImageBoardThreadPage::create_related_videos_page(Program*, const std::string&, const std::string&) { + return nullptr; + } + PluginResult ImageBoardThreadPage::login(const std::string &token, const std::string &pin, std::string &response_msg) { (void)token; (void)pin; diff --git a/src/plugins/Page.cpp b/src/plugins/Page.cpp index e444ecd..9e0e97a 100644 --- a/src/plugins/Page.cpp +++ b/src/plugins/Page.cpp @@ -3,11 +3,6 @@ #include <json/reader.h> namespace QuickMedia { - BodyItems Page::get_related_media(const std::string &url) { - (void)url; - return {}; - } - DownloadResult Page::download_json(Json::Value &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent, std::string *err_msg) { std::string server_response; if(download_to_string(url, server_response, std::move(additional_args), is_tor_enabled(), use_browser_useragent, err_msg == nullptr) != DownloadResult::OK) { diff --git a/src/plugins/Pornhub.cpp b/src/plugins/Pornhub.cpp index f527e76..1f0840e 100644 --- a/src/plugins/Pornhub.cpp +++ b/src/plugins/Pornhub.cpp @@ -138,16 +138,28 @@ namespace QuickMedia { return search_result_to_plugin_result(get_videos_in_page(url, is_tor_enabled(), result_items)); } - PluginResult PornhubSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { - (void)title; - (void)url; + PluginResult PornhubSearchPage::submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) { result_tabs.push_back(Tab{nullptr, std::make_unique<PornhubVideoPage>(program), nullptr}); return PluginResult::OK; } - BodyItems PornhubVideoPage::get_related_media(const std::string &url) { + PluginResult PornhubRelatedVideosPage::submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) { + result_tabs.push_back(Tab{nullptr, std::make_unique<PornhubVideoPage>(program), nullptr}); + return PluginResult::OK; + } + + BodyItems PornhubVideoPage::get_related_media(const std::string &url, std::string&) { BodyItems result_items; get_videos_in_page(url, is_tor_enabled(), result_items); return result_items; } + + std::unique_ptr<Page> PornhubVideoPage::create_search_page(Program *program, int &search_delay) { + search_delay = 500; + return std::make_unique<PornhubSearchPage>(program); + } + + std::unique_ptr<RelatedVideosPage> PornhubVideoPage::create_related_videos_page(Program *program, const std::string&, const std::string&) { + return std::make_unique<PornhubRelatedVideosPage>(program); + } }
\ No newline at end of file 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<CommandArg> 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<CommandArg> 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<Tab> &result_tabs) { + result_tabs.push_back(Tab{nullptr, std::make_unique<YoutubeVideoPage>(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<Page> YoutubeVideoPage::create_search_page(Program *program, int &search_delay) { + search_delay = 350; + return std::make_unique<YoutubeSearchPage>(program); + } + + std::unique_ptr<RelatedVideosPage> YoutubeVideoPage::create_related_videos_page(Program *program, const std::string&, const std::string&) { + return std::make_unique<YoutubeRelatedVideosPage>(program); + } + + std::unique_ptr<LazyFetchPage> YoutubeVideoPage::create_channels_page(Program *program, const std::string &channel_url) { + return std::make_unique<YoutubeChannelPage>(program, channel_url, "", "Channel videos"); + } }
\ No newline at end of file |