From ca07c2be3bba3291f59d160eac13831c85d16550 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 Oct 2020 05:48:46 +0200 Subject: Remove unused code --- src/plugins/Fourchan.cpp | 26 ++++++--------------- src/plugins/Mangadex.cpp | 13 ----------- src/plugins/Mangatown.cpp | 57 ----------------------------------------------- src/plugins/Matrix.cpp | 35 ----------------------------- src/plugins/NyaaSi.cpp | 18 +-------------- 5 files changed, 8 insertions(+), 141 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index fa5e9e3..111aca1 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -73,17 +73,12 @@ namespace QuickMedia { } } -#if 0 - std::string server_response; - if(download_to_string(fourchan_url + "boards.json", server_response, {}, use_tor) != DownloadResult::OK) - return PluginResult::NET_ERR; -#else std::string server_response; if(file_get_content(resources_root + "boards.json", server_response) != 0) { fprintf(stderr, "failed to read boards.json\n"); return PluginResult::ERR; } -#endif + Json::Value json_root; Json::CharReaderBuilder json_builder; std::unique_ptr json_reader(json_builder.newCharReader()); @@ -552,21 +547,17 @@ namespace QuickMedia { PostResult Fourchan::post_comment(const std::string &board, const std::string &thread, const std::string &captcha_id, const std::string &comment) { std::string url = "https://sys.4chan.org/" + board + "/post"; - std::vector form_data = { - FormData{"resto", thread}, - FormData{"com", comment}, - FormData{"mode", "regist"}, - FormData{"g-recaptcha-response", captcha_id} - }; std::vector additional_args = { CommandArg{"-H", "Referer: https://boards.4chan.org/"}, - CommandArg{"-H", "Content-Type: multipart/form-data; boundary=---------------------------119561554312148213571335532670"}, - CommandArg{"-H", "Origin: https://boards.4chan.org"} + CommandArg{"-H", "Origin: https://boards.4chan.org"}, + CommandArg{"-F", "resto=" + thread}, + CommandArg{"-F", "com=" + comment}, + CommandArg{"-F", "mode=regist"} }; if(pass_id.empty()) { - form_data.push_back(FormData{"g-recaptcha-response", captcha_id}); + additional_args.push_back(CommandArg{"-F", "g-recaptcha-response=" + captcha_id}); } else { Path cookies_filepath; if(get_cookies_filepath(cookies_filepath, name) != 0) { @@ -578,11 +569,8 @@ namespace QuickMedia { } } - std::vector form_data_args = create_command_args_from_form_data(form_data); - additional_args.insert(additional_args.end(), form_data_args.begin(), form_data_args.end()); - std::string response; - if(download_to_string(url, response, additional_args, use_tor) != DownloadResult::OK) + if(download_to_string(url, response, additional_args, use_tor, true) != DownloadResult::OK) return PostResult::ERR; if(response.find("successful") != std::string::npos) diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index e9487bc..bf493d3 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -220,19 +220,6 @@ namespace QuickMedia { if(result != 0) goto cleanup; - // body_item_image_context.index = 0; - // result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='pl-1']", - // [](QuickMediaHtmlNode *node, void *userdata) { - // auto *item_data = (BodyItemImageContext*)userdata; - // const char *text = quickmedia_html_node_get_text(node); - // if(text && item_data->index < item_data->body_items->size()) { - // std::string desc = strip(text); - // std::replace_if(desc.begin(), desc.end(), [](int c) { return c == '\n'; }, ' '); - // (*item_data->body_items)[item_data->index]->set_description(std::move(desc)); - // item_data->index++; - // } - // }, &body_item_image_context); - cleanup: quickmedia_html_search_deinit(&html_search); return result == 0 ? SuggestionResult::OK : SuggestionResult::ERR; diff --git a/src/plugins/Mangatown.cpp b/src/plugins/Mangatown.cpp index 0964310..1f3bcae 100644 --- a/src/plugins/Mangatown.cpp +++ b/src/plugins/Mangatown.cpp @@ -46,62 +46,6 @@ namespace QuickMedia { }; SuggestionResult Mangatown::update_search_suggestions(const std::string &text, BodyItems &result_items) { -#if 0 - std::string url = "https://www.mangatown.com/ajax/search/?query="; - url += url_param_encode(text); - - std::string server_response; - if(download_to_string(url, server_response, {}, use_tor, true) != DownloadResult::OK) - return SuggestionResult::NET_ERR; - - if(server_response.empty()) - return SuggestionResult::OK; - - Json::Value json_root; - Json::CharReaderBuilder json_builder; - std::unique_ptr json_reader(json_builder.newCharReader()); - std::string json_errors; - if(!json_reader->parse(&server_response[0], &server_response[server_response.size()], &json_root, &json_errors)) { - fprintf(stderr, "Mangatown suggestions json error: %s\n", json_errors.c_str()); - return SuggestionResult::ERR; - } - - if(!json_root.isObject()) - return SuggestionResult::OK; - - Json::Value &json_data = json_root["data"]; - Json::Value &json_suggestions = json_root["suggestions"]; - if(!json_data.isArray() || !json_suggestions.isArray()) - return SuggestionResult::OK; - - for(const Json::Value &child : json_suggestions) { - if(!child.isString()) { - result_items.push_back(BodyItem::create("")); - continue; - } - result_items.push_back(BodyItem::create(child.asString())); - } - - size_t index = 0; - for(const Json::Value &child : json_data) { - BodyItem *body_item = nullptr; - if(index < result_items.size()) { - body_item = result_items[index].get(); - } else { - result_items.push_back(BodyItem::create("")); - body_item = result_items.back().get(); - } - - ++index; - - if(!child.isString()) - continue; - - body_item->url = mangatown_url + child.asString(); - } - - return SuggestionResult::OK; -#else std::string url = "https://www.mangatown.com/search?name="; url += url_param_encode(text); @@ -146,7 +90,6 @@ namespace QuickMedia { cleanup: quickmedia_html_search_deinit(&html_search); return SuggestionResult::OK; -#endif } static bool is_number_with_zero_fill(const char *str) { diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 9ba1b6b..48d29eb 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -21,18 +21,6 @@ namespace QuickMedia { } - PluginResult Matrix::get_cached_sync(BodyItems &result_items) { - /* - Path sync_cache_path = get_cache_dir().join(name).join("sync.json"); - Json::Value root; - if(!read_file_as_json(sync_cache_path, root)) - return PluginResult::ERR; - return sync_response_to_body_items(root, result_items); - */ - (void)result_items; - return PluginResult::OK; - } - PluginResult Matrix::sync(RoomSyncMessages &room_messages) { std::vector additional_args = { { "-H", "Authorization: Bearer " + access_token }, @@ -40,16 +28,6 @@ namespace QuickMedia { }; std::string server_response; - // timeout=30000, filter=0. First sync should be without filter and timeout=0, then all other sync should be with timeout=30000 and filter=0. - // GET https://glowers.club/_matrix/client/r0/user/%40dec05eba%3Aglowers.club/filter/0 first to check if the filter is available - // and if lazy load members is available and get limit to use with https://glowers.club/_matrix/client/r0/rooms/!oSXkiqBKooDcZsmiGO%3Aglowers.club/ - // when first launching the client. This call to /rooms/ should be called before /sync/, when accessing a room. But only the first time - // (for the session). - - // Note: the first sync call with always exclude since= (next_batch) because we want to receive the latest messages in a room, - // which is important if we for example login to matrix after having not been online for several days and there are many new messages. - // We should be shown the latest messages first and if the user wants to see older messages then they should scroll up. - // Note: missed mentions are received in /sync and they will remain in new /sync unless we send a read receipt that we have read them. char url[512]; if(next_batch.empty()) @@ -84,19 +62,6 @@ namespace QuickMedia { fprintf(stderr, "Matrix: missing next batch\n"); } - // TODO: Only create the first time sync is called? - /* - Path sync_cache_path = get_cache_dir().join(name); - if(create_directory_recursive(sync_cache_path) == 0) { - sync_cache_path.join("sync.json"); - if(!save_json_to_file_atomic(sync_cache_path, json_root)) { - fprintf(stderr, "Warning: failed to save sync response to %s\n", sync_cache_path.data.c_str()); - } - } else { - fprintf(stderr, "Warning: failed to create directory: %s\n", sync_cache_path.data.c_str()); - } - */ - return PluginResult::OK; } diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index 186852b..8e13789 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -154,25 +154,9 @@ namespace QuickMedia { size_t index; }; - // Returns empty string on error - // static std::string view_url_get_id(const std::string &url) { - // size_t index = url.rfind('/'); - // if(index == std::string::npos) - // return ""; - // return url.substr(index); - // } - PluginResult NyaaSi::get_content_details(const std::string&, const std::string &url, BodyItems &result_items) { size_t comments_start_index; - // std::string id = view_url_get_id(url); - // if(id.empty()) { - // fprintf(stderr, "Error: nyaa.si: failed to extract id from url %s\n", url.c_str()); - // return PluginResult::ERR; - // } - - // std::string torrent_url = "https://nyaa.si/download/" + id + ".torrent"; - // auto torrent_item = BodyItem::create("Download torrent"); - // torrent_item->url = "https://nyaa.si/download/" + id + ".torrent"; + auto torrent_item = BodyItem::create("Download magnet"); std::string magnet_url; std::string description; -- cgit v1.2.3