aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-09-09 11:35:47 +0200
committerdec05eba <dec05eba@protonmail.com>2021-09-09 11:35:47 +0200
commit76ef34393aa72230a3490ecf7b06647ede1448da (patch)
tree1121b209293e719271b62c4fddeb4ec44ea6aac6 /plugins
parentda2988c4356d2756e86037b1c7e859f49583c109 (diff)
Add initial peertube support
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Page.hpp3
-rw-r--r--plugins/Peertube.hpp92
2 files changed, 94 insertions, 1 deletions
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index 6944afb..071351b 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -135,7 +135,8 @@ namespace QuickMedia {
virtual std::unique_ptr<Page> create_channels_page(Program *program, const std::string &channel_url) = 0;
virtual void set_url(std::string new_url) { url = std::move(new_url); }
std::string get_url() { return url; }
- // Returns empty string for no timestamp or if the video doesn't support timestamps
+ // Returns empty string for no timestamp or if the video doesn't support timestamps.
+ // Timestamp is in seconds.
virtual std::string get_url_timestamp() { return ""; }
// Falls back to |get_url| if this and |get_audio_url| returns empty strings.
// Might do a network request.
diff --git a/plugins/Peertube.hpp b/plugins/Peertube.hpp
new file mode 100644
index 0000000..833cb5f
--- /dev/null
+++ b/plugins/Peertube.hpp
@@ -0,0 +1,92 @@
+#pragma once
+
+#include "Page.hpp"
+
+namespace QuickMedia {
+ class PeertubeInstanceSelectionPage : public LazyFetchPage {
+ public:
+ PeertubeInstanceSelectionPage(Program *program) : LazyFetchPage(program) {}
+ const char* get_title() const override { return "Select instance"; }
+ bool allow_submit_no_selection() const override { return true; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ PluginResult lazy_fetch(BodyItems &result_items) override;
+ };
+
+ class PeertubeSearchPage : public LazyFetchPage {
+ public:
+ enum class SearchType {
+ VIDEO_CHANNELS,
+ VIDEO_PLAYLISTS,
+ VIDEOS
+ };
+
+ PeertubeSearchPage(Program *program, const std::string &server);
+ const char* get_title() const override { return "Search"; }
+ bool search_is_filter() override { return false; }
+ // Fetches local videos if |str| is empty
+ 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;
+ // Fetches all local videos
+ PluginResult lazy_fetch(BodyItems &result_items) override;
+ private:
+ PluginResult get_local_videos(int page, BodyItems &result_items);
+ PluginResult get_page_by_type(SearchType search_type, const std::string &str, int page, int count, BodyItems &result_items);
+ private:
+ std::string server;
+ };
+
+ class PeertubeChannelPage : public LazyFetchPage {
+ public:
+ PeertubeChannelPage(Program *program, const std::string &server, std::string display_name, std::string name) :
+ LazyFetchPage(program), server(server), name(std::move(name)), title(std::move(display_name)) {}
+ 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;
+ private:
+ std::string server;
+ std::string name;
+ std::string title;
+ };
+
+ class PeertubePlaylistPage : public LazyFetchPage {
+ public:
+ PeertubePlaylistPage(Program *program, const std::string &server, std::string display_name, std::string uuid) :
+ LazyFetchPage(program), server(server), uuid(std::move(uuid)), title(std::move(display_name)) {}
+ 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;
+ private:
+ std::string server;
+ std::string uuid;
+ std::string title;
+ };
+
+ class PeertubeVideoPage : public VideoPage {
+ public:
+ struct VideoSource {
+ std::string url;
+ int resolution; // 720p = 720. 0 = no resolution found
+ };
+
+ PeertubeVideoPage(Program *program, std::string server, std::string url, bool autoplay_next) : VideoPage(program, std::move(url)), server(server), autoplay_next(autoplay_next) {}
+ const char* get_title() const override { return ""; }
+ //BodyItems get_related_media(const std::string &url) override;
+ //bool create_search_page(Program *program, Tab &tab) override;
+ std::unique_ptr<Page> create_comments_page(Program *program) override;
+ std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program) override;
+ std::unique_ptr<Page> create_channels_page(Program *program, const std::string &channel_url) override;
+ std::string get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) override;
+ std::string get_audio_url(std::string &ext) override;
+ PluginResult load(std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters, std::string &err_str) override;
+ bool autoplay_next_item() override { return autoplay_next; }
+ //void mark_watched() override;
+ //void get_subtitles(SubtitleData &subtitle_data) override;
+ private:
+ std::string server;
+ std::vector<VideoSource> video_sources;
+ bool autoplay_next;
+ };
+}