aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Manga.hpp19
-rw-r--r--plugins/Mangadex.hpp31
-rw-r--r--plugins/Manganelo.hpp16
-rw-r--r--plugins/Plugin.hpp1
4 files changed, 58 insertions, 9 deletions
diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp
new file mode 100644
index 0000000..18ed2f9
--- /dev/null
+++ b/plugins/Manga.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Plugin.hpp"
+#include <functional>
+#include <mutex>
+
+namespace QuickMedia {
+ // Return false to stop iteration
+ using PageCallback = std::function<bool(const std::string &url)>;
+
+ class Manga : public Plugin {
+ public:
+ Manga(const std::string &plugin_name) : Plugin(plugin_name) {}
+ bool is_manga() override { return true; }
+ virtual ImageResult get_number_of_images(const std::string &url, int &num_images) = 0;
+ virtual ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) = 0;
+ virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) = 0;
+ };
+} \ No newline at end of file
diff --git a/plugins/Mangadex.hpp b/plugins/Mangadex.hpp
new file mode 100644
index 0000000..9d6d366
--- /dev/null
+++ b/plugins/Mangadex.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "Manga.hpp"
+#include <functional>
+#include <mutex>
+
+namespace QuickMedia {
+ class Mangadex : public Manga {
+ public:
+ Mangadex() : Manga("mangadex") {}
+ SearchResult search(const std::string &url, BodyItems &result_items) override;
+ SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override;
+ ImageResult get_number_of_images(const std::string &url, int &num_images) override;
+ bool search_suggestions_has_thumbnails() const override { return true; }
+ bool search_results_has_thumbnails() const override { return false; }
+ int get_search_delay() const override { return 300; }
+ Page get_page_after_search() const override { return Page::EPISODE_LIST; }
+
+ ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override;
+
+ bool extract_id_from_url(const std::string &url, std::string &manga_id) override;
+ private:
+ SearchResult search_page(const std::string &url, BodyItems &result_items, int page, bool *is_last_page);
+ // Caches url. If the same url is requested multiple times then the cache is used
+ ImageResult get_image_urls_for_chapter(const std::string &url);
+ private:
+ std::string last_chapter_url;
+ std::vector<std::string> last_chapter_image_urls;
+ std::mutex image_urls_mutex;
+ };
+} \ No newline at end of file
diff --git a/plugins/Manganelo.hpp b/plugins/Manganelo.hpp
index 3405de2..ffac830 100644
--- a/plugins/Manganelo.hpp
+++ b/plugins/Manganelo.hpp
@@ -1,26 +1,24 @@
#pragma once
-#include "Plugin.hpp"
+#include "Manga.hpp"
#include <functional>
#include <mutex>
namespace QuickMedia {
- // Return false to stop iteration
- using PageCallback = std::function<bool(const std::string &url)>;
-
- class Manganelo : public Plugin {
+ class Manganelo : public Manga {
public:
- Manganelo() : Plugin("manganelo") {}
+ Manganelo() : Manga("manganelo") {}
SearchResult search(const std::string &url, BodyItems &result_items) override;
SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override;
- ImageResult get_image_by_index(const std::string &url, int index, std::string &image_data);
- ImageResult get_number_of_images(const std::string &url, int &num_images);
+ ImageResult get_number_of_images(const std::string &url, int &num_images) override;
bool search_suggestions_has_thumbnails() const override { return true; }
bool search_results_has_thumbnails() const override { return false; }
int get_search_delay() const override { return 150; }
Page get_page_after_search() const override { return Page::EPISODE_LIST; }
- ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback);
+ ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override;
+
+ bool extract_id_from_url(const std::string &url, std::string &manga_id) override;
private:
// Caches url. If the same url is requested multiple times then the cache is used
ImageResult get_image_urls_for_chapter(const std::string &url);
diff --git a/plugins/Plugin.hpp b/plugins/Plugin.hpp
index e19fbcd..b430d57 100644
--- a/plugins/Plugin.hpp
+++ b/plugins/Plugin.hpp
@@ -42,6 +42,7 @@ namespace QuickMedia {
virtual ~Plugin() = default;
virtual bool is_image_board() { return false; }
+ virtual bool is_manga() { return false; }
virtual PluginResult get_front_page(BodyItems &result_items) {
(void)result_items; return PluginResult::OK;