From 0a26a319b241978ee317bbe768eb61c4eb7a39d9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 25 Aug 2021 18:48:34 +0200 Subject: Faster mangakatana search on exact match --- src/plugins/Youtube.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/plugins/Youtube.cpp') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 4934c43..b490e97 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -237,20 +237,26 @@ namespace QuickMedia { std::vector additional_args = get_cookies(); additional_args.push_back({"--no-buffer", ""}); + std::vector response_headers; const int max_redirects = 5; for(int i = 0; i < max_redirects; ++i) { std::string response_body; - std::string response_headers; + response_headers.clear(); download_to_string(playback_url, response_body, additional_args, true, true, false, &response_headers, 4096); - std::string content_type = header_extract_value(response_headers, "content-type"); + if(response_headers.empty()) { + fprintf(stderr, "Youtube video header not found\n"); + return ""; + } + + std::string content_type = header_extract_value(response_headers.back(), "content-type"); if(content_type.empty()) { fprintf(stderr, "Failed to find content-type in youtube video header\n"); return ""; } if(string_starts_with(content_type, "video") || string_starts_with(content_type, "audio")) { - std::string content_length_str = header_extract_value(response_headers, "content-length"); + std::string content_length_str = header_extract_value(response_headers.back(), "content-length"); if(content_length_str.empty()) return ""; -- cgit v1.2.3