From 7c40643d8e652adf47cd0ad66fd98b4d808dfade Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 17 Aug 2021 01:53:55 +0200 Subject: Add AniList (WIP) --- plugins/AniList.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ plugins/MyAnimeList.hpp | 1 + plugins/Page.hpp | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 plugins/AniList.hpp (limited to 'plugins') diff --git a/plugins/AniList.hpp b/plugins/AniList.hpp new file mode 100644 index 0000000..3d71f5c --- /dev/null +++ b/plugins/AniList.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "Page.hpp" + +namespace QuickMedia { + class AniListSearchPage : public Page { + public: + AniListSearchPage(Program *program) : Page(program) {} + const char* get_title() const override { return "Search for anime or manga"; } + bool search_is_filter() override { return false; } + bool submit_is_async() const 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 &result_tabs) override; + PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override; + private: + SearchResult search_page(const std::string &str, int page, BodyItems &result_items); + }; + + class AniListRelatedPage : public LazyFetchPage { + public: + AniListRelatedPage(Program *program, std::string id) : LazyFetchPage(program), id(std::move(id)) {} + const char* get_title() const override { return "Related"; } + bool submit_is_async() const override { return false; } + PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + PluginResult lazy_fetch(BodyItems &result_items) override; + private: + std::string id; + }; + + class AniListDetailsPage : public LazyFetchPage { + public: + AniListDetailsPage(Program *program, std::string id) : LazyFetchPage(program), id(std::move(id)) {} + const char* get_title() const override { return "Details"; } + bool submit_is_async() const override { return false; } + PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + PluginResult lazy_fetch(BodyItems &result_items) override; + private: + std::string id; + }; + + class AniListRecommendationsPage : public LazyFetchPage { + public: + AniListRecommendationsPage(Program *program, std::string id) : LazyFetchPage(program), id(std::move(id)) {} + const char* get_title() const override { return "Recommendations"; } + bool submit_is_async() const override { return false; } + PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + PluginResult lazy_fetch(BodyItems &result_items) override; + private: + std::string id; + }; +} \ No newline at end of file diff --git a/plugins/MyAnimeList.hpp b/plugins/MyAnimeList.hpp index c88e94f..192f0f3 100644 --- a/plugins/MyAnimeList.hpp +++ b/plugins/MyAnimeList.hpp @@ -8,6 +8,7 @@ namespace QuickMedia { MyAnimeListSearchPage(Program *program) : Page(program) {} const char* get_title() const override { return "Search for anime or manga"; } bool search_is_filter() override { return false; } + bool submit_is_async() const 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 &result_tabs) override; }; diff --git a/plugins/Page.hpp b/plugins/Page.hpp index 8d033e1..f793c65 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -50,7 +50,7 @@ namespace QuickMedia { return PluginResult::ERR; } // 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 + // Note: the first page fetched is 1 (search 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; } DownloadResult download_json(Json::Value &result, const std::string &url, std::vector additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr); -- cgit v1.2.3