From 77ed51898157d99112be7550471ec06e32344c9e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 11 Oct 2020 21:35:37 +0200 Subject: Refactor plugin into seperate pages TODO: Readd 4chan login page, manganelo creators page, autocomplete --- src/plugins/Pornhub.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/plugins/Pornhub.cpp') diff --git a/src/plugins/Pornhub.cpp b/src/plugins/Pornhub.cpp index 77d5594..afdd8fc 100644 --- a/src/plugins/Pornhub.cpp +++ b/src/plugins/Pornhub.cpp @@ -1,4 +1,5 @@ #include "../../plugins/Pornhub.hpp" +#include "../../include/StringUtils.hpp" #include #include @@ -11,14 +12,13 @@ namespace QuickMedia { return strstr(str, substr); } - // TODO: Speed this up by using string.find instead of parsing html - SuggestionResult Pornhub::update_search_suggestions(const std::string &text, BodyItems &result_items) { + SearchResult PornhubSearchPage::search(const std::string &str, BodyItems &result_items) { std::string url = "https://www.pornhub.com/video/search?search="; - url += url_param_encode(text); + url += url_param_encode(str); std::string website_data; - if(download_to_string(url, website_data, {}, use_tor) != DownloadResult::OK) - return SuggestionResult::NET_ERR; + if(download_to_string(url, website_data, {}, is_tor_enabled()) != DownloadResult::OK) + return SearchResult::NET_ERR; struct ItemData { BodyItems *result_items; @@ -65,14 +65,21 @@ namespace QuickMedia { cleanup: quickmedia_html_search_deinit(&html_search); - return result == 0 ? SuggestionResult::OK : SuggestionResult::ERR; + return result == 0 ? SearchResult::OK : SearchResult::ERR; } - BodyItems Pornhub::get_related_media(const std::string &url) { + PluginResult PornhubSearchPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { + (void)title; + (void)url; + result_tabs.push_back(Tab{create_body(), std::make_unique(program), nullptr}); + return PluginResult::OK; + } + + BodyItems PornhubVideoPage::get_related_media(const std::string &url) { BodyItems result_items; std::string website_data; - if(download_to_string(url, website_data, {}, use_tor) != DownloadResult::OK) + if(download_to_string(url, website_data, {}, is_tor_enabled()) != DownloadResult::OK) return result_items; struct ItemData { -- cgit v1.2.3