aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-07-26 19:50:12 +0200
committerdec05eba <dec05eba@protonmail.com>2022-07-26 19:50:12 +0200
commit8a96eb3a74244f2580e57d12341c80b4748371c9 (patch)
treeb8e0669f24acde224df234cd53ee2b432b143b0c /src
parent6758cdc82e4cb295123b0a84819c6a6ebd5ebad0 (diff)
Redirect mangakakalot/broken manganelo links to migrated url
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Mangadex.cpp3
-rw-r--r--src/plugins/Manganelo.cpp64
2 files changed, 65 insertions, 2 deletions
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp
index c100b0b..a137318 100644
--- a/src/plugins/Mangadex.cpp
+++ b/src/plugins/Mangadex.cpp
@@ -155,6 +155,9 @@ namespace QuickMedia {
}
SearchResult MangadexSearchPage::search(const std::string &str, BodyItems &result_items) {
+ if(str.empty())
+ return SearchResult::OK;
+
return plugin_result_to_search_result(search_manga(this, SearchType::TITLE, str, 0, result_items));
}
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