aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-04 01:30:38 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-04 01:30:38 +0100
commitb6b972e2dae816a8f0686f4986029a5ed50e592c (patch)
treeb7966625b8ad02628f053a7436c0dd39d8de8abd /plugins
parentae6fb457ca385540e0f9b1347ef9c3c84815b16d (diff)
Add channels page to related videos menu, fix related videos menu broken after video failing to load
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ImageBoard.hpp17
-rw-r--r--plugins/Manga.hpp7
-rw-r--r--plugins/Matrix.hpp15
-rw-r--r--plugins/Page.hpp29
-rw-r--r--plugins/Pornhub.hpp22
-rw-r--r--plugins/Youtube.hpp27
6 files changed, 67 insertions, 50 deletions
diff --git a/plugins/ImageBoard.hpp b/plugins/ImageBoard.hpp
index 2d235ec..c65b269 100644
--- a/plugins/ImageBoard.hpp
+++ b/plugins/ImageBoard.hpp
@@ -10,20 +10,17 @@ namespace QuickMedia {
ERR
};
- class ImageBoardThreadPage : public Page {
+ class ImageBoardThreadPage : public VideoPage {
public:
- 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)) {}
+ ImageBoardThreadPage(Program *program, std::string board_id, std::string thread_id, std::vector<std::string> cached_media_urls) : VideoPage(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;
- }
-
PageTypez get_type() const override { return PageTypez::IMAGE_BOARD_THREAD; }
- virtual BodyItems get_related_media(const std::string &url) override;
+ BodyItems get_related_media(const std::string &url, std::string &channel_url) override;
+ std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program, const std::string &video_url, const std::string &video_title) override;
+ std::unique_ptr<LazyFetchPage> create_channels_page(Program*, const std::string&) override {
+ return nullptr;
+ }
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();
diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp
index cd0ab77..23e8dd0 100644
--- a/plugins/Manga.hpp
+++ b/plugins/Manga.hpp
@@ -17,13 +17,6 @@ namespace QuickMedia {
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;
- }
-
PageTypez get_type() const override { return PageTypez::MANGA_IMAGES; }
virtual ImageResult get_number_of_images(int &num_images) = 0;
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 20ad7da..e7131b0 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -356,17 +356,16 @@ namespace QuickMedia {
};
// Dummy, only play one video. TODO: Play all videos in room, as related videos?
- class MatrixVideoPage : public Page {
+ class MatrixVideoPage : public VideoPage {
public:
- MatrixVideoPage(Program *program) : Page(program) {}
+ MatrixVideoPage(Program *program) : VideoPage(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;
+ std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program*, const std::string&, const std::string&) override {
+ return nullptr;
+ }
+ std::unique_ptr<LazyFetchPage> create_channels_page(Program*, const std::string&) override {
+ return nullptr;
}
- PageTypez get_type() const override { return PageTypez::VIDEO; }
};
class MatrixChatPage : public Page {
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index 5f5af60..28c2bd6 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -29,14 +29,16 @@ namespace QuickMedia {
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 submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
+ (void)title;
+ (void)url;
+ (void)result_tabs;
+ 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
virtual PluginResult get_page(const std::string &str, int page, BodyItems &result_items) { (void)str; (void)page; (void)result_items; return PluginResult::OK; }
- // TODO: Move to a subclass called VideoPage
- 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 PageTypez get_type() const { return PageTypez::REGULAR; }
@@ -81,7 +83,26 @@ namespace QuickMedia {
class LazyFetchPage : public Page {
public:
LazyFetchPage(Program *program) : Page(program) {}
+ bool search_is_filter() override { return true; }
bool is_lazy_fetch_page() const override { return true; }
virtual PluginResult lazy_fetch(BodyItems &result_items) = 0;
};
+
+ class RelatedVideosPage : public Page {
+ public:
+ RelatedVideosPage(Program *program) : Page(program) {}
+ const char* get_title() const override { return "Related videos"; }
+ };
+
+ class VideoPage : public Page {
+ public:
+ VideoPage(Program *program) : Page(program) {}
+ virtual PageTypez get_type() const override { return PageTypez::VIDEO; }
+ virtual BodyItems get_related_media(const std::string &url, std::string &channel_url) { (void)url; (void)channel_url; return {}; }
+ virtual std::unique_ptr<Page> create_search_page(Program *program, int &search_delay) { (void)program; (void)search_delay; return nullptr; }
+ // Return nullptr if the service doesn't support related videos page
+ virtual std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program, const std::string &video_url, const std::string &video_title) = 0;
+ // Return nullptr if the service doesn't support channels page
+ virtual std::unique_ptr<LazyFetchPage> create_channels_page(Program *program, const std::string &channel_url) = 0;
+ };
} \ No newline at end of file
diff --git a/plugins/Pornhub.hpp b/plugins/Pornhub.hpp
index 74fb00e..5c3f835 100644
--- a/plugins/Pornhub.hpp
+++ b/plugins/Pornhub.hpp
@@ -13,17 +13,21 @@ namespace QuickMedia {
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
};
- class PornhubVideoPage : public Page {
+ class PornhubRelatedVideosPage : public RelatedVideosPage {
public:
- PornhubVideoPage(Program *program) : Page(program) {}
+ PornhubRelatedVideosPage(Program *program) : RelatedVideosPage(program) {}
+ PluginResult submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) override;
+ };
+
+ class PornhubVideoPage : public VideoPage {
+ public:
+ PornhubVideoPage(Program *program) : VideoPage(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, std::string &channel_url) override;
+ std::unique_ptr<Page> create_search_page(Program *program, int &search_delay) override;
+ std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program, const std::string &video_url, const std::string &video_title) override;
+ std::unique_ptr<LazyFetchPage> create_channels_page(Program*, const std::string&) override {
+ return nullptr;
}
- BodyItems get_related_media(const std::string &url) override;
- PageTypez get_type() const override { return PageTypez::VIDEO; }
};
} \ No newline at end of file
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index e2dd201..1a66e5c 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -21,12 +21,13 @@ namespace QuickMedia {
std::unordered_set<std::string> added_videos;
};
- class YoutubeChannelPage : public Page {
+ class YoutubeChannelPage : public LazyFetchPage {
public:
- YoutubeChannelPage(Program *program, std::string url, std::string continuation_token, std::string title) : Page(program), url(std::move(url)), continuation_token(std::move(continuation_token)), title(std::move(title)) {}
+ YoutubeChannelPage(Program *program, std::string url, std::string continuation_token, std::string title) : LazyFetchPage(program), url(std::move(url)), continuation_token(std::move(continuation_token)), title(std::move(title)) {}
const char* get_title() const override { return title.c_str(); }
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;
+ PluginResult lazy_fetch(BodyItems &result_items) override;
std::unordered_set<std::string> added_videos;
private:
@@ -38,17 +39,19 @@ namespace QuickMedia {
int current_page = 0;
};
- class YoutubeVideoPage : public Page {
+ class YoutubeRelatedVideosPage : public RelatedVideosPage {
public:
- YoutubeVideoPage(Program *program) : Page(program) {}
+ YoutubeRelatedVideosPage(Program *program) : RelatedVideosPage(program) {}
+ PluginResult submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) override;
+ };
+
+ class YoutubeVideoPage : public VideoPage {
+ public:
+ YoutubeVideoPage(Program *program) : VideoPage(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;
- PageTypez get_type() const override { return PageTypez::VIDEO; }
+ BodyItems get_related_media(const std::string &url, std::string &channel_url) override;
+ std::unique_ptr<Page> create_search_page(Program *program, int &search_delay) override;
+ std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program, const std::string &video_url, const std::string &video_title) override;
+ std::unique_ptr<LazyFetchPage> create_channels_page(Program *program, const std::string &channel_url) override;
};
} \ No newline at end of file