From 80696a506afcee0cca48c22448adacb4aea6eece Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Mar 2022 07:07:04 +0100 Subject: youtube: use mpv stream_cb instead of proxy server --- include/Downloader.hpp | 29 ++++++++++++++++++++++------- include/Storage.hpp | 4 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/Downloader.hpp b/include/Downloader.hpp index cc15e5d..cb70f2e 100644 --- a/include/Downloader.hpp +++ b/include/Downloader.hpp @@ -1,6 +1,5 @@ #pragma once -#include "../plugins/youtube/YoutubeMediaProxy.hpp" #include "Path.hpp" #include "AsyncTask.hpp" #include @@ -46,7 +45,7 @@ namespace QuickMedia { AsyncTask header_reader; std::string header; int64_t content_length = -1; - size_t downloaded_since_last_check = 0; + int64_t downloaded_since_last_check = 0; float progress = 0.0f; std::mutex content_length_mutex; std::string progress_text; @@ -80,9 +79,26 @@ namespace QuickMedia { int64_t content_length; }; + struct YoutubeReadProgram { + ReadProgram read_program; + int64_t offset = 0; + int64_t content_length = -1; + int64_t bytes_downloaded = 0; + int64_t downloaded_since_last_check = 0; + char *url = nullptr; + std::string output_filepath; + std::string output_filepath_tmp; + double progress = 0.0; + std::string progress_text; + std::string download_speed_text; + bool finished = false; + }; + class YoutubeDownloader : public Downloader { public: YoutubeDownloader(const MediaMetadata &video_metadata, const MediaMetadata &audio_metadata, const std::string &output_filepath); + ~YoutubeDownloader(); + bool start() override; bool stop(bool download_completed) override; DownloadUpdateStatus update() override; @@ -90,15 +106,14 @@ namespace QuickMedia { std::string get_progress_text() override; std::string get_download_speed_text() override; private: - CurlDownloader* get_min_progress_downloader(); + YoutubeReadProgram* get_min_progress_downloader(); + DownloadUpdateStatus update(size_t program_index); private: MediaMetadata video_metadata; MediaMetadata audio_metadata; std::string video_output_filepath; std::string audio_output_filepath; - std::unique_ptr downloaders[2]; - AsyncTask downloader_task; - std::unique_ptr youtube_video_media_proxy; - std::unique_ptr youtube_audio_media_proxy; + YoutubeReadProgram *program[2]; + AsyncTask downloader_tasks[2]; }; } \ No newline at end of file diff --git a/include/Storage.hpp b/include/Storage.hpp index c187261..19dd345 100644 --- a/include/Storage.hpp +++ b/include/Storage.hpp @@ -30,7 +30,7 @@ namespace QuickMedia { int create_directory_recursive(const Path &path); FileType get_file_type(const Path &path); int file_get_content(const Path &path, std::string &result); - int file_get_size(const Path &path, size_t *size); + int file_get_size(const Path &path, int64_t *size); bool file_get_last_modified_time_seconds(const char *path, time_t *result); int file_overwrite(const Path &path, const std::string &data); int file_overwrite_atomic(const Path &path, const std::string &data); @@ -46,5 +46,5 @@ namespace QuickMedia { bool is_program_executable_by_name(const char *name); - std::string file_size_to_human_readable_string(size_t bytes); + std::string file_size_to_human_readable_string(int64_t bytes); } \ No newline at end of file -- cgit v1.2.3