aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-20 09:35:17 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-20 09:35:17 +0100
commitade32bea240fa74f01d4dd4792b1069cca619bba (patch)
tree1ac13e7df419d01a3784b8421713e1bddf118b56
parentb85c9839ae86247179a4adf7f2e90f194380cb93 (diff)
Improve youtube throttling by increasing youtube downloader range buffer size by 10
-rw-r--r--plugins/youtube/YoutubeMediaProxy.hpp3
-rw-r--r--src/Downloader.cpp6
-rw-r--r--src/QuickMedia.cpp5
-rw-r--r--src/plugins/youtube/YoutubeMediaProxy.cpp9
4 files changed, 5 insertions, 18 deletions
diff --git a/plugins/youtube/YoutubeMediaProxy.hpp b/plugins/youtube/YoutubeMediaProxy.hpp
index 8e6ea38..e2c4bf7 100644
--- a/plugins/youtube/YoutubeMediaProxy.hpp
+++ b/plugins/youtube/YoutubeMediaProxy.hpp
@@ -25,9 +25,6 @@ namespace QuickMedia {
virtual bool get_address(std::string &address) = 0;
bool start_download(const std::string &media_url, ReadProgram &read_program, int64_t range_start, bool include_header, bool is_livestream = false, int livestream_sequence = -1);
- private:
- int rn = 0;
- int rbuf = 0;
};
class YoutubeStaticMediaProxy : public YoutubeMediaProxy {
diff --git a/src/Downloader.cpp b/src/Downloader.cpp
index 1bb3e34..e5b1a3c 100644
--- a/src/Downloader.cpp
+++ b/src/Downloader.cpp
@@ -2,7 +2,6 @@
#include "../include/Storage.hpp"
#include "../include/NetUtils.hpp"
#include "../include/Notification.hpp"
-#include <mglpp/system/Clock.hpp>
#include <unistd.h>
#include <signal.h>
@@ -346,7 +345,6 @@ namespace QuickMedia {
}
downloader_task = AsyncTask<void>([this]() {
- mgl::Clock timer;
// TODO: Poll instead of sleep
while(!program_is_dead_in_current_thread()) {
if(youtube_video_media_proxy)
@@ -355,9 +353,7 @@ namespace QuickMedia {
if(youtube_audio_media_proxy)
youtube_audio_media_proxy->update();
- const double sleep_left_sec = timer.restart();
- if(sleep_left_sec > 0.000001)
- std::this_thread::sleep_for(std::chrono::milliseconds((long)(sleep_left_sec * 1000.0)));
+ usleep(1000);
}
});
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index b364fe0..464417a 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2874,7 +2874,6 @@ namespace QuickMedia {
if(num_proxied_media > 0) {
youtube_downloader_task = AsyncTask<void>([&youtube_video_media_proxy, &youtube_audio_media_proxy]() {
- mgl::Clock timer;
// TODO: Poll instead of sleep
while(!program_is_dead_in_current_thread()) {
if(youtube_video_media_proxy)
@@ -2883,9 +2882,7 @@ namespace QuickMedia {
if(youtube_audio_media_proxy)
youtube_audio_media_proxy->update();
- const double sleep_left_sec = timer.restart();
- if(sleep_left_sec > 0.000001)
- std::this_thread::sleep_for(std::chrono::milliseconds((long)(sleep_left_sec * 1000.0)));
+ usleep(1000);
}
});
}
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp
index 913fb77..6e2c5c4 100644
--- a/src/plugins/youtube/YoutubeMediaProxy.cpp
+++ b/src/plugins/youtube/YoutubeMediaProxy.cpp
@@ -20,7 +20,7 @@
namespace QuickMedia {
static const int MAX_BUFFER_SIZE = 65536;
- static const int64_t RANGE = 524287;
+ static const int64_t RANGE = 5242870;
static const int64_t THROTTLED_DOWNLOAD_LIMIT_KB = 80; // TODO: What about people with really slow internet? What if the video player cache is not working and download is stuck, leading to false download speed calculation?
static const int64_t THROTTLED_DURATION_SECS = 3;
static const char download_error_response_msg[] =
@@ -39,9 +39,9 @@ namespace QuickMedia {
bool YoutubeMediaProxy::start_download(const std::string &media_url, ReadProgram &read_program, int64_t range_start, bool include_header, bool is_livestream, int livestream_sequence) {
std::string r = std::to_string(range_start) + "-" + std::to_string(range_start + RANGE);
- std::string url = media_url + "&rn=" + std::to_string(rn) + "&rbuf=" + std::to_string(rbuf);
+ std::string url = media_url;;
std::vector<const char*> args = { "curl",
- //"-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive",
+ "-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive",
"--no-buffer",
"-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
"-g", "-s", "-L", "-f" };
@@ -72,9 +72,6 @@ namespace QuickMedia {
return false;
}
- ++rn;
- rbuf += 3000;
- if(rbuf > 75000) rbuf = 75000;
return true;
}