diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-05-02 01:01:39 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-05-02 01:01:39 +0200 |
commit | d1f1683bc44ebc51b45083280adabf60d0dd27d7 (patch) | |
tree | b448da7229683f3c5822eb072ac3edba1f2490f6 /src | |
parent | 08740aec621a296497c8ed168672d62c3aad663e (diff) |
Make submit async, sort manga combined view by manga service name, show correct timeout, use youtube thumbnail without black bars at top and bottom
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 25 | ||||
-rw-r--r-- | src/plugins/MangaCombined.cpp | 58 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 8 |
3 files changed, 53 insertions, 38 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index b9f0bc8..64f326b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -354,8 +354,8 @@ namespace QuickMedia { auto body_item = BodyItem::create(recommended_title_json.asString()); body_item->url = "https://www.youtube.com/watch?v=" + recommended_item_id; - body_item->thumbnail_url = "https://img.youtube.com/vi/" + recommended_item_id + "/hqdefault.jpg"; - body_item->thumbnail_size = sf::Vector2i(175, 131); + body_item->thumbnail_url = "https://img.youtube.com/vi/" + recommended_item_id + "/mqdefault.jpg"; + body_item->thumbnail_size = sf::Vector2i(192, 108); body_items.push_back(std::move(body_item)); // We dont want more than 150 recommendations @@ -765,7 +765,7 @@ namespace QuickMedia { } static void add_mangatown_handlers(MangaGenericSearchPage *manga_generic_search_page) { - manga_generic_search_page->search_handler("https://mangatown.com/search?name=%s&page=%p", 1) + manga_generic_search_page->search_handler("https://www.mangatown.com/search?name=%s&page=%p", 1) .text_handler({{"//p[class='title']/a", "title", "href", "/manga/"}}) .thumbnail_handler({{"//a[class='manga_cover']/img", "src", nullptr}}) .authors_handler({ @@ -1182,9 +1182,10 @@ namespace QuickMedia { auto body_item = BodyItem::create(std::move(title_str)); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; - body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg"; + body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/mqdefault.jpg"; body_item->set_description("Watched " + seconds_to_relative_time_str(time_now - timestamp.asInt64())); - body_item->thumbnail_size = sf::Vector2i(175, 131); + body_item->set_description_color(sf::Color(179, 179, 179)); + body_item->thumbnail_size = sf::Vector2i(192, 108); body_items.push_back(std::move(body_item)); } @@ -1458,12 +1459,20 @@ namespace QuickMedia { auto selected_item = tabs[selected_tab].body->get_selected_shared(); if(!selected_item && !tabs[selected_tab].page->allow_submit_no_selection()) return; + + hide_virtual_keyboard(); std::vector<Tab> new_tabs; auto prev_selected_item = tabs[selected_tab].page->submit_body_item; tabs[selected_tab].page->submit_body_item = selected_item; - PluginResult submit_result = tabs[selected_tab].page->submit(selected_item ? selected_item->get_title() : search_text, selected_item ? selected_item->url : "", new_tabs); - if(submit_result != PluginResult::OK) { + TaskResult submit_result = run_task_with_loading_screen([&tabs, selected_tab, &selected_item, &search_text, &new_tabs](){ + PluginResult submit_result = tabs[selected_tab].page->submit(selected_item ? selected_item->get_title() : search_text, selected_item ? selected_item->url : "", new_tabs); + return submit_result == PluginResult::OK; + }); + + if(submit_result == TaskResult::CANCEL) { + return; + } else if(submit_result != TaskResult::TRUE) { // TODO: Show the exact cause of error (get error message from curl). show_notification("QuickMedia", std::string("Submit failed for page ") + tabs[selected_tab].page->get_title(), Urgency::CRITICAL); return; @@ -1502,8 +1511,6 @@ namespace QuickMedia { tab.body->clear_cache(); } - hide_virtual_keyboard(); - if(tabs[selected_tab].page->allow_submit_no_selection()) { page_loop(new_tabs, 0, after_submit_handler); } else if(new_tabs.size() == 1 && new_tabs[0].page->get_type() == PageTypez::MANGA_IMAGES) { diff --git a/src/plugins/MangaCombined.cpp b/src/plugins/MangaCombined.cpp index ea6188c..1745ee0 100644 --- a/src/plugins/MangaCombined.cpp +++ b/src/plugins/MangaCombined.cpp @@ -1,7 +1,7 @@ #include "../../plugins/MangaCombined.hpp" namespace QuickMedia { - static const int SEARCH_TIMEOUT_MILLISECONDS = 6000; + static const int SEARCH_TIMEOUT_MILLISECONDS = 5000; MangaCombinedSearchPage::MangaCombinedSearchPage(Program *program, std::vector<MangaPlugin> search_pages) : Page(program), search_pages(std::move(search_pages)) @@ -9,43 +9,35 @@ namespace QuickMedia { } - static void result_items_add_thread_results(std::vector<std::pair<MangaPlugin*, AsyncTask<BodyItems>>> &search_threads, BodyItems &result_items) { - std::vector<std::pair<MangaPlugin*, bool>> plugin_finished_state(search_threads.size()); + using PluginFinishedState = std::pair<MangaPlugin*, std::unique_ptr<BodyItems>>; + static void result_items_add_thread_results(std::vector<MangaCombinedSearchThread> &search_threads, BodyItems &result_items) { + std::sort(search_threads.begin(), search_threads.end(), [](const MangaCombinedSearchThread &plugin1, const MangaCombinedSearchThread &plugin2){ + return plugin1.first->title < plugin2.first->title; + }); + + std::vector<PluginFinishedState> plugin_finished_state(search_threads.size()); for(size_t i = 0; i < plugin_finished_state.size(); ++i) { plugin_finished_state[i].first = search_threads[i].first; + plugin_finished_state[i].second = nullptr; } int accumulated_sleep_time = 0; while(true) { - size_t finshed_plugin_index = 0; - for(auto &f : plugin_finished_state) { - f.second = false; - } - - for(auto &search_thread : search_threads) { - if(!search_thread.second.valid()) { - plugin_finished_state[finshed_plugin_index].second = true; - ++finshed_plugin_index; + for(size_t i = 0; i < search_threads.size(); ++i) { + auto &search_thread = search_threads[i]; + if(!search_thread.second.valid()) continue; - } if(!search_thread.second.ready()) continue; - BodyItems search_page_body_items = search_thread.second.get(); - plugin_finished_state[finshed_plugin_index].second = true; - ++finshed_plugin_index; - if(search_page_body_items.empty()) + plugin_finished_state[i].second = std::make_unique<BodyItems>(search_thread.second.get()); + if(plugin_finished_state[i].second->empty()) continue; - auto title_item = BodyItem::create(""); - title_item->set_author("------------------------ " + search_thread.first->title + " ------------------------"); - result_items.push_back(std::move(title_item)); - - for(auto &new_body_item : search_page_body_items) { + for(auto &new_body_item : *plugin_finished_state[i].second) { new_body_item->userdata = search_thread.first->page.get(); } - result_items.insert(result_items.end(), std::move_iterator(search_page_body_items.begin()), std::move_iterator(search_page_body_items.end())); } size_t num_finished_plugins = 0; @@ -54,15 +46,31 @@ namespace QuickMedia { ++num_finished_plugins; } - if(num_finished_plugins == search_threads.size()) + if(num_finished_plugins == search_threads.size()) { + for(auto &f : plugin_finished_state) { + if(f.second && !f.second->empty()) { + auto title_item = BodyItem::create(""); + title_item->set_author("------------------------ " + f.first->title + " ------------------------"); + result_items.push_back(std::move(title_item)); + result_items.insert(result_items.end(), std::move_iterator(f.second->begin()), std::move_iterator(f.second->end())); + } + } break; + } int sleep_time_ms = 200; std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_ms)); accumulated_sleep_time += sleep_time_ms; if(accumulated_sleep_time >= SEARCH_TIMEOUT_MILLISECONDS) { for(auto &f : plugin_finished_state) { - if(!f.second) { + if(f.second) { + if(!f.second->empty()) { + auto title_item = BodyItem::create(""); + title_item->set_author("------------------------ " + f.first->title + " ------------------------"); + result_items.push_back(std::move(title_item)); + result_items.insert(result_items.end(), std::move_iterator(f.second->begin()), std::move_iterator(f.second->end())); + } + } else { auto title_item = BodyItem::create(""); title_item->set_author("------------------------ " + f.first->title + " timed out ------------------------"); result_items.push_back(std::move(title_item)); diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index cf3bbe4..6149b84 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -196,8 +196,8 @@ namespace QuickMedia { if(scheduled_text.empty()) body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; - body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg"; - body_item->thumbnail_size = sf::Vector2i(175, 131); + body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/mqdefault.jpg"; + body_item->thumbnail_size = sf::Vector2i(192, 108); added_videos.insert(video_id_str); return body_item; @@ -1345,8 +1345,8 @@ namespace QuickMedia { body_item->set_description("Uploaded " + seconds_to_relative_time_str(time_now - subscription_data.subscription_entry.published)); body_item->set_description_color(sf::Color(179, 179, 179)); body_item->url = "https://www.youtube.com/watch?v=" + subscription_data.subscription_entry.video_id; - body_item->thumbnail_url = "https://img.youtube.com/vi/" + subscription_data.subscription_entry.video_id + "/hqdefault.jpg"; - body_item->thumbnail_size = sf::Vector2i(175, 131); + body_item->thumbnail_url = "https://img.youtube.com/vi/" + subscription_data.subscription_entry.video_id + "/mqdefault.jpg"; + body_item->thumbnail_size = sf::Vector2i(192, 108); results.push_back({std::move(body_item), subscription_data.subscription_entry.published}); } return results; |