diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-04-28 05:37:15 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-04-28 05:37:42 +0200 |
commit | 1b7abc7e819d055b3d0ea5be8967a1e381bb5d60 (patch) | |
tree | 503e6f67d933119df4512ef7186ed380b393f868 /plugins | |
parent | f045e579e1faa186ca0ebf6e6d1e562fbcd75727 (diff) |
Add youtube subscriptions, etc
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ImageBoard.hpp | 2 | ||||
-rw-r--r-- | plugins/Manga.hpp | 6 | ||||
-rw-r--r-- | plugins/Matrix.hpp | 2 | ||||
-rw-r--r-- | plugins/Page.hpp | 9 | ||||
-rw-r--r-- | plugins/Pornhub.hpp | 2 | ||||
-rw-r--r-- | plugins/Soundcloud.hpp | 4 | ||||
-rw-r--r-- | plugins/Spankbang.hpp | 2 | ||||
-rw-r--r-- | plugins/Spotify.hpp | 2 | ||||
-rw-r--r-- | plugins/Youtube.hpp | 25 |
9 files changed, 37 insertions, 17 deletions
diff --git a/plugins/ImageBoard.hpp b/plugins/ImageBoard.hpp index bd47bec..9d4c123 100644 --- a/plugins/ImageBoard.hpp +++ b/plugins/ImageBoard.hpp @@ -18,7 +18,7 @@ namespace QuickMedia { 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 { + std::unique_ptr<Page> create_channels_page(Program*, const std::string&) override { return nullptr; } std::string get_url() override { return video_url; } diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp index 388ce66..ee7638b 100644 --- a/plugins/Manga.hpp +++ b/plugins/Manga.hpp @@ -47,11 +47,13 @@ namespace QuickMedia { int chapter_num_pages; }; - class MangaChaptersPage : public TrackablePage { + class MangaChaptersPage : public Page, public TrackablePage { public: - MangaChaptersPage(Program *program, std::string manga_name, std::string manga_url) : TrackablePage(program, std::move(manga_name), std::move(manga_url)) {} + MangaChaptersPage(Program *program, std::string manga_name, std::string manga_url) : Page(program), TrackablePage(std::move(manga_name), std::move(manga_url)) {} + const char* get_title() const override { return content_title.c_str(); } TrackResult track(const std::string &str) override; void on_navigate_to_page(Body *body) override; + bool is_trackable() const override { return true; } protected: virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) const = 0; virtual const char* get_service_name() const = 0; diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index 1063e0e..fb52744 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -420,7 +420,7 @@ namespace QuickMedia { 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 { + std::unique_ptr<Page> create_channels_page(Program*, const std::string&) override { return nullptr; } std::string get_url() override { return url; } diff --git a/plugins/Page.hpp b/plugins/Page.hpp index 6599fe4..175b44b 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -72,11 +72,10 @@ namespace QuickMedia { ERR }; - class TrackablePage : public Page { + class TrackablePage { 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; } + TrackablePage(std::string content_title, std::string content_url) : content_title(std::move(content_title)), content_url(std::move(content_url)) {} + virtual ~TrackablePage() = default; virtual TrackResult track(const std::string &str) = 0; const std::string content_title; @@ -110,7 +109,7 @@ namespace QuickMedia { // 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; + virtual std::unique_ptr<Page> create_channels_page(Program *program, const std::string &channel_url) = 0; virtual std::string get_url() = 0; virtual std::string url_get_playable_url(const std::string &url) { return url; } virtual bool video_should_be_skipped(const std::string &url) { (void)url; return false; } diff --git a/plugins/Pornhub.hpp b/plugins/Pornhub.hpp index 87e33da..8f6f563 100644 --- a/plugins/Pornhub.hpp +++ b/plugins/Pornhub.hpp @@ -26,7 +26,7 @@ namespace QuickMedia { 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 { + std::unique_ptr<Page> create_channels_page(Program*, const std::string&) override { return nullptr; } std::string get_url() override { return url; } diff --git a/plugins/Soundcloud.hpp b/plugins/Soundcloud.hpp index 24dc051..0f397a1 100644 --- a/plugins/Soundcloud.hpp +++ b/plugins/Soundcloud.hpp @@ -25,7 +25,7 @@ namespace QuickMedia { private: SoundcloudPage submit_page; std::string query_urn; - std::vector<AsyncTask<std::string>> async_download_threads; + std::vector<AsyncTask<std::string>> async_download_tasks; }; class SoundcloudUserPage : public SoundcloudPage { @@ -56,7 +56,7 @@ namespace QuickMedia { const char* get_title() const override { return ""; } bool autoplay_next_item() override { return true; } 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; } + std::unique_ptr<Page> create_channels_page(Program *, const std::string &) override { return nullptr; } std::string get_url() override { return url; } std::string url_get_playable_url(const std::string &url) override; bool video_should_be_skipped(const std::string &url) override { return url == "track" || url.find("/stream/users/") != std::string::npos; } diff --git a/plugins/Spankbang.hpp b/plugins/Spankbang.hpp index 95b8820..06ea509 100644 --- a/plugins/Spankbang.hpp +++ b/plugins/Spankbang.hpp @@ -26,7 +26,7 @@ namespace QuickMedia { 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 { + std::unique_ptr<Page> create_channels_page(Program*, const std::string&) override { return nullptr; } std::string get_url() override { return url; } diff --git a/plugins/Spotify.hpp b/plugins/Spotify.hpp index 89f8f3d..66cc992 100644 --- a/plugins/Spotify.hpp +++ b/plugins/Spotify.hpp @@ -41,7 +41,7 @@ namespace QuickMedia { SpotifyAudioPage(Program *program, const std::string &url) : VideoPage(program), url(url) {} const char* get_title() const override { return ""; } 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; } + std::unique_ptr<Page> create_channels_page(Program *, const std::string &) override { return nullptr; } std::string get_url() override { return url; } private: std::string url; diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp index 4691f04..4be5339 100644 --- a/plugins/Youtube.hpp +++ b/plugins/Youtube.hpp @@ -1,6 +1,7 @@ #pragma once #include "Page.hpp" +#include "../include/AsyncTask.hpp" #include <unordered_set> namespace QuickMedia { @@ -47,9 +48,9 @@ namespace QuickMedia { std::string continuation_token; }; - class YoutubeChannelPage : public LazyFetchPage { + class YoutubeChannelPage : public LazyFetchPage, public TrackablePage { public: - 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)) {} + YoutubeChannelPage(Program *program, std::string url, std::string continuation_token, std::string title) : LazyFetchPage(program), TrackablePage(title, url), url(url), continuation_token(std::move(continuation_token)), title(title) {} const char* get_title() const override { return title.c_str(); } bool search_is_filter() override { return false; } SearchResult search(const std::string &str, BodyItems &result_items) override; @@ -57,6 +58,9 @@ namespace QuickMedia { PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override; PluginResult lazy_fetch(BodyItems &result_items) override; + TrackResult track(const std::string &str) override; + bool is_trackable() const override { return true; } + std::unordered_set<std::string> added_videos; private: PluginResult search_get_continuation(const std::string &url, const std::string &continuation_token, BodyItems &result_items); @@ -67,6 +71,21 @@ namespace QuickMedia { int current_page = 0; }; + struct YoutubeSubscriptionTaskResult { + std::shared_ptr<BodyItem> body_item; + time_t timestamp = 0; + }; + + class YoutubeSubscriptionsPage : public LazyFetchPage { + public: + YoutubeSubscriptionsPage(Program *program) : LazyFetchPage(program) {} + const char* get_title() const override { return "Subscriptions"; } + PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override; + PluginResult lazy_fetch(BodyItems &result_items) override; + private: + std::array<AsyncTask<std::vector<YoutubeSubscriptionTaskResult>>, 4> subscription_load_tasks; // TODO: Use multiple curl outputs instead? + }; + class YoutubeRelatedVideosPage : public RelatedVideosPage { public: YoutubeRelatedVideosPage(Program *program) : RelatedVideosPage(program) {} @@ -81,7 +100,7 @@ namespace QuickMedia { std::unique_ptr<Page> create_search_page(Program *program, int &search_delay) override; std::unique_ptr<Page> create_comments_page(Program *program) 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; + std::unique_ptr<Page> create_channels_page(Program *program, const std::string &channel_url) override; std::string get_url() override { return url; } private: std::string xsrf_token; |