aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/youtube
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-07 16:21:05 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-07 16:21:33 +0200
commiteb89e4048642a4ebf73635730e2a0aa960e7ecdd (patch)
tree14158bcdd86a82ce746e1fce583bfaa192f18f4e /src/plugins/youtube
parentfc4d55f8464779e0912be771973ebd94a27df951 (diff)
Fix seeking in youtube videos larger than 2gb, launch launcher when running qm without any args
Diffstat (limited to 'src/plugins/youtube')
-rw-r--r--src/plugins/youtube/Signature.cpp2
-rw-r--r--src/plugins/youtube/YoutubeMediaProxy.cpp27
2 files changed, 16 insertions, 13 deletions
diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp
index 394abf0..7e5e835 100644
--- a/src/plugins/youtube/Signature.cpp
+++ b/src/plugins/youtube/Signature.cpp
@@ -77,7 +77,7 @@ namespace QuickMedia {
errno = 0;
char *endptr;
- const long value_int = strtoll(value_args.c_str(), &endptr, 10);
+ const int64_t value_int = strtoll(value_args.c_str(), &endptr, 10);
if(endptr != value_args.c_str() && errno == 0)
new_func_calls.push_back({ std::move(func_name), value_int });
else
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp
index e67a920..90dedbf 100644
--- a/src/plugins/youtube/YoutubeMediaProxy.cpp
+++ b/src/plugins/youtube/YoutubeMediaProxy.cpp
@@ -18,7 +18,7 @@
namespace QuickMedia {
static const int MAX_BUFFER_SIZE = 65536;
- static const int RANGE = 524287;
+ static const int64_t RANGE = 524287;
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 = 2;
static const char download_error_response_msg[] =
@@ -34,7 +34,7 @@ namespace QuickMedia {
// TODO: Restrict range end to remote file size (content-length which we have saved).
// TODO: Check if custom youtube redirect code is needed
- bool YoutubeMediaProxy::start_download(const std::string &media_url, ReadProgram &read_program, int range_start, bool include_header, bool is_livestream, int livestream_sequence) {
+ 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);
@@ -214,13 +214,13 @@ namespace QuickMedia {
}
// Returns 0 if start range is not found
- static int header_extract_start_range(const std::string &header) {
+ static int64_t header_extract_start_range(const std::string &header) {
std::string range = header_extract_value(header, "range");
if(range.empty())
return 0;
- int start_range = 0;
- if(sscanf(range.c_str(), " bytes=%d", &start_range) != 1)
+ int64_t start_range = 0;
+ if(sscanf(range.c_str(), " bytes=%lld", &start_range) != 1)
return 0;
return start_range;
@@ -259,9 +259,7 @@ namespace QuickMedia {
download_started = false;
throttle_started = false;
- 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) {
+ const int64_t new_start_range = header_extract_start_range(client_request_buffer);
if(downloader_read_program.pid != -1) {
kill(downloader_read_program.pid, SIGTERM);
wait_program(downloader_read_program.pid);
@@ -269,7 +267,6 @@ namespace QuickMedia {
}
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;
@@ -345,6 +342,12 @@ namespace QuickMedia {
if(!restart_download)
return Error::OK;
+ if(new_range_start == -1) {
+ download_header_finished = true;
+ download_header_sent = true;
+ download_header_remaining_sent = true;
+ }
+
const bool start_download_success = start_download(youtube_media_url, downloader_read_program, current_download_range, new_range_start != -1);
if(!start_download_success) {
fprintf(stderr, "YoutubeStaticMediaProxy::update_download_program_status: failed to start download\n");
@@ -461,7 +464,7 @@ namespace QuickMedia {
throttle_started = false;
struct timespec tp;
- clock_gettime(CLOCK_BOOTTIME, &tp);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
download_start_time = tp.tv_sec;
}
total_downloaded_bytes += downloader_num_read_bytes;
@@ -470,7 +473,7 @@ namespace QuickMedia {
if(download_started) {
struct timespec tp;
- clock_gettime(CLOCK_BOOTTIME, &tp);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
int64_t time_elapsed = tp.tv_sec - download_start_time;
int64_t download_speed_kb_sec = 0;
@@ -780,4 +783,4 @@ namespace QuickMedia {
address = "fd://" + std::to_string(fd[0]);
return true;
}
-} \ No newline at end of file
+}