aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-17 09:43:20 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-17 09:43:20 +0200
commite671784144174c4fceaa6df3737ba9b4de4a6c63 (patch)
treea3ad7d12959b92f5be9430c961d86a9c131d7036 /src/plugins/Youtube.cpp
parentb09d1e70661226697e2441c18ea6ff59c387fb93 (diff)
Youtube: remove dependency on youtube-dl for downloads (also fixes downloads of age restricted videos)
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp31
1 files changed, 20 insertions, 11 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;
}