diff options
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r-- | src/plugins/Youtube.cpp | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 9a9ed81..b86112d 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1,5 +1,4 @@ #include "../../plugins/Youtube.hpp" -#include "../../plugins/youtube/Signature.hpp" #include "../../include/Storage.hpp" #include "../../include/NetUtils.hpp" #include "../../include/StringUtils.hpp" @@ -115,8 +114,6 @@ namespace QuickMedia { static std::vector<CommandArg> get_cookies() { std::lock_guard<std::mutex> lock(cookies_mutex); if(cookies_filepath.empty()) { - //YoutubeSignatureDecryptor::get_instance(); - cpn.resize(16); generate_random_characters(cpn.data(), cpn.size(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_", 64); @@ -2268,20 +2265,75 @@ namespace QuickMedia { return -1; } + static int get_start_of_comment_timestamp(const char *str, size_t size) { + for(int i = (int)size - 1; i >= 0; --i) { + char c = str[i]; + if(c == ' ' || c == '\t') + return i + 1; + } + return -1; + } + + static int start_of_timestamp_title(const char *str, size_t size) { + for(int i = 0; i < (int)size; ++i) { + char c = str[i]; + if(c != '-' && c != ':' && c != '.' && c != ' ' && c != '\t') + return i; + } + return -1; + } + + static int end_of_timestamp_title(const char *str, size_t size) { + for(int i = (int)size - 1; i >= 0; --i) { + char c = str[i]; + if(c != '-' && c != ':' && c != '.' && c != ' ' && c != '\t') + return i + 1; + } + return -1; + } + static std::vector<MediaChapter> youtube_description_extract_chapters(const std::string &description) { std::vector<MediaChapter> result; string_split(description, '\n', [&result](const char *str, size_t size) { - const void *first_space_p = memchr(str, ' ', size); - if(!first_space_p) + strip(str, size, &size); + if(size == 0) return true; - int timestamp_seconds = youtube_comment_timestamp_to_seconds(str, (const char*)first_space_p - str); - if(timestamp_seconds == -1) + const char *first_space_p = (const char*)memchr(str, ' ', size); + if(!first_space_p) return true; + int timestamp_seconds = youtube_comment_timestamp_to_seconds(str, first_space_p - str); + if(timestamp_seconds != -1) { + // Timestamp at the start of the line + size -= (first_space_p - str); + str = first_space_p; + const int timestamp_title_start = start_of_timestamp_title(str, size); + if(timestamp_title_start == -1) + return true; + + str += timestamp_title_start; + size -= timestamp_title_start; + } else { + // Timestamp at the end of the line + const int timestamp_start = get_start_of_comment_timestamp(str, size); + if(timestamp_start == -1) + return true; + + timestamp_seconds = youtube_comment_timestamp_to_seconds(str + timestamp_start, size - timestamp_start); + if(timestamp_seconds == -1) + return true; + + const int timestamp_title_end = end_of_timestamp_title(str, timestamp_start); + if(timestamp_title_end == -1) + return true; + + size = timestamp_title_end; + } + MediaChapter chapter; chapter.start_seconds = timestamp_seconds; - chapter.title.assign((const char*)first_space_p, (str + size) - (const char*)first_space_p); + chapter.title.assign(str, size); chapter.title = strip(chapter.title); result.push_back(std::move(chapter)); return true; @@ -2593,17 +2645,6 @@ R"END( return true; } - //std::string url_decoded = url_param_decode(url); - //url_decoded += "&alr=yes&cver=2.20210615.01.00&cpn=" + cpn; - -#ifdef YOUTUBE_SIGNATURE_DECRYPTOR - const std::string &s = cipher_params["s"]; - const std::string &sp = cipher_params["sp"]; - std::string sig_key; - std::string sig_value; - if(YoutubeSignatureDecryptor::get_instance().decrypt(s, sp, sig_key, sig_value)) - url += "&" + std::move(sig_key) + "=" + std::move(sig_value); -#endif youtube_format.url = std::move(url); return true; } |