diff options
Diffstat (limited to 'src/plugins/Fourchan.cpp')
-rw-r--r-- | src/plugins/Fourchan.cpp | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index cf229d4..1ce97c4 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -19,6 +19,43 @@ static const std::string fourchan_image_url = "https://i.4cdn.org/"; static const char *SERVICE_NAME = "4chan"; namespace QuickMedia { + bool fourchan_extract_url(const std::string &url, std::string &board_id, std::string &thread_id, std::string &post_id) { + size_t len = 10; + size_t index = url.find("4chan.org/"); + if(index == std::string::npos) { + len = 13; + index = url.find("4channel.org/"); + } + + if(index == std::string::npos) + return false; + + index += len; + size_t board_end = url.find('/', index); + if(board_end == std::string::npos) + return false; + + board_id = url.substr(index, board_end - index); + index = board_end + 1; + + const std::string_view remaining(url.data() + index, url.size() - index); + if(remaining.size() <= 7 || remaining.substr(0, 7) != "thread/") + return false; + + index += 7; + size_t thread_id_end = url.find("#p", index); + if(thread_id_end == std::string::npos) + thread_id_end = url.size(); + + thread_id = url.substr(index, thread_id_end - index); + if(thread_id.empty()) + return false; + + index = thread_id_end + 2; + post_id = url.substr(index); + return true; + } + // 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; @@ -271,9 +308,9 @@ namespace QuickMedia { // TODO: Link this quote to a 4chan archive that still has the quoted comment (if available) comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); } else { - result_items[body_item_index]->replies_to.push_back(it->second); - result_items[it->second]->replies.push_back(body_item_index); - result_items[it->second]->add_reaction(">>" + result_items[body_item_index]->post_number, nullptr, get_theme().replies_text_color); + static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->replies_to.push_back(it->second); + static_cast<ImageBoardBodyItemData*>(result_items[it->second]->extra.get())->replies.push_back(body_item_index); + result_items[it->second]->add_reaction(">>" + std::to_string(static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->post_id), nullptr, get_theme().replies_text_color); if(it->second == 0) comment_text += Text::formatted_text(std::move(cp.text) + " (OP)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); else @@ -391,7 +428,7 @@ namespace QuickMedia { } PluginResult FourchanThreadListPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) { - result_tabs.push_back(Tab{create_body(), std::make_unique<FourchanThreadPage>(program, board_id, args.url, pass_id), nullptr}); + result_tabs.push_back(Tab{create_body(), std::make_unique<FourchanThreadPage>(program, board_id, args.url, "", pass_id), nullptr}); return PluginResult::OK; } @@ -500,8 +537,10 @@ namespace QuickMedia { int64_t post_num_int = post_num.asInt64(); comment_by_postno[post_num_int] = result_items.size(); + auto image_board_post_data = std::make_shared<ImageBoardBodyItemData>(); + image_board_post_data->post_id = post_num_int; result_items.push_back(BodyItem::create("")); - result_items.back()->post_number = std::to_string(post_num_int); + result_items.back()->extra = std::move(image_board_post_data); } size_t body_item_index = 0; |