From fc27e590c39e3b309683e275541fd9b3164985dc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Mar 2022 12:41:16 +0100 Subject: Fix youtube streaming for really long videos I dedicate this one to rat --- src/plugins/Youtube.cpp | 9 +++++++++ video_player/src/main.cpp | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 2d92cd8..b3150a3 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2517,6 +2517,15 @@ R"END( if(!format.isObject()) continue; + if(is_adaptive) { + // TODO: Fix. Some streams use &sq=num instead of index + const Json::Value &index_range_json = format["indexRange"]; + if(index_range_json.isNull()) { + fprintf(stderr, "Ignoring adaptive stream without indexRange\n"); + continue; + } + } + // TODO: Support HDR? const Json::Value &quality_label_json = format["qualityLabel"]; if(quality_label_json.isString() && strstr(quality_label_json.asCString(), "HDR")) continue; diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp index 4ec9278..e166e85 100644 --- a/video_player/src/main.cpp +++ b/video_player/src/main.cpp @@ -449,25 +449,33 @@ static int64_t size_fn(void *cookie) { if(res == 0) { size_t header_start = str_find_case_insensitive(buffer, 0, "200 OK", 6); - if(header_start == std::string::npos) + if(header_start == std::string::npos) { + res = MPV_ERROR_UNSUPPORTED; goto end; + } header_start += 6; size_t content_length_index = str_find_case_insensitive(buffer, header_start, "content-length:", 15); - if(content_length_index == std::string::npos) + if(content_length_index == std::string::npos) { + res = MPV_ERROR_UNSUPPORTED; goto end; + } content_length_index += 15; size_t content_length_end = buffer.find('\r', content_length_index); - if(content_length_end == std::string::npos) + if(content_length_end == std::string::npos) { + res = MPV_ERROR_UNSUPPORTED; goto end; + } buffer[content_length_end] = '\0'; errno = 0; char *endptr; int64_t content_length = strtoll(&buffer[content_length_index], &endptr, 10); - if(endptr == &buffer[content_length_index] || errno != 0) + if(endptr == &buffer[content_length_index] || errno != 0) { + res = MPV_ERROR_UNSUPPORTED; goto end; + } res = content_length; } -- cgit v1.2.3