diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-06-23 22:57:40 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-06-23 22:57:40 +0200 |
commit | 29c9ef23c41d91603cc2860ac233c30b6ade54e3 (patch) | |
tree | 037b415eda2b4b2fdeec6aeea0d8894ed5d70eb3 /src/plugins | |
parent | 47d594f0676a644e7c072331a009ceb46de8f62e (diff) |
Dramacool: fix video not working sometimes by adding support for more video backends: doodstream
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/DramaCool.cpp | 50 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 41 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 22 |
3 files changed, 59 insertions, 54 deletions
diff --git a/src/plugins/DramaCool.cpp b/src/plugins/DramaCool.cpp index df0bb43..f259f9e 100644 --- a/src/plugins/DramaCool.cpp +++ b/src/plugins/DramaCool.cpp @@ -128,6 +128,7 @@ namespace QuickMedia { std::string streamtape; std::string mixdrop; std::string mp4upload; + std::string doodstream; }; static bool dembed_extract_video_source(const std::string &website_data, const std::string &video_source_url, std::string &video_source) { @@ -149,6 +150,7 @@ namespace QuickMedia { dembed_extract_video_source(website_data, "streamtape.com", video_sources.streamtape); dembed_extract_video_source(website_data, "mixdrop.co", video_sources.mixdrop); dembed_extract_video_source(website_data, "www.mp4upload.com", video_sources.mp4upload); + dembed_extract_video_source(website_data, "dood.wf", video_sources.doodstream); } // TODO: Re-add. It's broken right now (because of the json_url has incorrect value I guess) @@ -359,6 +361,45 @@ namespace QuickMedia { return false; } + static bool generate_random_string_doodstream(char *buffer, int buffer_size) { + return generate_random_characters(buffer, buffer_size, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62); + } + + static bool doodstream_extract_video_url(const std::string &website_data, std::string &url, const std::string &referer) { + const size_t pass_start = website_data.find("/pass_md5/"); + if(pass_start == std::string::npos) + return false; + + const size_t pass_end1 = website_data.find("'", pass_start + 10); + const size_t pass_end2 = website_data.find("\"", pass_start + 10); + size_t pass_end = pass_end1; + if(pass_end2 != std::string::npos && pass_end2 < pass_end) + pass_end = pass_end2; + + if(pass_end == std::string::npos) + return false; + + const std::string pass_url = "https://dood.wf" + website_data.substr(pass_start, pass_end - pass_start); + std::string video_url; + DownloadResult result = download_to_string(pass_url, video_url, {{ "-H", "Referer: " + referer }}, true); + if(result != DownloadResult::OK) return false; + + const size_t token_start = pass_url.rfind('/'); + if(token_start == std::string::npos) + return false; + + const std::string token = pass_url.substr(token_start + 1); + + char random_str[10]; + if(!generate_random_string_doodstream(random_str, sizeof(random_str))) + return false; + + video_url.append(random_str, sizeof(random_str)); + video_url += "?token=" + token + "&expiry=" + std::to_string((int64_t)time(NULL) * 1000LL); + url = std::move(video_url); + return true; + } + PluginResult DramaCoolEpisodesPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) { std::string website_data; DownloadResult result = download_to_string(args.url, website_data, {}, true); @@ -441,6 +482,15 @@ namespace QuickMedia { referer = "https://www.mp4upload.com"; } + if(!video_sources.doodstream.empty() && video_url.empty()) { + result = download_to_string(video_sources.doodstream, website_data, {}, true); + if(result != DownloadResult::OK) return download_result_to_plugin_result(result); + doodstream_extract_video_url(website_data, video_url, video_sources.doodstream); + + if(!video_url.empty()) + referer = "https://dood.wf"; + } + if(video_url.empty()) return PluginResult::ERR; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index b9fbea0..7bee2ab 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -15,7 +15,6 @@ #include <rapidjson/stringbuffer.h> #include <rapidjson/filereadstream.h> #include <rapidjson/filewritestream.h> -#include <fcntl.h> #include <unistd.h> #include <fstream> #include <malloc.h> @@ -258,6 +257,10 @@ namespace QuickMedia { return std::abs(hash); } + static bool generate_random_string_readable(char *buffer, int buffer_size) { + return generate_random_characters(buffer, buffer_size, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62); + } + mgl::Color user_id_to_color(const std::string &user_id) { const int num_colors = 8; const mgl::Color colors[num_colors] = { @@ -1233,31 +1236,6 @@ namespace QuickMedia { return filepath.c_str() + index + 1; } - static bool generate_random_characters(char *buffer, int buffer_size) { - int fd = open("/dev/urandom", O_RDONLY); - if(fd == -1) { - perror("/dev/urandom"); - return false; - } - - if(read(fd, buffer, buffer_size) < buffer_size) { - fprintf(stderr, "Failed to read %d bytes from /dev/urandom\n", buffer_size); - close(fd); - return false; - } - - close(fd); - return true; - } - - static std::string random_characters_to_readable_string(const char *buffer, int buffer_size) { - std::ostringstream result; - result << std::hex; - for(int i = 0; i < buffer_size; ++i) - result << (int)(unsigned char)buffer[i]; - return result.str(); - } - PluginResult MatrixCustomEmojiPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) { if(args.url == "add") { auto submit_handler = [this](FileManagerPage*, const std::filesystem::path &filepath) { @@ -1270,12 +1248,11 @@ namespace QuickMedia { } if(key.empty()) { - char random_characters[10]; - if(!generate_random_characters(random_characters, sizeof(random_characters))) { + key.resize(10); + if(!generate_random_string_readable(key.data(), key.size())) { show_notification("QuickMedia", "Failed to generate random string", Urgency::CRITICAL); return false; } - key = random_characters_to_readable_string(random_characters, sizeof(random_characters)); } if(matrix->does_custom_emoji_with_name_exist(key)) { @@ -3996,11 +3973,11 @@ namespace QuickMedia { } std::string create_transaction_id() { - char random_characters[18]; - if(!generate_random_characters(random_characters, sizeof(random_characters))) + std::string random_readable_chars; + random_readable_chars.resize(18); + if(!generate_random_string_readable(random_readable_chars.data(), random_readable_chars.size())) return ""; - std::string random_readable_chars = random_characters_to_readable_string(random_characters, sizeof(random_characters)); return "m." + std::to_string(time(NULL)) + random_readable_chars; } diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 33e4cea..f7cfb09 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -18,7 +18,6 @@ extern "C" { #include <json/writer.h> #include <string.h> #include <unistd.h> -#include <fcntl.h> namespace QuickMedia { static const char *youtube_client_version = "x-youtube-client-version: 2.20210622.10.00"; @@ -191,27 +190,6 @@ namespace QuickMedia { static std::string cpn; - static bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size) { - int fd = open("/dev/urandom", O_RDONLY); - if(fd == -1) { - perror("/dev/urandom"); - return false; - } - - if(read(fd, buffer, buffer_size) < buffer_size) { - fprintf(stderr, "Failed to read %d bytes from /dev/urandom\n", buffer_size); - close(fd); - return false; - } - - for(int i = 0; i < buffer_size; ++i) { - unsigned char c = *(unsigned char*)&buffer[i]; - buffer[i] = alphabet[c % alphabet_size]; - } - close(fd); - return true; - } - static std::string header_get_cookie(const char *str, size_t size, const char *cookies_key) { const int cookie_key_len = strlen(cookies_key); const char *cookie_p = (const char*)memmem(str, size, cookies_key, cookie_key_len); |