Peertube.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "Page.hpp"
  3. namespace QuickMedia {
  4. class PeertubeInstanceSelectionPage : public LazyFetchPage {
  5. public:
  6. PeertubeInstanceSelectionPage(Program *program) : LazyFetchPage(program) {}
  7. const char* get_title() const override { return "Select instance"; }
  8. bool allow_submit_no_selection() const override { return true; }
  9. bool submit_is_async() const override { return false; }
  10. PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
  11. PluginResult lazy_fetch(BodyItems &result_items) override;
  12. };
  13. class PeertubeSearchPage : public LazyFetchPage {
  14. public:
  15. enum class SearchType {
  16. VIDEO_CHANNELS,
  17. VIDEO_PLAYLISTS,
  18. VIDEOS
  19. };
  20. PeertubeSearchPage(Program *program, const std::string &server);
  21. const char* get_title() const override { return "Search"; }
  22. bool search_is_filter() override { return false; }
  23. bool submit_is_async() const override { return false; }
  24. // Fetches local videos if |str| is empty
  25. SearchResult search(const std::string &str, BodyItems &result_items) override;
  26. PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
  27. PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
  28. // Fetches all local videos
  29. PluginResult lazy_fetch(BodyItems &result_items) override;
  30. private:
  31. PluginResult get_local_videos(int page, BodyItems &result_items);
  32. PluginResult get_page_by_type(SearchType search_type, const std::string &str, int page, int count, BodyItems &result_items);
  33. private:
  34. std::string server;
  35. };
  36. class PeertubeChannelPage : public LazyFetchPage {
  37. public:
  38. PeertubeChannelPage(Program *program, const std::string &server, std::string display_name, std::string name) :
  39. LazyFetchPage(program), server(server), name(std::move(name)), title(std::move(display_name)) {}
  40. const char* get_title() const override { return title.c_str(); }
  41. bool submit_is_async() const override { return false; }
  42. PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
  43. PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
  44. PluginResult lazy_fetch(BodyItems &result_items) override;
  45. private:
  46. std::string server;
  47. std::string name;
  48. std::string title;
  49. };
  50. class PeertubePlaylistPage : public LazyFetchPage {
  51. public:
  52. PeertubePlaylistPage(Program *program, const std::string &server, std::string display_name, std::string uuid) :
  53. LazyFetchPage(program), server(server), uuid(std::move(uuid)), title(std::move(display_name)) {}
  54. const char* get_title() const override { return title.c_str(); }
  55. bool submit_is_async() const override { return false; }
  56. PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
  57. PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
  58. PluginResult lazy_fetch(BodyItems &result_items) override;
  59. private:
  60. std::string server;
  61. std::string uuid;
  62. std::string title;
  63. };
  64. class PeertubeVideoPage : public VideoPage {
  65. public:
  66. struct VideoSource {
  67. std::string url;
  68. int resolution; // 720p = 720. 0 = no resolution found
  69. };
  70. PeertubeVideoPage(Program *program, std::string server, std::string url, bool autoplay_next) : VideoPage(program, std::move(url)), server(server), autoplay_next(autoplay_next) {}
  71. const char* get_title() const override { return ""; }
  72. //BodyItems get_related_media(const std::string &url) override;
  73. std::string get_download_url(int max_height) override;
  74. std::string get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) override;
  75. std::string get_audio_url(std::string &ext) override;
  76. PluginResult load(const SubmitArgs &args, VideoInfo &video_info, std::string &err_str) override;
  77. bool autoplay_next_item() override { return autoplay_next; }
  78. //void get_subtitles(SubtitleData &subtitle_data) override;
  79. private:
  80. std::string server;
  81. std::vector<VideoSource> video_sources;
  82. bool autoplay_next;
  83. };
  84. }