diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-14 18:37:00 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-14 18:37:34 +0200 |
commit | d6131b8ba482414be76f2478aea90bd7a4a2379b (patch) | |
tree | 9ea48087f0db0d7c956b87d09a93d8b3a335551a /src/plugins | |
parent | 6208faf754b76a7c9a806220c97484ea2e9c0a2e (diff) |
Add support for 4chan pass
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Fourchan.cpp | 92 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 2 |
2 files changed, 93 insertions, 1 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 42bb54e..5932144 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -45,7 +45,34 @@ namespace QuickMedia { thread_list_update_thread.join(); } + // Returns empty string on failure to read cookie + static std::string get_pass_id_from_cookies_file(const Path &cookies_filepath) { + std::string file_content; + if(file_get_content(cookies_filepath, file_content) != 0) + return ""; + + size_t pass_id_index = file_content.find("pass_id"); + if(pass_id_index == std::string::npos) + return ""; + + pass_id_index += 7; + size_t line_end = file_content.find('\n', pass_id_index); + if(line_end == std::string::npos) + line_end = file_content.size(); + + return strip(file_content.substr(pass_id_index, line_end - pass_id_index)); + } + PluginResult Fourchan::get_front_page(BodyItems &result_items) { + if(pass_id.empty()) { + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, name) != 0) { + fprintf(stderr, "Failed to get 4chan cookies filepath\n"); + } else { + pass_id = get_pass_id_from_cookies_file(cookies_filepath); + } + } + #if 0 std::string server_response; if(download_to_string(fourchan_url + "boards.json", server_response, {}, use_tor) != DownloadResult::OK) @@ -543,6 +570,20 @@ namespace QuickMedia { CommandArg{"-H", "Content-Type: multipart/form-data; boundary=---------------------------119561554312148213571335532670"}, CommandArg{"-H", "Origin: https://boards.4chan.org"} }; + + if(pass_id.empty()) { + form_data.push_back(FormData{"g-recaptcha-response", captcha_id}); + } else { + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, name) != 0) { + fprintf(stderr, "Failed to get 4chan cookies filepath\n"); + return PostResult::ERR; + } else { + additional_args.push_back(CommandArg{"-c", cookies_filepath.data}); + additional_args.push_back(CommandArg{"-b", cookies_filepath.data}); + } + } + std::vector<CommandArg> form_data_args = create_command_args_from_form_data(form_data); additional_args.insert(additional_args.end(), form_data_args.begin(), form_data_args.end()); @@ -573,4 +614,55 @@ namespace QuickMedia { } return body_items; } + + PluginResult Fourchan::login(const std::string &token, const std::string &pin, std::string &response_msg) { + response_msg.clear(); + + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, name) != 0) { + fprintf(stderr, "Failed to get 4chan cookies filepath\n"); + return PluginResult::ERR; + } + + std::vector<CommandArg> additional_args = { + CommandArg{"-F", "id=" + token}, + CommandArg{"-F", "pin=" + pin}, + CommandArg{"-F", "xhr=1"}, + CommandArg{"-c", cookies_filepath.data} + }; + + std::string response; + if(download_to_string("https://sys.4chan.org/auth", response, std::move(additional_args), use_tor, true) != DownloadResult::OK) + return PluginResult::NET_ERR; + + Json::Value json_root; + Json::CharReaderBuilder json_builder; + std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader()); + std::string json_errors; + if(!json_reader->parse(&response[0], &response[response.size()], &json_root, &json_errors) || !json_root.isObject()) { + fprintf(stderr, "Youtube get front page error: %s\n", json_errors.c_str()); + return PluginResult::ERR; + } + + const Json::Value &status_json = json_root["status"]; + if(!status_json.isNumeric()) + return PluginResult::ERR; + + const Json::Value &message_json = json_root["message"]; + if(message_json.isString()) + response_msg = message_json.asString(); + + if(status_json.asInt64() == 1) { + pass_id = get_pass_id_from_cookies_file(cookies_filepath); + if(pass_id.empty()) + return PluginResult::ERR; + return PluginResult::OK; + } else { + return PluginResult::ERR; + } + } + + const std::string& Fourchan::get_pass_id() const { + return pass_id; + } }
\ No newline at end of file diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 10f689f..4afa89b 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -241,7 +241,7 @@ namespace QuickMedia { } bool Mangadex::save_mangadex_cookies(const std::string &url, const std::string &cookie_filepath) { - CommandArg cookie_arg = { "-c", std::move(cookie_filepath) }; + CommandArg cookie_arg = { "-c", cookie_filepath }; std::string server_response; if(download_to_string(url, server_response, {std::move(cookie_arg)}, use_tor, true) != DownloadResult::OK) return false; |