aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Fourchan.cpp62
-rw-r--r--src/plugins/youtube/YoutubeMediaProxy.cpp2
2 files changed, 61 insertions, 3 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index d4fb726..84a0675 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -3,6 +3,8 @@
#include "../../include/Storage.hpp"
#include "../../include/StringUtils.hpp"
#include "../../include/NetUtils.hpp"
+#include "../../include/Notification.hpp"
+#include "../../external/cppcodec/base64_rfc4648.hpp"
#include <HtmlParser.h>
#include <json/reader.h>
#include <string.h>
@@ -500,7 +502,7 @@ namespace QuickMedia {
return filepath.c_str() + index + 1;
}
- PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &comment, const std::string &filepath) {
+ PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &captcha_solution, const std::string &comment, const std::string &filepath) {
std::string url = "https://sys.4chan.org/" + board_id + "/post";
std::vector<CommandArg> additional_args = {
@@ -517,7 +519,9 @@ namespace QuickMedia {
}
if(pass_id.empty()) {
- additional_args.push_back(CommandArg{"--form-string", "g-recaptcha-response=" + captcha_id});
+ additional_args.push_back(CommandArg{"--form-string", "t-challenge=" + captcha_id});
+ if(!captcha_solution.empty())
+ additional_args.push_back(CommandArg{"--form-string", "t-response=" + captcha_solution});
} else {
Path cookies_filepath;
if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) {
@@ -558,4 +562,58 @@ namespace QuickMedia {
}
return pass_id;
}
+
+ static bool base64_decode(const Json::Value &json_to_decode, std::string &decoded) {
+ if(!json_to_decode.isString())
+ return false;
+
+ const char *start;
+ const char *end;
+ if(!json_to_decode.getString(&start, &end))
+ return false;
+
+ try {
+ decoded = cppcodec::base64_rfc4648::decode<std::string>(start, end - start);
+ return true;
+ } catch(std::exception&) {
+ return false;
+ }
+ }
+
+ PluginResult FourchanThreadPage::request_captcha_challenge(ImageBoardCaptchaChallenge &challenge_response) {
+ Json::Value json_root;
+ DownloadResult result = download_json(json_root, "https://sys.4chan.org/captcha?board=" + url_param_encode(board_id) + "&thread_id=" + thread_id, {}, true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
+
+ if(!json_root.isObject())
+ return PluginResult::ERR;
+
+ const Json::Value &error_json = json_root["error"];
+ if(error_json.isString()) {
+ show_notification("QuickMedia", "Failed to get captcha, error: " + error_json.asString(), Urgency::CRITICAL);
+ return PluginResult::ERR;
+ }
+
+ const Json::Value &challenge_json = json_root["challenge"];
+ const Json::Value &img_json = json_root["img"];
+ const Json::Value &bg_json = json_root["bg"];
+ const Json::Value &ttl_json = json_root["ttl"];
+ if(!challenge_json.isString() || !img_json.isString())
+ return PluginResult::ERR;
+
+ challenge_response.challenge_id = challenge_json.asString();
+
+ if(!base64_decode(img_json, challenge_response.img_data))
+ return PluginResult::ERR;
+
+ if(bg_json.isString() && !base64_decode(bg_json, challenge_response.bg_data))
+ return PluginResult::ERR;
+
+ if(ttl_json.isInt())
+ challenge_response.ttl = ttl_json.asInt();
+ else
+ challenge_response.ttl = 120;
+
+ return PluginResult::OK;
+ }
} \ No newline at end of file
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp
index 2296d1a..d7ffb53 100644
--- a/src/plugins/youtube/YoutubeMediaProxy.cpp
+++ b/src/plugins/youtube/YoutubeMediaProxy.cpp
@@ -38,7 +38,7 @@ namespace QuickMedia {
std::string url = media_url + "&rn=" + std::to_string(rn) + "&rbuf=" + std::to_string(rbuf);
std::vector<const char*> args = { "curl",
//"-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive",
- //"-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
+ "-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
"-g", "-s", "-L", "-f" };
if(is_livestream) {