From ab5065e541cb6f84b11062892ce25f033c7fa82d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 3 May 2021 01:48:19 +0200 Subject: Add readm.org --- src/plugins/Fourchan.cpp | 7 ++++- src/plugins/MangaGeneric.cpp | 66 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 9 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 5e6a970..34cb8bf 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -540,12 +540,15 @@ namespace QuickMedia { PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &comment, const std::string &filepath) { std::string url = "https://sys.4chan.org/" + board_id + "/post"; + std::string comment_fixed = comment; + if(comment_fixed[0] == '@') + comment_fixed = "\\" + comment_fixed; std::vector additional_args = { CommandArg{"-H", "Referer: https://boards.4chan.org/"}, CommandArg{"-H", "Origin: https://boards.4chan.org"}, CommandArg{"-F", "resto=" + thread_id}, - CommandArg{"-F", "com=" + comment}, + CommandArg{"-F", "com=" + comment_fixed}, CommandArg{"-F", "mode=regist"} }; @@ -583,6 +586,8 @@ namespace QuickMedia { return PostResult::TRY_AGAIN; if(response.find("Audio streams are not allowed") != std::string::npos) return PostResult::FILE_TYPE_NOT_ALLOWED; + if(response.find("Error: Upload failed") != std::string::npos) + return PostResult::UPLOAD_FAILED; return PostResult::ERR; } diff --git a/src/plugins/MangaGeneric.cpp b/src/plugins/MangaGeneric.cpp index 48533b8..a6df1c1 100644 --- a/src/plugins/MangaGeneric.cpp +++ b/src/plugins/MangaGeneric.cpp @@ -162,11 +162,32 @@ namespace QuickMedia { return plugin_result_to_search_result(get_page(str, 0, result_items)); } - PluginResult MangaGenericSearchPage::get_page(const std::string &url, BodyItems &result_items) { + PluginResult MangaGenericSearchPage::get_page(const std::string &url, bool is_post, const std::vector &form_data, BodyItems &result_items) { std::vector args; if(!website_url.empty()) args.push_back({ "-H", "referer: " + website_url }); + if(is_post) { + args.push_back({ "-X", "POST" }); + args.push_back({ "-H", "x-requested-with: XMLHttpRequest" }); + for(const MangaFormDataStr &form : form_data) { + std::string form_value = form.value; + if(form_value[0] == '@') + form_value = "\\" + form_value; + args.push_back({ "-F", std::string(form.key) + "=" + form_value }); + } + + assert(search_query.json_handler); + std::string err_msg; + Json::Value json_root; + if(download_json(json_root, url, args, true, fail_on_http_error ? nullptr : &err_msg) != DownloadResult::OK) + return PluginResult::NET_ERR; + + result_items = search_query.json_handler(json_root); + body_items_prepend_website_url(result_items, website_url); + return PluginResult::OK; + } + std::string target_url; std::string website_data; if(download_to_string(url, website_data, args, true, fail_on_http_error) != DownloadResult::OK) @@ -266,10 +287,27 @@ namespace QuickMedia { } PluginResult MangaGenericSearchPage::get_page(const std::string &str, int page, BodyItems &result_items) { - std::string url = search_query.search_template; - string_replace_all(url, "%s", url_param_encode(str)); - string_replace_all(url, "%p", std::to_string(search_query.page_start + page)); - return get_page(url, result_items); + if(search_query.is_post) { + if(page != 0) + return PluginResult::OK; + + std::vector form_data(search_query.form_data.size()); + for(size_t i = 0; i < form_data.size(); ++i) { + MangaFormDataStr &form = form_data[i]; + form.key = search_query.form_data[i].key; + form.value = search_query.form_data[i].value; + string_replace_all(form.value, "%s", str); + } + return get_page(search_query.search_template, search_query.is_post, form_data, result_items); + } else { + std::string url = search_query.search_template; + string_replace_all(url, "%s", url_param_encode(str)); + size_t num_replaced = string_replace_all(url, "%p", std::to_string(search_query.page_start + page)); + if(num_replaced == 0 && page != 0) + return PluginResult::OK; + else + return get_page(url, false, {}, result_items); + } } PluginResult MangaGenericSearchPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { @@ -396,7 +434,7 @@ namespace QuickMedia { } PluginResult MangaGenericCreatorPage::lazy_fetch(BodyItems &result_items) { - return search_page->get_page(creator.url, result_items); + return search_page->get_page(creator.url, false, {}, result_items); } static bool is_number(const char *str) { @@ -680,6 +718,18 @@ namespace QuickMedia { MangaGenericSearchPage& MangaGenericSearchPage::search_handler(const char *search_template, int page_start) { search_query.search_template = search_template; search_query.page_start = page_start; + search_query.form_data.clear(); + search_query.is_post = false; + search_query.json_handler = nullptr; + return *this; + } + + MangaGenericSearchPage& MangaGenericSearchPage::search_post_handler(const char *url, std::vector form_data, SearchQueryJsonHandler result_handler) { + search_query.search_template = url; + search_query.page_start = 1; + search_query.form_data = std::move(form_data); + search_query.is_post = true; + search_query.json_handler = std::move(result_handler); return *this; } @@ -723,7 +773,7 @@ namespace QuickMedia { list_page_query.images_query.html_query = html_query; list_page_query.images_query.field_name = field_name; list_page_query.images_query.field_contains = field_contains; - list_page_query.images_query.post_handler = post_handler; + list_page_query.images_query.post_handler = std::move(post_handler); return *this; } @@ -749,7 +799,7 @@ namespace QuickMedia { MangaGenericSearchPage& MangaGenericSearchPage::list_page_images_custom_handler(ListPageCustomHandler handler) { assert(handler); list_page_query.type = ListPageQueryType::CUSTOM; - list_page_query.custom_query.handler = handler; + list_page_query.custom_query.handler = std::move(handler); return *this; } -- cgit v1.2.3