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/plugins | |
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/plugins')
-rw-r--r-- | src/plugins/MangaCombined.cpp | 58 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 8 |
2 files changed, 37 insertions, 29 deletions
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; |