aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-11 21:35:37 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-13 13:13:01 +0200
commit77ed51898157d99112be7550471ec06e32344c9e (patch)
tree0645274d0f13b4fa6940d4054f74a070611a8ef0 /plugins
parentda89ec98fb34757f0c46dc8cb2dd87ae78d317ce (diff)
Refactor plugin into seperate pages
TODO: Readd 4chan login page, manganelo creators page, autocomplete
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dmenu.hpp20
-rw-r--r--plugins/FileManager.hpp20
-rw-r--r--plugins/Fourchan.hpp61
-rw-r--r--plugins/ImageBoard.hpp28
-rw-r--r--plugins/Manga.hpp49
-rw-r--r--plugins/Mangadex.hpp43
-rw-r--r--plugins/Manganelo.hpp49
-rw-r--r--plugins/Mangatown.hpp38
-rw-r--r--plugins/Matrix.hpp31
-rw-r--r--plugins/NyaaSi.hpp46
-rw-r--r--plugins/Page.hpp61
-rw-r--r--plugins/Plugin.hpp72
-rw-r--r--plugins/Pornhub.hpp29
-rw-r--r--plugins/Youtube.hpp36
14 files changed, 327 insertions, 256 deletions
diff --git a/plugins/Dmenu.hpp b/plugins/Dmenu.hpp
deleted file mode 100644
index 32fdad1..0000000
--- a/plugins/Dmenu.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include "Plugin.hpp"
-
-namespace QuickMedia {
- class Dmenu : public Plugin {
- public:
- Dmenu();
- bool search_is_filter() override { return true; }
- bool search_suggestions_has_thumbnails() const override { return false; }
- bool search_results_has_thumbnails() const override { return false; }
- int get_search_delay() const override { return 50; }
- bool search_suggestion_is_search() const override { return true; }
- Page get_page_after_search() const override { return Page::EXIT; }
- PluginResult get_front_page(BodyItems &result_items) override;
- SearchResult search(const std::string &text, BodyItems &result_items) override;
- private:
- std::vector<std::string> stdin_data;
- };
-} \ No newline at end of file
diff --git a/plugins/FileManager.hpp b/plugins/FileManager.hpp
index f13184b..38babc1 100644
--- a/plugins/FileManager.hpp
+++ b/plugins/FileManager.hpp
@@ -1,22 +1,18 @@
#pragma once
-#include "Plugin.hpp"
+#include "Page.hpp"
#include <filesystem>
namespace QuickMedia {
- class FileManager : public Plugin {
+ class FileManagerPage : public Page {
public:
- FileManager();
- virtual ~FileManager() = default;
- PluginResult get_files_in_directory(BodyItems &result_items);
- bool set_current_directory(const std::string &path);
- bool set_child_directory(const std::string &filename);
- const std::filesystem::path& get_current_dir() const;
+ FileManagerPage(Program *program) : Page(program), current_dir("/") {}
+ const char* get_title() const override { return current_dir.c_str(); }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ bool is_single_page() const override { return true; }
- bool search_suggestions_has_thumbnails() const override { return true; }
- bool search_results_has_thumbnails() const override { return true; }
- int get_search_delay() const override { return 50; }
- Page get_page_after_search() const override { return Page::FILE_MANAGER; }
+ bool set_current_directory(const std::string &path);
+ PluginResult get_files_in_directory(BodyItems &result_items);
private:
std::filesystem::path current_dir;
};
diff --git a/plugins/Fourchan.hpp b/plugins/Fourchan.hpp
index bc336bf..3ee07dd 100644
--- a/plugins/Fourchan.hpp
+++ b/plugins/Fourchan.hpp
@@ -1,49 +1,38 @@
#pragma once
#include "ImageBoard.hpp"
-#include <thread>
-#include <mutex>
-#include <condition_variable>
namespace QuickMedia {
- class Program;
+ class FourchanBoardsPage : public Page {
+ public:
+ FourchanBoardsPage(Program *program, std::string resources_root) : Page(program), resources_root(std::move(resources_root)) {}
+ const char* get_title() const override { return "Select board"; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ void get_boards(BodyItems &result_items);
+
+ const std::string resources_root;
+ };
- class Fourchan : public ImageBoard {
+ class FourchanThreadListPage : public Page {
public:
- Fourchan(const std::string &resources_root);
- ~Fourchan() override;
- PluginResult get_front_page(BodyItems &result_items) override;
- PluginResult get_threads(const std::string &url, BodyItems &result_items) override;
- PluginResult get_thread_comments(const std::string &list_url, const std::string &url, BodyItems &result_items) override;
- PostResult post_comment(const std::string &board, const std::string &thread, const std::string &captcha_id, const std::string &comment) override;
- bool search_suggestions_has_thumbnails() const override { return false; }
- 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::IMAGE_BOARD_THREAD_LIST; }
- bool search_is_filter() override { return true; }
- BodyItems get_related_media(const std::string &url) override;
+ FourchanThreadListPage(Program *program, std::string title, std::string board_id) : Page(program), title(std::move(title)), board_id(std::move(board_id)) {}
+ const char* get_title() const override { return title.c_str(); }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
- PluginResult login(const std::string &token, const std::string &pin, std::string &response_msg);
- const std::string& get_pass_id() const override;
+ const std::string title;
+ const std::string board_id;
private:
- PluginResult get_threads_internal(const std::string &url, BodyItems &result_items);
- void set_board_url(const std::string &new_url);
- std::string get_board_url();
- void set_board_thread_list(BodyItems body_items);
- BodyItems get_board_thread_list();
- private:
- std::string current_board_url;
- std::thread thread_list_update_thread;
- BodyItems cached_thread_list_items;
- std::mutex board_url_mutex;
- std::mutex board_list_mutex;
- std::condition_variable thread_list_cached_cv;
- std::mutex thread_list_cache_mutex;
- std::condition_variable thread_list_update_cv;
- bool thread_list_cached = false;
- bool running = true;
std::vector<std::string> cached_media_urls;
- std::string resources_root;
+ };
+
+ class FourchanThreadPage : public ImageBoardThreadPage {
+ public:
+ FourchanThreadPage(Program *program, std::string board_id, std::string thread_id, std::vector<std::string> cached_media_urls) : ImageBoardThreadPage(program, std::move(board_id), std::move(thread_id), std::move(cached_media_urls)) {}
+
+ PluginResult login(const std::string &token, const std::string &pin, std::string &response_msg) override;
+ PostResult post_comment(const std::string &captcha_id, const std::string &comment) override;
+ const std::string& get_pass_id() override;
+ private:
std::string pass_id;
};
} \ No newline at end of file
diff --git a/plugins/ImageBoard.hpp b/plugins/ImageBoard.hpp
index abab22e..6f2a276 100644
--- a/plugins/ImageBoard.hpp
+++ b/plugins/ImageBoard.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "Plugin.hpp"
+#include "Page.hpp"
namespace QuickMedia {
enum class PostResult {
@@ -10,16 +10,26 @@ namespace QuickMedia {
ERR
};
- class ImageBoard : public Plugin {
+ class ImageBoardThreadPage : public Page {
public:
- ImageBoard(const std::string &name) : Plugin(name) {}
- virtual ~ImageBoard() = default;
+ ImageBoardThreadPage(Program *program, std::string board_id, std::string thread_id, std::vector<std::string> cached_media_urls) : Page(program), board_id(std::move(board_id)), thread_id(std::move(thread_id)), cached_media_urls(std::move(cached_media_urls)) {}
+ const char* get_title() const override { return ""; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ return PluginResult::ERR;
+ }
- bool is_image_board() override { return true; }
- virtual const std::string& get_pass_id() const = 0;
+ bool is_image_board_thread_page() const override { return true; }
- virtual PluginResult get_threads(const std::string &url, BodyItems &result_items) = 0;
- virtual PluginResult get_thread_comments(const std::string &list_url, const std::string &url, BodyItems &result_items) = 0;
- virtual PostResult post_comment(const std::string &board, const std::string &thread, const std::string &captcha_id, const std::string &comment) = 0;
+ virtual BodyItems get_related_media(const std::string &url) override;
+ virtual PluginResult login(const std::string &token, const std::string &pin, std::string &response_msg);
+ virtual PostResult post_comment(const std::string &captcha_id, const std::string &comment) = 0;
+ virtual const std::string& get_pass_id();
+
+ const std::string board_id;
+ const std::string thread_id;
+ const std::vector<std::string> cached_media_urls;
};
} \ No newline at end of file
diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp
index 13c494e..732e208 100644
--- a/plugins/Manga.hpp
+++ b/plugins/Manga.hpp
@@ -1,8 +1,7 @@
#pragma once
-#include "Plugin.hpp"
+#include "Page.hpp"
#include <functional>
-#include <mutex>
namespace QuickMedia {
// Return false to stop iteration
@@ -13,18 +12,46 @@ namespace QuickMedia {
std::string url;
};
- class Manga : public Plugin {
+ class MangaImagesPage : public Page {
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;
+ MangaImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url) : Page(program), manga_name(std::move(manga_name)), chapter_name(std::move(chapter_name)), url(std::move(url)) {}
+ virtual ~MangaImagesPage() = default;
+ const char* get_title() const override { return chapter_name.c_str(); }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ return PluginResult::OK;
+ }
- virtual PluginResult get_creators_manga_list(const std::string &url, BodyItems &result_items) { (void)url; (void)result_items; return {}; }
+ bool is_manga_images_page() const override { return true; }
- const std::vector<Creator>& get_creators() const;
+ virtual ImageResult get_number_of_images(int &num_images) = 0;
+ virtual ImageResult for_each_page_in_chapter(PageCallback callback) = 0;
+
+ virtual void change_chapter(std::string new_chapter_name, std::string new_url) {
+ chapter_name = std::move(new_chapter_name);
+ if(url != new_url) {
+ url = std::move(new_url);
+ chapter_image_urls.clear();
+ }
+ }
+
+ const std::string& get_chapter_name() const { return chapter_name; }
+ const std::string& get_url() const { return url; }
+
+ virtual const char* get_service_name() const = 0;
+
+ const std::string manga_name;
protected:
- std::vector<Creator> creators;
+ std::string chapter_name;
+ std::string url;
+ std::vector<std::string> chapter_image_urls;
+ };
+
+ class MangaChaptersPage : public TrackablePage {
+ public:
+ MangaChaptersPage(Program *program, std::string manga_name, std::string manga_url) : TrackablePage(program, std::move(manga_name), std::move(manga_url)) {}
+ TrackResult track(const std::string &str) override;
};
} \ No newline at end of file
diff --git a/plugins/Mangadex.hpp b/plugins/Mangadex.hpp
index aaca18d..ba43498 100644
--- a/plugins/Mangadex.hpp
+++ b/plugins/Mangadex.hpp
@@ -2,32 +2,37 @@
#include "Manga.hpp"
#include <functional>
-#include <mutex>
namespace QuickMedia {
- class Mangadex : public Manga {
+ class MangadexSearchPage : public Page {
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; }
+ MangadexSearchPage(Program *program) : Page(program) {}
+ 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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ private:
+ bool get_rememberme_token(std::string &rememberme_token);
+ std::optional<std::string> rememberme_token;
+ };
+
+ class MangadexChaptersPage : public MangaChaptersPage {
+ public:
+ MangadexChaptersPage(Program *program, std::string manga_name, std::string manga_url) : MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)) {}
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ };
+
+ class MangadexImagesPage : public MangaImagesPage {
+ public:
+ MangadexImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url) : MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(url)) {}
- ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override;
+ ImageResult get_number_of_images(int &num_images) override;
+ ImageResult for_each_page_in_chapter(PageCallback callback) override;
- bool extract_id_from_url(const std::string &url, std::string &manga_id) override;
+ const char* get_service_name() const override { return "mangadex"; }
private:
- // Caches url. If the same url is requested multiple times then the cache is used
+ // Cached
ImageResult get_image_urls_for_chapter(const std::string &url);
- bool get_rememberme_token(std::string &rememberme_token);
bool save_mangadex_cookies(const std::string &url, const std::string &cookie_filepath);
- private:
- std::string last_chapter_url;
- std::vector<std::string> last_chapter_image_urls;
- std::mutex image_urls_mutex;
- std::optional<std::string> rememberme_token;
};
} \ No newline at end of file
diff --git a/plugins/Manganelo.hpp b/plugins/Manganelo.hpp
index c2ad693..d79f814 100644
--- a/plugins/Manganelo.hpp
+++ b/plugins/Manganelo.hpp
@@ -2,31 +2,44 @@
#include "Manga.hpp"
#include <functional>
-#include <mutex>
namespace QuickMedia {
- class Manganelo : public Manga {
+ class ManganeloSearchPage : public Page {
public:
- 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_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 200; }
- Page get_page_after_search() const override { return Page::EPISODE_LIST; }
+ ManganeloSearchPage(Program *program) : Page(program) {}
+ 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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ private:
+ bool extract_id_from_url(const std::string &url, std::string &manga_id) const;
+ };
- ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override;
+ class ManganeloChaptersPage : public MangaChaptersPage {
+ public:
+ ManganeloChaptersPage(Program *program, std::string manga_name, std::string manga_url) : MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)) {}
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ };
- bool extract_id_from_url(const std::string &url, std::string &manga_id) override;
+ class ManganeloCreatorPage : public Page {
+ public:
+ ManganeloCreatorPage(Program *program, Creator creator) : Page(program), creator(std::move(creator)) {}
+ const char* get_title() const override { return creator.name.c_str(); }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ private:
+ Creator creator;
+ };
+
+ class ManganeloImagesPage : public MangaImagesPage {
+ public:
+ ManganeloImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url) : MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(url)) {}
- PluginResult get_creators_manga_list(const std::string &url, BodyItems &result_items) override;
+ ImageResult get_number_of_images(int &num_images) override;
+ ImageResult for_each_page_in_chapter(PageCallback callback) override;
+
+ const char* get_service_name() const override { return "manganelo"; }
private:
- // Caches url. If the same url is requested multiple times then the cache is used
+ // Cached
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/Mangatown.hpp b/plugins/Mangatown.hpp
index 2a22ccd..c85b5b7 100644
--- a/plugins/Mangatown.hpp
+++ b/plugins/Mangatown.hpp
@@ -2,26 +2,34 @@
#include "Manga.hpp"
#include <functional>
-#include <mutex>
namespace QuickMedia {
- class Mangatown : public Manga {
+ class MangatownSearchPage : public Page {
public:
- Mangatown() : Manga("mangatown") {}
- 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 200; }
- Page get_page_after_search() const override { return Page::EPISODE_LIST; }
+ MangatownSearchPage(Program *program) : Page(program) {}
+ 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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ private:
+ bool extract_id_from_url(const std::string &url, std::string &manga_id) const;
+ };
+
+ class MangatownChaptersPage : public MangaChaptersPage {
+ public:
+ MangatownChaptersPage(Program *program, std::string manga_name, std::string manga_url) : MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)) {}
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ };
+
+ class MangatownImagesPage : public MangaImagesPage {
+ public:
+ MangatownImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url) : MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(url)) {}
- ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) override;
+ ImageResult get_number_of_images(int &num_images) override;
+ ImageResult for_each_page_in_chapter(PageCallback callback) override;
- bool extract_id_from_url(const std::string &url, std::string &manga_id) override;
+ const char* get_service_name() const override { return "mangatown"; }
private:
- std::string last_chapter_url_num_images;
- int last_num_pages = 0;
- std::mutex image_urls_mutex;
+ ImageResult get_image_urls_for_chapter(const std::string &url);
};
} \ No newline at end of file
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 4d7bc11..5819420 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -2,10 +2,27 @@
#include "../include/FileAnalyzer.hpp"
#include "Plugin.hpp"
+#include "Page.hpp"
+#include <SFML/Graphics/Color.hpp>
#include <unordered_map>
+#include <mutex>
#include <json/value.h>
namespace QuickMedia {
+ // Dummy, only play one video. TODO: Play all videos in room, as related videos?
+ class MatrixVideoPage : public Page {
+ public:
+ MatrixVideoPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return ""; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ return PluginResult::ERR;
+ }
+ bool is_video_page() const override { return true; }
+ };
+
struct RoomData;
struct UserInfo {
@@ -91,22 +108,13 @@ namespace QuickMedia {
using RoomSyncMessages = std::unordered_map<std::shared_ptr<RoomData>, std::vector<std::shared_ptr<Message>>>;
- class Matrix : public Plugin {
+ class Matrix {
public:
- Matrix();
- virtual ~Matrix() = default;
- bool search_is_filter() override { return true; }
- 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 0; }
- bool search_suggestion_is_search() const override { return true; }
- Page get_page_after_search() const override { return Page::EXIT; }
PluginResult sync(RoomSyncMessages &room_messages);
PluginResult get_joined_rooms(BodyItems &result_items);
PluginResult get_all_synced_room_messages(const std::string &room_id, BodyItems &result_items);
PluginResult get_new_room_messages(const std::string &room_id, BodyItems &result_items);
PluginResult get_previous_room_messages(const std::string &room_id, BodyItems &result_items);
- SearchResult search(const std::string &text, BodyItems &result_items) override;
// |url| should only be set when uploading media.
// TODO: Make api better.
@@ -139,6 +147,8 @@ namespace QuickMedia {
PluginResult get_config(int *upload_size);
std::shared_ptr<UserInfo> get_me(const std::string &room_id);
+
+ bool use_tor = false;
private:
PluginResult sync_response_to_body_items(const Json::Value &root, RoomSyncMessages &room_messages);
PluginResult get_previous_room_messages(std::shared_ptr<RoomData> &room_data);
@@ -152,6 +162,7 @@ namespace QuickMedia {
std::shared_ptr<RoomData> get_room_by_id(const std::string &id);
void add_room(std::shared_ptr<RoomData> room);
+ DownloadResult download_json(Json::Value &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr) const;
private:
std::unordered_map<std::string, std::shared_ptr<RoomData>> room_data_by_id;
std::mutex room_data_mutex;
diff --git a/plugins/NyaaSi.hpp b/plugins/NyaaSi.hpp
index 97b69e7..bad5863 100644
--- a/plugins/NyaaSi.hpp
+++ b/plugins/NyaaSi.hpp
@@ -1,29 +1,33 @@
#pragma once
-#include "Plugin.hpp"
-#include <thread>
-#include <mutex>
-#include <condition_variable>
+#include "Page.hpp"
namespace QuickMedia {
- class Program;
+ class NyaaSiCategoryPage : public Page {
+ public:
+ NyaaSiCategoryPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return "Select category"; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ void get_categories(BodyItems &result_items);
+ };
+
+ class NyaaSiSearchPage : public Page {
+ public:
+ NyaaSiSearchPage(Program *program, std::string category_name, std::string category_id) : Page(program), category_name(std::move(category_name)), category_id(std::move(category_id)) {}
+ const char* get_title() const override { return category_name.c_str(); }
+ 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;
+
+ const std::string category_name;
+ const std::string category_id;
+ };
- class NyaaSi : public Plugin {
+ class NyaaSiTorrentPage : public Page {
public:
- NyaaSi();
- ~NyaaSi() override;
- PluginResult get_front_page(BodyItems &result_items) override;
- SearchResult content_list_search(const std::string &list_url, const std::string &text, BodyItems &result_items) override;
- SearchResult content_list_search_page(const std::string &list_url, const std::string &text, int page, BodyItems &result_items) 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::CONTENT_LIST; }
- bool search_is_filter() override { return true; }
- bool content_list_search_is_filter() const override { return false; }
- PluginResult get_content_list(const std::string &url, BodyItems &result_items) override;
- PluginResult get_content_details(const std::string &list_url, const std::string &url, BodyItems &result_items) override;
- private:
- SearchResult search_page(const std::string &list_url, const std::string &text, int page, BodyItems &result_items);
+ NyaaSiTorrentPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return "Torrent"; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
};
} \ No newline at end of file
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
new file mode 100644
index 0000000..947f045
--- /dev/null
+++ b/plugins/Page.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "Plugin.hpp"
+
+#include "../include/Tab.hpp"
+#include "../include/SearchBar.hpp"
+#include "../include/Body.hpp"
+
+namespace QuickMedia {
+ constexpr int SEARCH_DELAY_FILTER = 50;
+
+ class Page {
+ public:
+ Page(Program *program) : program(program) {}
+ virtual ~Page() = default;
+
+ virtual const char* get_title() const = 0;
+ virtual bool search_is_filter() { return true; }
+ // This show be overriden if search_is_filter is overriden to return false
+ virtual SearchResult search(const std::string &str, BodyItems &result_items) { (void)str; (void)result_items; return SearchResult::ERR; }
+
+ // 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;
+ 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);
+
+ DownloadResult download_json(Json::Value &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr);
+
+ virtual bool is_manga_images_page() const { return false; }
+ virtual bool is_image_board_thread_page() const { return false; }
+ virtual bool is_video_page() const { return false; }
+ // Mutually exclusive with |is_manga_images_page|, |is_image_board_thread_page| and |is_video_page|
+ virtual bool is_single_page() const { return false; }
+ virtual bool is_trackable() const { return false; }
+
+ bool is_tor_enabled();
+ std::unique_ptr<Body> create_body();
+ std::unique_ptr<SearchBar> create_search_bar(const std::string &placeholder_text, int search_delay);
+
+ bool load_manga_content_storage(const char *service_name, const std::string &manga_title, const std::string &manga_id);
+
+ Program *program;
+ };
+
+ enum class TrackResult {
+ OK,
+ ERR
+ };
+
+ class TrackablePage : public Page {
+ public:
+ TrackablePage(Program *program, std::string content_title, std::string content_url) : Page(program), content_title(std::move(content_title)), content_url(std::move(content_url)) {}
+ const char* get_title() const override { return content_title.c_str(); }
+ bool is_trackable() const override { return true; }
+ virtual TrackResult track(const std::string &str) = 0;
+
+ const std::string content_title;
+ const std::string content_url;
+ };
+} \ No newline at end of file
diff --git a/plugins/Plugin.hpp b/plugins/Plugin.hpp
index 438b4ea..1427233 100644
--- a/plugins/Plugin.hpp
+++ b/plugins/Plugin.hpp
@@ -1,12 +1,9 @@
#pragma once
-#include "../include/Page.hpp"
#include "../include/Body.hpp"
-#include "../include/StringUtils.hpp"
#include "../include/DownloadUtils.hpp"
+#include <stddef.h>
#include <string>
-#include <vector>
-#include <memory>
namespace QuickMedia {
enum class PluginResult {
@@ -34,64 +31,17 @@ namespace QuickMedia {
NET_ERR
};
+ struct BodyItemImageContext {
+ BodyItems *body_items;
+ size_t index;
+ };
+
void html_escape_sequences(std::string &str);
void html_unescape_sequences(std::string &str);
+ std::string url_param_encode(const std::string &param);
- class Plugin {
- public:
- Plugin(const std::string &name) : name(name) {}
- virtual ~Plugin() = default;
-
- virtual bool is_image_board() { return false; }
- virtual bool is_manga() { return false; }
- // Return true if searching should update the search result (which could be a remote server search) or filter the existing list locally
- virtual bool search_is_filter() { return false; }
-
- virtual PluginResult get_front_page(BodyItems &result_items) {
- (void)result_items; return PluginResult::OK;
- }
- virtual SearchResult search(const std::string &text, BodyItems &result_items);
- virtual SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items);
- virtual SearchResult content_list_search(const std::string &list_url, const std::string &text, BodyItems &result_items);
- // TODO: Merge with above?
- // page 0 is the first page
- virtual SearchResult content_list_search_page(const std::string &list_url, const std::string &text, int page, BodyItems &result_items) {
- (void)list_url;
- (void)text;
- (void)page;
- (void)result_items;
- return SearchResult::OK;
- }
- virtual BodyItems get_related_media(const std::string &url);
- virtual PluginResult get_content_list(const std::string &url, BodyItems &result_items) {
- (void)url;
- (void)result_items;
- return PluginResult::OK;
- }
- virtual PluginResult get_content_details(const std::string &list_url, const std::string &url, BodyItems &result_items) {
- (void)list_url;
- (void)url;
- (void)result_items;
- return PluginResult::OK;
- }
- virtual bool search_suggestions_has_thumbnails() const = 0;
- virtual bool search_results_has_thumbnails() const = 0;
- virtual std::string autocomplete_search(const std::string &query) { return query; }
- virtual int get_autocomplete_delay() const { return 100; }
- virtual int get_search_delay() const = 0;
- virtual int get_content_list_search_delay() const { return 350; }
- virtual bool search_suggestion_is_search() const { return false; }
- virtual bool content_list_search_is_filter() const { return true; }
- virtual Page get_page_after_search() const = 0;
-
- const std::string name;
- bool use_tor = false;
- protected:
- std::string url_param_encode(const std::string &param) const;
- DownloadResult download_json(Json::Value &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr) const;
- SuggestionResult download_result_to_suggestion_result(DownloadResult download_result) const { return (SuggestionResult)download_result; }
- PluginResult download_result_to_plugin_result(DownloadResult download_result) const { return (PluginResult)download_result; }
- SearchResult download_result_to_search_result(DownloadResult download_result) const { return (SearchResult)download_result; }
- ImageResult download_result_to_image_result(DownloadResult download_result) const { return (ImageResult)download_result; }
- };
+ SuggestionResult download_result_to_suggestion_result(DownloadResult download_result);
+ PluginResult download_result_to_plugin_result(DownloadResult download_result);
+ SearchResult download_result_to_search_result(DownloadResult download_result);
+ ImageResult download_result_to_image_result(DownloadResult download_result);
} \ No newline at end of file
diff --git a/plugins/Pornhub.hpp b/plugins/Pornhub.hpp
index 188a68e..195845f 100644
--- a/plugins/Pornhub.hpp
+++ b/plugins/Pornhub.hpp
@@ -1,17 +1,28 @@
#pragma once
-#include "Plugin.hpp"
+#include "Page.hpp"
namespace QuickMedia {
- class Pornhub : public Plugin {
+ class PornhubSearchPage : public Page {
public:
- Pornhub() : Plugin("pornhub") {}
- SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override;
+ PornhubSearchPage(Program *program) : Page(program) {}
+ 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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ };
+
+ class PornhubVideoPage : public Page {
+ public:
+ PornhubVideoPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return ""; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ return PluginResult::ERR;
+ }
BodyItems get_related_media(const std::string &url) 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 500; }
- bool search_suggestion_is_search() const override { return true; }
- Page get_page_after_search() const override { return Page::VIDEO_CONTENT; }
+ bool is_video_page() const override { return true; }
};
} \ No newline at end of file
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index 685d4b0..0922b9d 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -1,24 +1,30 @@
#pragma once
-#include "Plugin.hpp"
+#include "Page.hpp"
namespace QuickMedia {
- class Youtube : public Plugin {
+ class YoutubeSearchPage : public Page {
public:
- Youtube();
- PluginResult get_front_page(BodyItems &result_items) override;
- SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override;
- BodyItems get_related_media(const std::string &url) override;
- bool search_suggestions_has_thumbnails() const override { return true; }
- bool search_results_has_thumbnails() const override { return false; }
- std::string autocomplete_search(const std::string &query) override;
- int get_search_delay() const override { return 350; }
- bool search_suggestion_is_search() const override { return true; }
- Page get_page_after_search() const override { return Page::VIDEO_CONTENT; }
+ YoutubeSearchPage(Program *program) : Page(program) {}
+ 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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
private:
void search_suggestions_get_continuation(const std::string &url, const std::string &continuation_token, BodyItems &result_items);
- std::vector<CommandArg> get_cookies() const;
- private:
- std::string last_autocomplete_result;
+ };
+
+ class YoutubeVideoPage : public Page {
+ public:
+ YoutubeVideoPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return ""; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ return PluginResult::ERR;
+ }
+ BodyItems get_related_media(const std::string &url) override;
+ bool is_video_page() const override { return true; }
};
} \ No newline at end of file