From e671784144174c4fceaa6df3737ba9b4de4a6c63 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 17 Jul 2021 09:43:20 +0200 Subject: Youtube: remove dependency on youtube-dl for downloads (also fixes downloads of age restricted videos) --- plugins/Page.hpp | 5 +++-- plugins/Youtube.hpp | 6 +++--- plugins/youtube/YoutubeMediaProxy.hpp | 14 +++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'plugins') diff --git a/plugins/Page.hpp b/plugins/Page.hpp index 3a382ec..35e778b 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -120,14 +120,15 @@ namespace QuickMedia { 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. - virtual std::string get_video_url(int max_height, bool &has_embedded_audio) { + virtual std::string get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) { (void)max_height; + (void)ext; has_embedded_audio = true; return ""; } // Only used if |get_video_url| sets |has_embedded_audio| to false. // Might do a network request. - virtual std::string get_audio_url() { return ""; } + virtual std::string get_audio_url(std::string &ext) { (void)ext; return ""; } 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; } virtual PluginResult load(std::string &title, std::string &channel_url, std::vector &chapters) { (void)title; (void)channel_url; (void)chapters; return PluginResult::OK; } diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp index 2958c44..c89d68d 100644 --- a/plugins/Youtube.hpp +++ b/plugins/Youtube.hpp @@ -26,7 +26,7 @@ namespace QuickMedia { bool youtube_url_extract_id(const std::string &youtube_url, std::string &youtube_video_id); // |video_url| or |audio_url| will be empty if there is an error and false will be returned. // If false is returned from |active_handler|, then this function is cancelled. - bool youtube_custom_redirect(std::string &video_url, std::string &audio_url, int &video_content_length, int &audio_content_length, std::function active_handler); + bool youtube_custom_redirect(std::string &video_url, std::string &audio_url, int64_t &video_content_length, int64_t &audio_content_length, std::function active_handler); class YoutubeSearchPage : public LazyFetchPage { public: @@ -144,8 +144,8 @@ namespace QuickMedia { std::unique_ptr create_channels_page(Program *program, const std::string &channel_url) override; void set_url(std::string new_url) override; std::string get_url_timestamp() override { return timestamp; } - std::string get_video_url(int max_height, bool &has_embedded_audio) override; - std::string get_audio_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 &chapters) override; void mark_watched() override; private: diff --git a/plugins/youtube/YoutubeMediaProxy.hpp b/plugins/youtube/YoutubeMediaProxy.hpp index 2d6ea93..28aa6fe 100644 --- a/plugins/youtube/YoutubeMediaProxy.hpp +++ b/plugins/youtube/YoutubeMediaProxy.hpp @@ -15,7 +15,7 @@ namespace QuickMedia { virtual ~YoutubeMediaProxy() = default; - virtual bool start(const std::string &youtube_media_url, int content_length) = 0; + virtual bool start(const std::string &youtube_media_url, int64_t content_length) = 0; // This should be the last call. Do not call |start| after this. TODO: Allow restarting with |start| after |stop| is called. virtual void stop() = 0; virtual Error update() = 0; @@ -34,7 +34,7 @@ namespace QuickMedia { YoutubeStaticMediaProxy&operator=(YoutubeStaticMediaProxy&) = delete; ~YoutubeStaticMediaProxy(); - bool start(const std::string &youtube_media_url, int content_length) override; + bool start(const std::string &youtube_media_url, int64_t content_length) override; void stop() override; Error update() override; bool get_address(std::string &address) override; @@ -43,7 +43,7 @@ namespace QuickMedia { Error read_client_data(); void clear_download_state(); // If |new_range_start| is not -1 then the start range is set to that - Error update_download_program_status(bool client_disconnected, int new_range_start = -1, bool restart_download = false); + Error update_download_program_status(bool client_disconnected, int64_t new_range_start = -1, bool restart_download = false); Error continue_send(const char *buffer_start, size_t total_bytes_to_write, int &buffer_offset); Error handle_download(); // Returns the client fd or -1 @@ -53,12 +53,12 @@ namespace QuickMedia { int port = 0; int client_fd = -1; std::string youtube_media_url; - int content_length = 0; + int64_t content_length = 0; ReadProgram downloader_read_program; int download_read_buffer_offset = 0; ssize_t downloader_num_read_bytes = 0; - int download_range_start = 0; - int current_download_range = 0; + int64_t download_range_start = 0; + int64_t current_download_range = 0; std::string download_header; bool download_header_finished = false; bool download_header_sent = false; @@ -77,7 +77,7 @@ namespace QuickMedia { YoutubeLiveStreamMediaProxy&operator=(YoutubeLiveStreamMediaProxy&) = delete; ~YoutubeLiveStreamMediaProxy(); - bool start(const std::string &youtube_media_url, int content_length) override; + bool start(const std::string &youtube_media_url, int64_t content_length) override; void stop() override; Error update() override; bool get_address(std::string &address) override; -- cgit v1.2.3