diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Fourchan.cpp | 53 | ||||
-rw-r--r-- | src/plugins/MangaGeneric.cpp | 2 | ||||
-rw-r--r-- | src/plugins/NyaaSi.cpp | 9 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 4 | ||||
-rw-r--r-- | src/plugins/youtube/Signature.cpp | 2 | ||||
-rw-r--r-- | src/plugins/youtube/YoutubeMediaProxy.cpp | 2 |
6 files changed, 40 insertions, 32 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 84a0675..24886c6 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -503,6 +503,12 @@ namespace QuickMedia { } PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &captcha_solution, const std::string &comment, const std::string &filepath) { + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) { + fprintf(stderr, "Failed to get 4chan cookies filepath\n"); + return PostResult::ERR; + } + std::string url = "https://sys.4chan.org/" + board_id + "/post"; std::vector<CommandArg> additional_args = { @@ -510,7 +516,9 @@ namespace QuickMedia { CommandArg{"-H", "Origin: https://boards.4chan.org"}, CommandArg{"--form-string", "resto=" + thread_id}, CommandArg{"--form-string", "com=" + comment}, - CommandArg{"--form-string", "mode=regist"} + CommandArg{"--form-string", "mode=regist"}, + CommandArg{"-c", cookies_filepath.data}, + CommandArg{"-b", cookies_filepath.data} }; if(!filepath.empty()) { @@ -520,17 +528,7 @@ namespace QuickMedia { if(pass_id.empty()) { 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) { - 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}); - } + additional_args.push_back(CommandArg{"--form-string", "t-response=" + captcha_solution}); } std::string response; @@ -541,8 +539,10 @@ namespace QuickMedia { return PostResult::OK; if(response.find("banned") != std::string::npos) return PostResult::BANNED; - if(response.find("try again") != std::string::npos || response.find("No valid captcha") != std::string::npos) + if(response.find("try again") != std::string::npos) return PostResult::TRY_AGAIN; + if(response.find("No valid captcha") != std::string::npos) + return PostResult::INVALID_CAPTCHA; if(response.find("Audio streams are not allowed") != std::string::npos) return PostResult::FILE_TYPE_NOT_ALLOWED; if(response.find("Error: Upload failed") != std::string::npos) @@ -581,8 +581,19 @@ namespace QuickMedia { } PluginResult FourchanThreadPage::request_captcha_challenge(ImageBoardCaptchaChallenge &challenge_response) { + Path cookies_filepath; + if(get_cookies_filepath(cookies_filepath, SERVICE_NAME) != 0) { + fprintf(stderr, "Failed to get 4chan cookies filepath\n"); + return PluginResult::ERR; + } + + std::vector<CommandArg> additional_args = { + CommandArg{"-c", cookies_filepath.data}, + CommandArg{"-b", cookies_filepath.data} + }; + 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); + DownloadResult result = download_json(json_root, "https://sys.4chan.org/captcha?board=" + url_param_encode(board_id) + "&thread_id=" + thread_id, std::move(additional_args), true); if(result != DownloadResult::OK) return download_result_to_plugin_result(result); if(!json_root.isObject()) @@ -598,16 +609,20 @@ namespace QuickMedia { 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()) + if(!challenge_json.isString()) return PluginResult::ERR; challenge_response.challenge_id = challenge_json.asString(); + if(strcmp(challenge_json.asCString(), "noop") != 0) { + if(!img_json.isString()) + return PluginResult::ERR; - if(!base64_decode(img_json, challenge_response.img_data)) - return PluginResult::ERR; + 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(bg_json.isString() && !base64_decode(bg_json, challenge_response.bg_data)) + return PluginResult::ERR; + } if(ttl_json.isInt()) challenge_response.ttl = ttl_json.asInt(); diff --git a/src/plugins/MangaGeneric.cpp b/src/plugins/MangaGeneric.cpp index 29480da..4668970 100644 --- a/src/plugins/MangaGeneric.cpp +++ b/src/plugins/MangaGeneric.cpp @@ -487,7 +487,7 @@ namespace QuickMedia { if(field1_value.data) { std::string field_value_stripped(field1_value.data, field1_value.size); if(is_number(field_value_stripped.c_str())) - page_count_userdata->num_pages = strtol(field_value_stripped.c_str(), nullptr, 10); + page_count_userdata->num_pages = strtoll(field_value_stripped.c_str(), nullptr, 10); } return 0; }, &page_count_userdata); diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index 0202322..ccf027d 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -4,6 +4,7 @@ #include "../../include/Notification.hpp" #include "../../include/StringUtils.hpp" #include "../../include/NetUtils.hpp" +#include "../../include/Utils.hpp" #include <quickmedia/HtmlSearch.h> namespace QuickMedia { @@ -99,14 +100,6 @@ namespace QuickMedia { return timegm(&time); } - static std::string unix_time_to_local_time_str(time_t unix_time) { - struct tm time_tm; - localtime_r(&unix_time, &time_tm); - char time_str[128] = {0}; - strftime(time_str, sizeof(time_str) - 1, "%Y %b %d, %a %H:%M", &time_tm); - return time_str; - } - static const std::array<const char*, 10> sort_type_names = { "Size desc 🡇", "Uploaded date desc 🡇", diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 7e5bd7b..f81d934 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -288,7 +288,7 @@ R"END( errno = 0; char *endptr; - content_length = strtol(content_length_str.c_str(), &endptr, 10); + content_length = strtoll(content_length_str.c_str(), &endptr, 10); if(endptr == content_length_str.c_str() || errno != 0) return ""; @@ -488,7 +488,7 @@ R"END( if(!upcoming_event_text) return nullptr; - time_t start_time = strtol(start_time_json.asCString(), nullptr, 10); + time_t start_time = strtoll(start_time_json.asCString(), nullptr, 10); struct tm message_tm; localtime_r(&start_time, &message_tm); char time_str[128] = {0}; diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp index 59385ad..394abf0 100644 --- a/src/plugins/youtube/Signature.cpp +++ b/src/plugins/youtube/Signature.cpp @@ -77,7 +77,7 @@ namespace QuickMedia { errno = 0; char *endptr; - const long value_int = strtol(value_args.c_str(), &endptr, 10); + const long value_int = strtoll(value_args.c_str(), &endptr, 10); if(endptr != value_args.c_str() && errno == 0) new_func_calls.push_back({ std::move(func_name), value_int }); else diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp index d7ffb53..6642b86 100644 --- a/src/plugins/youtube/YoutubeMediaProxy.cpp +++ b/src/plugins/youtube/YoutubeMediaProxy.cpp @@ -690,7 +690,7 @@ namespace QuickMedia { if(sequence_num.empty()) fprintf(stderr, "YoutubeLiveStreamMediaProxy::handle_download: missing sequence num from server\n"); else - livestream_sequence_num = strtol(sequence_num.c_str(), nullptr, 10); + livestream_sequence_num = strtoll(sequence_num.c_str(), nullptr, 10); } } else { if(download_header.size() > MAX_BUFFER_SIZE) { |