aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-11 07:07:04 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-11 07:09:29 +0100
commit80696a506afcee0cca48c22448adacb4aea6eece (patch)
treee1b642940ced3bb01460ef06308d4f86c887b88d /include
parent8c142359fd27d73fc6c77dc5d1bd4df831f7c0c1 (diff)
youtube: use mpv stream_cb instead of proxy server
Diffstat (limited to 'include')
-rw-r--r--include/Downloader.hpp29
-rw-r--r--include/Storage.hpp4
2 files changed, 24 insertions, 9 deletions
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 <string>
@@ -46,7 +45,7 @@ namespace QuickMedia {
AsyncTask<bool> 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<CurlDownloader> downloaders[2];
- AsyncTask<void> downloader_task;
- std::unique_ptr<YoutubeMediaProxy> youtube_video_media_proxy;
- std::unique_ptr<YoutubeMediaProxy> youtube_audio_media_proxy;
+ YoutubeReadProgram *program[2];
+ AsyncTask<bool> 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