aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Youtube.cpp31
-rw-r--r--src/plugins/youtube/YoutubeMediaProxy.cpp28
2 files changed, 34 insertions, 25 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index eb95c05..2fd193f 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -266,9 +266,8 @@ R"END(
// Sometimes youtube returns a redirect url (not in the header but in the body...).
// TODO: Find why this happens and if there is a way bypass it.
- static std::string get_playback_url_recursive(std::string playback_url, int &content_length) {
+ static std::string get_playback_url_recursive(std::string playback_url, int64_t &content_length) {
std::vector<CommandArg> additional_args = get_cookies();
- additional_args.push_back({ "-r", "0-4096" });
const int max_redirects = 5;
for(int i = 0; i < max_redirects; ++i) {
@@ -307,7 +306,7 @@ R"END(
return playback_url;
}
- bool youtube_custom_redirect(std::string &video_url, std::string &audio_url, int &video_content_length, int &audio_content_length, std::function<bool()> 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<bool()> active_handler) {
// TODO: Do this without threads
int num_total_tasks = 0;
AsyncTask<std::string> tasks[2];
@@ -2164,10 +2163,6 @@ R"END(
return url.substr(index, end - index);
}
- static void print_chosen_format(const YoutubeVideoFormat &format) {
- fprintf(stderr, "Choosing youtube video format: width: %d, height: %d, fps: %d, bitrate: %d, mime type: %s\n", format.width, format.height, format.fps, format.base.bitrate, format.base.mime_type.c_str());
- }
-
static const YoutubeVideoFormat* get_highest_resolution_mp4_non_av1(const std::vector<YoutubeVideoFormat> &video_formats, int max_height) {
for(const YoutubeVideoFormat &video_format : video_formats) {
if(video_format.height <= max_height && video_format.base.mime_type.find("mp4") != std::string::npos && video_format.base.mime_type.find("av01") == std::string::npos)
@@ -2184,14 +2179,14 @@ R"END(
return nullptr;
}
- std::string YoutubeVideoPage::get_video_url(int max_height, bool &has_embedded_audio) {
+ std::string YoutubeVideoPage::get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) {
if(!livestream_url.empty()) {
has_embedded_audio = true;
return livestream_url;
}
if(video_formats.empty()) {
- has_embedded_audio = true;
+ has_embedded_audio = false;
return "";
}
@@ -2208,17 +2203,31 @@ R"END(
if(!chosen_video_format)
chosen_video_format = &video_formats.back();
- print_chosen_format(*chosen_video_format);
+ fprintf(stderr, "Choosing youtube video format: width: %d, height: %d, fps: %d, bitrate: %d, mime type: %s\n", chosen_video_format->width, chosen_video_format->height, chosen_video_format->fps, chosen_video_format->base.bitrate, chosen_video_format->base.mime_type.c_str());
has_embedded_audio = chosen_video_format->has_embedded_audio;
+
+ if(chosen_video_format->base.mime_type.find("mp4") != std::string::npos)
+ ext = ".mp4";
+ else if(chosen_video_format->base.mime_type.find("webm") != std::string::npos)
+ ext = ".webm";
+
return chosen_video_format->base.url;
}
- std::string YoutubeVideoPage::get_audio_url() {
+ std::string YoutubeVideoPage::get_audio_url(std::string &ext) {
if(audio_formats.empty())
return "";
const YoutubeAudioFormat *chosen_audio_format = &audio_formats.front();
fprintf(stderr, "Choosing youtube audio format: bitrate: %d, mime type: %s\n", chosen_audio_format->base.bitrate, chosen_audio_format->base.mime_type.c_str());
+
+ if(chosen_audio_format->base.mime_type.find("mp4") != std::string::npos)
+ ext = ".m4a";
+ else if(chosen_audio_format->base.mime_type.find("webm") != std::string::npos)
+ ext = ".webm";
+ else if(chosen_audio_format->base.mime_type.find("opus") != std::string::npos)
+ ext = ".opus";
+
return chosen_audio_format->base.url;
}
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp
index cba4a1d..2296d1a 100644
--- a/src/plugins/youtube/YoutubeMediaProxy.cpp
+++ b/src/plugins/youtube/YoutubeMediaProxy.cpp
@@ -77,7 +77,7 @@ namespace QuickMedia {
stop();
}
- bool YoutubeStaticMediaProxy::start(const std::string &youtube_media_url, int content_length) {
+ bool YoutubeStaticMediaProxy::start(const std::string &youtube_media_url, int64_t content_length) {
if(socket_fd != -1)
return false;
@@ -251,15 +251,15 @@ namespace QuickMedia {
int new_start_range = header_extract_start_range(client_request_buffer);
//fprintf(stderr, "got new range from client: %d\n", new_start_range);
- if(new_start_range >= 0) {
- if(downloader_read_program.pid != -1) {
- kill(downloader_read_program.pid, SIGTERM);
- wait_program(downloader_read_program.pid);
- downloader_read_program.pid = -1;
- }
- clear_download_state();
- update_download_program_status(false, new_start_range, true);
+ //if(new_start_range >= 0) {
+ if(downloader_read_program.pid != -1) {
+ kill(downloader_read_program.pid, SIGTERM);
+ wait_program(downloader_read_program.pid);
+ downloader_read_program.pid = -1;
}
+ clear_download_state();
+ return update_download_program_status(false, new_start_range, true);
+ //}
} else {
if(client_request_buffer.size() > MAX_BUFFER_SIZE) {
client_request_finished = true;
@@ -278,13 +278,13 @@ namespace QuickMedia {
download_header_written_offset = 0;
}
- YoutubeStaticMediaProxy::Error YoutubeStaticMediaProxy::update_download_program_status(bool client_disconnected, int new_range_start, bool restart_download) {
+ YoutubeStaticMediaProxy::Error YoutubeStaticMediaProxy::update_download_program_status(bool client_disconnected, int64_t new_range_start, bool restart_download) {
int program_status = 0;
if(downloader_read_program.pid != -1) {
if(client_disconnected) {
wait_program(downloader_read_program.pid);
} else {
- if(!wait_program_non_blocking(downloader_read_program.pid, &program_status))
+ if(wait_program_non_blocking(downloader_read_program.pid, &program_status) == 0)
return Error::OK;
}
downloader_read_program.pid = -1;
@@ -353,7 +353,7 @@ namespace QuickMedia {
return Error::OK;
}
- static void header_replace_content_length(std::string &header, size_t header_size, int new_content_length) {
+ static void header_replace_content_length(std::string &header, size_t header_size, int64_t new_content_length) {
if(new_content_length < 0)
new_content_length = 0;
@@ -536,7 +536,7 @@ namespace QuickMedia {
stop();
}
- bool YoutubeLiveStreamMediaProxy::start(const std::string &youtube_media_url, int) {
+ bool YoutubeLiveStreamMediaProxy::start(const std::string &youtube_media_url, int64_t) {
fd[0] = -1;
fd[1] = -1;
if(pipe(fd) == -1) {
@@ -587,7 +587,7 @@ namespace QuickMedia {
YoutubeMediaProxy::Error YoutubeLiveStreamMediaProxy::update_download_program_status() {
int program_status = 0;
- if(!wait_program_non_blocking(downloader_read_program.pid, &program_status))
+ if(wait_program_non_blocking(downloader_read_program.pid, &program_status) == 0)
return Error::OK;
downloader_read_program.pid = -1;