aboutsummaryrefslogtreecommitdiff
path: root/plugins/Peertube.hpp
blob: c8578f7a8499b18f28d99cf29bd2e27d6546c96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#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; }
        bool submit_is_async() const override { return false; }
        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; }
        bool submit_is_async() const 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(); }
        bool submit_is_async() const override { return false; }
        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(); }
        bool submit_is_async() const override { return false; }
        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_download_url(int max_height) 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;
    };
}