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/DownloadUtils.cpp | 22 ---------- src/QuickMedia.cpp | 104 +++------------------------------------------- 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 +------- 7 files changed, 14 insertions(+), 261 deletions(-) (limited to 'src') diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index e748198..dc99028 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -75,26 +75,4 @@ namespace QuickMedia { return download_result; } } - - std::vector create_command_args_from_form_data(const std::vector &form_data) { - // TODO: This boundary value might need to change, depending on the content. What if the form data contains the boundary value? - const std::string boundary = "-----------------------------119561554312148213571335532670"; - std::string form_data_str; - for(const FormData &form_data_item : form_data) { - form_data_str += boundary; - form_data_str += "\r\n"; - // TODO: What if the form key contains " or \r\n ? - form_data_str += "Content-Disposition: form-data; name=\"" + form_data_item.key + "\""; - form_data_str += "\r\n\r\n"; - // TODO: What is the value contains \r\n ? - form_data_str += form_data_item.value; - form_data_str += "\r\n"; - } - // TODO: Verify if this should only be done also if the form data is empty - form_data_str += boundary + "--"; - return { - CommandArg{"-H", "Content-Type: multipart/form-data; boundary=" + boundary}, - CommandArg{"--data-binary", std::move(form_data_str)} - }; - } } \ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index bd9b091..c68ad0b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -505,12 +505,6 @@ namespace QuickMedia { search_suggestion_page(); body->clear_thumbnails(); break; -#if 0 - case Page::SEARCH_RESULT: - body->draw_thumbnails = current_plugin->search_results_has_thumbnails(); - search_result_page(); - break; -#endif case Page::VIDEO_CONTENT: body->draw_thumbnails = false; video_content_page(); @@ -952,7 +946,6 @@ namespace QuickMedia { } else if(next_page == Page::VIDEO_CONTENT) { watched_videos.clear(); if(content_url.empty()) - //next_page = Page::SEARCH_RESULT; next_page = Page::SEARCH_SUGGESTION; else { page_stack.push(Page::SEARCH_SUGGESTION); @@ -1072,23 +1065,12 @@ namespace QuickMedia { return on_search_suggestion_submit_text(tabs[selected_tab].body, body); }; - std::future recommended_future; - /* - if(recommended_body) { - recommended_future = std::async(std::launch::async, [this]() { - BodyItems body_items; - PluginResult front_page_result = current_plugin->get_front_page(body_items); - return body_items; - }); - } else { - */ - if(current_plugin->get_front_page(body->items) != PluginResult::OK) { - show_notification("QuickMedia", "Failed to get front page", Urgency::CRITICAL); - current_page = Page::EXIT; - return; - } - body->clamp_selection(); - /*}*/ + if(current_plugin->get_front_page(body->items) != PluginResult::OK) { + show_notification("QuickMedia", "Failed to get front page", Urgency::CRITICAL); + current_page = Page::EXIT; + return; + } + body->clamp_selection(); sf::Vector2f body_pos; sf::Vector2f body_size; @@ -1103,8 +1085,6 @@ namespace QuickMedia { sf::RoundedRectangleShape tab_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10); tab_background.setFillColor(tab_selected_color); - //sf::Clock tt; - //int fps = 0; while (current_page == Page::SEARCH_SUGGESTION) { while (window.pollEvent(event)) { base_event_handler(event, Page::EXIT, false, true, tabs[selected_tab].body != nullptr); @@ -1208,14 +1188,6 @@ namespace QuickMedia { autocomplete_running = false; } - /* - if(recommended_future.valid() && recommended_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { - recommended_body->items = recommended_future.get(); - recommended_body->filter_search_fuzzy(recommended_filter); - recommended_body->clamp_selection(); - } - */ - window.clear(back_color); if(tabs[selected_tab].body) search_bar->draw(window, false); @@ -1251,12 +1223,6 @@ namespace QuickMedia { } } - // fps++; - // if(tt.getElapsedTime().asMilliseconds() >= 1000) { - // fprintf(stderr, "fps: %d\n", fps); - // fps = 0; - // tt.restart(); - // } window.display(); } @@ -1264,52 +1230,6 @@ namespace QuickMedia { search_bar->onAutocompleteRequestCallback = nullptr; } - void Program::search_result_page() { - assert(false); - #if 0 - search_bar->onTextUpdateCallback = [this](const std::string &text) { - body->filter_search_fuzzy(text); - body->clamp_selection(); - }; - - search_bar->onTextSubmitCallback = [this](const std::string &text) { - BodyItem *selected_item = body->get_selected(); - if(!selected_item) - return; - video_url = selected_item->url; - current_page = Page::VIDEO_CONTENT; - }; - - sf::Vector2f body_pos; - sf::Vector2f body_size; - bool redraw = true; - sf::Event event; - - while (current_page == Page::SEARCH_RESULT) { - while (window.pollEvent(event)) { - base_event_handler(event, Page::SEARCH_SUGGESTION); - if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) - redraw = true; - } - - if(redraw) { - redraw = false; - search_bar->onWindowResize(window_size); - get_body_dimensions(window_size, search_bar.get(), body_pos, body_size); - } - - search_bar->update(); - - window.clear(back_color); - search_bar->draw(window); - body->draw(window, body_pos, body_size); - - window.display(); - faefeaf - } - #endif - } - static bool youtube_url_extract_id(const std::string &youtube_url, std::string &youtube_video_id) { size_t index = youtube_url.find("youtube.com/watch?v="); if(index != std::string::npos) { @@ -1721,8 +1641,6 @@ namespace QuickMedia { } // TODO: Show loading video animation. load_video needs to be made asynchronous first - //window.clear(); - //window.display(); /* Only save recommendations for the video if we have been watching it for 15 seconds */ if(is_youtube && video_loaded && !added_recommendations && time_watched_timer.getElapsedTime().asSeconds() >= 15) { @@ -2057,17 +1975,7 @@ namespace QuickMedia { image_plugin->for_each_page_in_chapter(chapter_url, [content_cache_dir_, &page, this](const std::string &url) { if(image_download_cancel) return false; - #if 0 - size_t last_index = url.find_last_of('/'); - if(last_index == std::string::npos || (int)url.size() - (int)last_index + 1 <= 0) { - show_notification("Manganelo", "Image url is in incorrect format, missing '/': " + url, Urgency::CRITICAL); - return false; - } - std::string image_filename = url.substr(last_index + 1); - Path image_filepath = content_cache_dir_; - image_filepath.join(image_filename); - #endif // TODO: Save image with the file extension that url says it has? right now the file is saved without any extension Path image_filepath = content_cache_dir_; image_filepath.join(std::to_string(page++)); 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