aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Manganelo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Manganelo.cpp')
-rw-r--r--src/plugins/Manganelo.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp
index 6f0d86f..8186155 100644
--- a/src/plugins/Manganelo.cpp
+++ b/src/plugins/Manganelo.cpp
@@ -2,6 +2,7 @@
#include "../../include/Notification.hpp"
#include "../../include/NetUtils.hpp"
#include "../../include/Theme.hpp"
+#include "../../include/StringUtils.hpp"
#include <quickmedia/HtmlSearch.h>
#include <json/value.h>
@@ -30,12 +31,66 @@ namespace QuickMedia {
return true;
}
+ static PluginResult redirect_check(std::string &website_data) {
+ size_t idx = website_data.find("window.location.assign(\"");
+ if(idx == std::string::npos)
+ return PluginResult::OK;
+
+ idx += 24;
+ size_t end = website_data.find('"', idx);
+ if(end == std::string::npos)
+ return PluginResult::OK;
+
+ std::string url = website_data.substr(idx, end - idx);
+ website_data.clear();
+ if(download_to_string(url, website_data, {CommandArg { "-H", "referer: https://manganelo.com/" }}, true) != DownloadResult::OK)
+ return PluginResult::NET_ERR;
+
+ return PluginResult::OK;
+ }
+
+ static PluginResult redirect_migrated_url(std::string &url, QuickMediaHtmlSearch &html_search) {
+ bool page_not_found = false;
+ quickmedia_html_find_nodes_xpath(&html_search, "//div[class='panel-not-found']",
+ [](QuickMediaMatchNode*, void *userdata) {
+ bool *page_not_found = (bool*)userdata;
+ *page_not_found = true;
+ return 0;
+ }, &page_not_found);
+
+ if(!page_not_found)
+ return PluginResult::OK;
+
+ if(!url.empty() && url.back() == '/')
+ url.pop_back();
+
+ string_replace_all(url, "manganelo", "mangakakalot");
+
+ std::string website_data;
+ if(download_to_string(url, website_data, {CommandArg { "-H", "referer: https://manganelo.com/" }}, true) != DownloadResult::OK)
+ return PluginResult::NET_ERR;
+
+ redirect_check(website_data);
+
+ quickmedia_html_search_deinit(&html_search);
+ memset(&html_search, 0, sizeof(html_search));
+
+ int result = quickmedia_html_search_init(&html_search, website_data.c_str(), website_data.size());
+ if(result != 0)
+ return PluginResult::ERR;
+
+ return PluginResult::OK;
+ }
+
static PluginResult submit_manga(Page *page, const SubmitArgs &args, std::vector<Tab> &result_tabs) {
BodyItems chapters_items;
std::vector<Creator> creators;
+ std::string url = args.url;
+ string_replace_all(url, "mangakakalot", "manganelo");
+
std::string website_data;
- if(download_to_string(args.url, website_data, {CommandArg { "-H", "referer: https://manganelo.com/" }}, true) != DownloadResult::OK)
+ if(download_to_string(url, website_data, {CommandArg { "-H", "referer: https://manganelo.com/" }}, true) != DownloadResult::OK)
return PluginResult::NET_ERR;
QuickMediaHtmlSearch html_search;
@@ -43,6 +98,11 @@ namespace QuickMedia {
if(result != 0)
goto cleanup;
+ if(redirect_migrated_url(url, html_search) != PluginResult::OK) {
+ result = -1;
+ goto cleanup;
+ }
+
result = quickmedia_html_find_nodes_xpath(&html_search, "//ul[class='row-content-chapter']//a",
[](QuickMediaMatchNode *node, void *userdata) {
auto *item_data = (BodyItems*)userdata;
@@ -95,7 +155,7 @@ namespace QuickMedia {
auto chapters_body = page->create_body();
chapters_body->set_items(std::move(chapters_items));
- auto chapters_page = std::make_unique<ManganeloChaptersPage>(page->program, args.title, args.url, args.thumbnail_url);
+ auto chapters_page = std::make_unique<ManganeloChaptersPage>(page->program, args.title, url, args.thumbnail_url);
result_tabs.push_back(Tab{std::move(chapters_body), std::move(chapters_page), page->create_search_bar("Search...", SEARCH_DELAY_FILTER)});
// TODO: Fix. Doesn't work because manganelo changed creator url format