aboutsummaryrefslogtreecommitdiff
path: root/src/DownloadUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-30 14:23:13 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-30 14:23:13 +0200
commit496f71413df2468a9d3329355ffef08280219808 (patch)
tree7efc4ca43d61299fae056cc2afcb41ef0db4f505 /src/DownloadUtils.cpp
parent65457dc196f1b56128b1dc6eeaf3a086da1a180f (diff)
Fix youtube redirect code (fixes all youtube videos)
Diffstat (limited to 'src/DownloadUtils.cpp')
-rw-r--r--src/DownloadUtils.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp
index afef072..7660cee 100644
--- a/src/DownloadUtils.cpp
+++ b/src/DownloadUtils.cpp
@@ -29,13 +29,11 @@ namespace QuickMedia {
return 0;
}
- static bool http_is_redirect(const std::string &header, size_t size) {
- size_t end_of_first_line = header.find("\r\n");
- if(end_of_first_line == std::string::npos)
+ static bool http_is_redirect(const char *header, size_t size) {
+ const void *end_of_first_line_p = memmem(header, size, "\r\n", 2);
+ if(!end_of_first_line_p)
return false;
-
- size_t find_index = header.find(" 30");
- return find_index != std::string::npos && find_index < size;
+ return memmem(header, (const char*)end_of_first_line_p - header, " 30", 3) != nullptr;
}
static int accumulate_string_with_header(char *data, int size, void *userdata) {
@@ -49,7 +47,7 @@ namespace QuickMedia {
size_t end_of_headers_index = download_userdata->header->find("\r\n\r\n");
if(end_of_headers_index != std::string::npos) {
while(true) {
- const bool is_redirect = http_is_redirect(*download_userdata->header, end_of_headers_index);
+ const bool is_redirect = http_is_redirect(download_userdata->header->c_str(), end_of_headers_index);
end_of_headers_index += 4;
if(is_redirect && download_userdata->header->size() - end_of_headers_index > 0) {
download_userdata->header->erase(download_userdata->header->begin(), download_userdata->header->begin() + end_of_headers_index);