aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-23 07:42:13 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-23 07:42:13 +0200
commitaa9a861c662f7c65cde92fbf133deaca3692bbd2 (patch)
tree37c8b2eddfc6315a45607325ca4abe6fca13ca76
parent261b0263f34ffcbe439d68b2e901fd3abbfc1eaf (diff)
Mangadex: implement pagination
-rw-r--r--plugins/Mangadex.hpp2
-rw-r--r--plugins/Page.hpp3
-rw-r--r--src/QuickMedia.cpp1
-rw-r--r--src/plugins/Mangadex.cpp14
4 files changed, 14 insertions, 6 deletions
diff --git a/plugins/Mangadex.hpp b/plugins/Mangadex.hpp
index 96bfc50..00da59c 100644
--- a/plugins/Mangadex.hpp
+++ b/plugins/Mangadex.hpp
@@ -10,9 +10,11 @@ namespace QuickMedia {
const char* get_title() const override { return "All"; }
bool search_is_filter() override { return false; }
SearchResult search(const std::string &str, BodyItems &result_items) override;
+ PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
sf::Vector2i get_thumbnail_max_size() override { return sf::Vector2i(101, 141); };
private:
+ SearchResult search(const std::string &str, int page, BodyItems &result_items);
bool get_rememberme_token(std::string &rememberme_token);
std::optional<std::string> rememberme_token;
};
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index b4ea9a6..d8f1d05 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -21,7 +21,8 @@ namespace QuickMedia {
// Return empty |result_tabs| and PluginResult::OK to do nothing; which is useful for implementing custom actions on item submit
virtual PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) = 0;
- // Note: If pagination is done by fetching the next page until we get to |page|, then the "current page" should be reset everytime |search| is called
+ // Note: If pagination is done by fetching the next page until we get to |page|, then the "current page" should be reset everytime |search| is called.
+ // Note: the first page is 0
virtual PluginResult get_page(const std::string &str, int page, BodyItems &result_items) { (void)str; (void)page; (void)result_items; return PluginResult::OK; }
virtual BodyItems get_related_media(const std::string &url);
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c9950a0..6d8f493 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1249,7 +1249,6 @@ namespace QuickMedia {
if(associated_data.search_text_updated && associated_data.fetch_status == FetchStatus::NONE && !associated_data.fetching_next_page_running) {
std::string update_search_text = associated_data.update_search_text;
- associated_data.update_search_text.clear();
associated_data.search_text_updated = false;
associated_data.fetch_status = FetchStatus::LOADING;
associated_data.fetch_type = FetchType::SEARCH;
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp
index e798b60..a52788d 100644
--- a/src/plugins/Mangadex.cpp
+++ b/src/plugins/Mangadex.cpp
@@ -55,14 +55,12 @@ namespace QuickMedia {
bool *is_last_page;
};
- // TODO: Implement pagination (go to next page and get all results as well)
- SearchResult MangadexSearchPage::search(const std::string &str, BodyItems &result_items) {
+ SearchResult MangadexSearchPage::search(const std::string &str, int page, BodyItems &result_items) {
std::string rememberme_token;
if(!get_rememberme_token(rememberme_token))
return SearchResult::ERR;
- std::string url = "https://mangadex.org/search?title=";
- url += url_param_encode(str);
+ std::string url = "https://mangadex.org/search?s=0&p=" + std::to_string(page) + "&tag_mode_inc=all&tag_mode_exc=any&title=" + url_param_encode(str) +"#listing";
CommandArg cookie_arg = { "-H", "cookie: mangadex_rememberme_token=" + rememberme_token };
std::string website_data;
@@ -111,6 +109,14 @@ namespace QuickMedia {
return result == 0 ? SearchResult::OK : SearchResult::ERR;
}
+ SearchResult MangadexSearchPage::search(const std::string &str, BodyItems &result_items) {
+ return search(str, 1, result_items);
+ }
+
+ PluginResult MangadexSearchPage::get_page(const std::string &str, int page, BodyItems &result_items) {
+ return search_result_to_plugin_result(search(str, 1 + page, result_items));
+ }
+
PluginResult MangadexSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
std::string request_url = "https://mangadex.org/api/?id=" + title_url_extract_manga_id(url) + "&type=manga";