aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-09-17 14:37:26 +0200
committerdec05eba <dec05eba@protonmail.com>2022-09-17 14:37:26 +0200
commit1eff755a13250e588538c20c7e27fff5036b8c5b (patch)
treee8f4fc53396860d402ffb93359e7cae71205197f /src/plugins
parentf34a17de0d867a8788a63ae9a955052744815922 (diff)
Dramacool: make mixdrop decoded more robust by decoding all parts and checking which decoded part is the video
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/DramaCool.cpp109
1 files changed, 82 insertions, 27 deletions
diff --git a/src/plugins/DramaCool.cpp b/src/plugins/DramaCool.cpp
index 4bb1054..3042519 100644
--- a/src/plugins/DramaCool.cpp
+++ b/src/plugins/DramaCool.cpp
@@ -222,18 +222,61 @@ namespace QuickMedia {
return true;
}
- static bool mixdrop_extract_mdcore_script(const std::string &website_data, const std::string &prefix, std::string &mdcore_script) {
- size_t script_start = website_data.find(prefix);
- if(script_start == std::string::npos)
- return false;
+ static std::vector<std::string> extract_javascript_sections(const std::string &html_source) {
+ std::vector<std::string> sections;
+ size_t start = 0;
+
+ while(true) {
+ start = html_source.find("<script", start);
+ if(start == std::string::npos)
+ break;
+
+ start += 7;
+ start = html_source.find(">", start);
+ if(start == std::string::npos)
+ break;
+
+ start += 1;
+ size_t end = html_source.find("</script>", start);
+ if(end == std::string::npos)
+ break;
+
+ sections.push_back(html_source.substr(start, end - start));
+ start = end + 9;
+ }
+
+ return sections;
+ }
- script_start += prefix.size();
- size_t script_end = website_data.find("\"", script_start);
- if(script_end == std::string::npos)
- return false;
+ static std::vector<std::string> mixdrop_extract_mdcore_scripts(const std::string &website_data) {
+ std::vector<std::string> scripts;
+ for(const std::string &js_section : extract_javascript_sections(website_data)) {
+ size_t eval_index = js_section.find("eval");
+ if(eval_index == std::string::npos)
+ continue;
- mdcore_script = website_data.substr(script_start, script_end - script_start);
- return true;
+ eval_index += 4;
+ size_t start = eval_index;
+
+ while(true) {
+ size_t script_start = js_section.find("\"//", start);
+ if(script_start == std::string::npos) {
+ script_start = js_section.find("://", start);
+ if(script_start == std::string::npos)
+ break;
+ }
+
+ script_start += 3;
+ size_t script_end = js_section.find("\"", script_start);
+ if(script_end == std::string::npos)
+ break;
+
+ size_t url_start = script_start - 2;
+ scripts.push_back(js_section.substr(url_start, script_end - url_start));
+ start = script_end + 1;
+ }
+ }
+ return scripts;
}
static bool mixdrop_extract_mdcore_parts(const std::string &website_data, std::vector<std::string> &parts) {
@@ -268,14 +311,8 @@ namespace QuickMedia {
return -1;
}
- static bool mixdrop_extract_video_url(const std::string &website_data, const std::string &prefix, std::string &url) {
- std::string mdcore_script;
- if(!mixdrop_extract_mdcore_script(website_data, prefix, mdcore_script))
- return false;
-
- std::vector<std::string> mdcore_parts;
- if(!mixdrop_extract_mdcore_parts(website_data, mdcore_parts))
- return false;
+ static std::string mdcore_script_decode(const std::string &mdcore_script, const std::vector<std::string> &mdcore_parts) {
+ std::string decoded;
for(size_t i = 0; i < mdcore_script.size();) {
char c = mdcore_script[i];
@@ -289,21 +326,38 @@ namespace QuickMedia {
++i;
}
} else {
- url += c;
+ decoded += c;
++i;
continue;
}
if(index >= (int)mdcore_parts.size() || mdcore_parts[index].empty())
- url += c;
+ decoded += c;
else
- url += mdcore_parts[index];
+ decoded += mdcore_parts[index];
}
- if(string_starts_with(url, "//"))
- url = "http:" + url;
+ if(string_starts_with(decoded, "//"))
+ decoded = "https:" + decoded;
- return true;
+ return decoded;
+ }
+
+ static bool mixdrop_extract_video_url(const std::string &website_data, std::string &url) {
+ std::vector<std::string> mdcore_scripts = mixdrop_extract_mdcore_scripts(website_data);
+ std::vector<std::string> mdcore_parts;
+ if(!mixdrop_extract_mdcore_parts(website_data, mdcore_parts))
+ return false;
+
+ for(const std::string &mdcore_script : mixdrop_extract_mdcore_scripts(website_data)) {
+ std::string decoded_url = mdcore_script_decode(mdcore_script, mdcore_parts);
+ if(decoded_url.find("/v/") != std::string::npos || decoded_url.find("/d/") != std::string::npos) {
+ url = std::move(decoded_url);
+ return true;
+ }
+ }
+
+ return false;
}
PluginResult DramaCoolEpisodesPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
@@ -371,7 +425,7 @@ namespace QuickMedia {
if(!video_sources.mixdrop.empty() && video_url.empty()) {
result = download_to_string(video_sources.mixdrop, website_data, {}, true);
if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
- mixdrop_extract_video_url(website_data, "0.f=\"", video_url);
+ mixdrop_extract_video_url(website_data, video_url);
if(!video_url.empty())
referer = "https://mixdrop.co";
@@ -380,8 +434,9 @@ namespace QuickMedia {
if(!video_sources.mp4upload.empty() && video_url.empty()) {
result = download_to_string(video_sources.mp4upload, website_data, {}, true);
if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
- // mp4upload uses the same algorithm as mixdrop but with different format
- mixdrop_extract_video_url(website_data, "2.25(\"", video_url);
+ // mp4upload uses the same algorithm as mixdrop but with a different format.
+ // |mixdrop_extract_video_url| handles both formats.
+ mixdrop_extract_video_url(website_data, video_url);
if(!video_url.empty())
referer = "https://www.mp4upload.com";