aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Mangadex.cpp60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp
index 848471f..445c809 100644
--- a/src/plugins/Mangadex.cpp
+++ b/src/plugins/Mangadex.cpp
@@ -215,7 +215,7 @@ namespace QuickMedia {
return search_manga(this, SearchType::TITLE, str, page, result_items);
}
- static PluginResult get_chapters_for_manga(Page *page, const std::string &manga_id, int page_num, BodyItems &result_items, ChapterImageUrls &chapter_image_urls) {
+ static PluginResult get_chapters_for_manga(Page *page, const std::string &manga_id, int page_num, BodyItems &result_items) {
std::string request_url = "https://api.mangadex.org/manga/" + manga_id + "/feed?order[chapter]=desc&limit=100&translatedLanguage[]=en&offset=" + std::to_string(page_num * 100);
Json::Value json_root;
@@ -260,20 +260,12 @@ namespace QuickMedia {
if(strcmp(prev_chapter.c_str(), chapter.c_str()) == 0)
continue;
- const Json::Value &hash_json = attributes_json["hash"];
- if(!hash_json.isString())
- continue;
-
std::string title = "Ch. " + chapter;
prev_chapter = std::move(chapter);
const Json::Value &title_json = attributes_json["title"];
if(title_json.isString() && title_json.asCString()[0] != '\0')
title += " - " + title_json.asString();
- const Json::Value &attributes_data_json = attributes_json["data"];
- if(!attributes_data_json.isArray())
- continue;
-
auto body_item = BodyItem::create(std::move(title));
body_item->url = id_json.asString();
@@ -286,17 +278,6 @@ namespace QuickMedia {
}
}
- std::vector<std::string> image_urls;
- image_urls.reserve(attributes_data_json.size());
- for(const Json::Value &data_item_json : attributes_data_json) {
- if(!data_item_json.isString())
- continue;
-
- std::string url = hash_json.asString() + "/" + data_item_json.asString();
- image_urls.push_back(std::move(url));
- }
- chapter_image_urls[body_item->url] = std::move(image_urls);
-
result_items.push_back(std::move(body_item));
}
@@ -373,13 +354,13 @@ namespace QuickMedia {
PluginResult result;
BodyItems body_items;
- ChapterImageUrls chapter_image_urls;
- result = get_chapters_for_manga(this, url, 0, body_items, chapter_image_urls);
+ result = get_chapters_for_manga(this, url, 0, body_items);
if(result != PluginResult::OK)
return result;
+
auto body = create_body();
body->set_items(std::move(body_items));
- result_tabs.push_back(Tab{std::move(body), std::make_unique<MangadexChaptersPage>(program, this, title, url, std::move(chapter_image_urls)), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ result_tabs.push_back(Tab{std::move(body), std::make_unique<MangadexChaptersPage>(program, this, title, url), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
std::vector<Creator> creators;
result = get_creators_for_manga(this, url, creators);
@@ -395,12 +376,12 @@ namespace QuickMedia {
}
PluginResult MangadexChaptersPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
- result_tabs.push_back(Tab{nullptr, std::make_unique<MangadexImagesPage>(program, search_page, content_title, url, title, &chapter_image_urls), nullptr});
+ result_tabs.push_back(Tab{nullptr, std::make_unique<MangadexImagesPage>(program, search_page, content_title, url, title), nullptr});
return PluginResult::OK;
}
PluginResult MangadexChaptersPage::get_page(const std::string&, int page, BodyItems &result_items) {
- return get_chapters_for_manga(this, content_url, page, result_items, chapter_image_urls);
+ return get_chapters_for_manga(this, content_url, page, result_items);
}
PluginResult MangadexCreatorPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
@@ -456,27 +437,42 @@ namespace QuickMedia {
return ImageResult::OK;
Json::Value json_root;
+ // TODO: If this fails, call this again to retrieve another server. Also do the same for automedia
if(download_json(json_root, "https://api.mangadex.org/at-home/server/" + url, {}, true) != DownloadResult::OK)
return ImageResult::NET_ERR;
if(!json_root.isObject())
return ImageResult::ERR;
+ const Json::Value &result_json = json_root["result"];
+ if(!result_json.isString() || strcmp(result_json.asCString(), "ok") != 0)
+ return ImageResult::ERR;
+
const Json::Value &base_url_json = json_root["baseUrl"];
if(!base_url_json.isString())
return ImageResult::ERR;
+ const Json::Value &chapter_json = json_root["chapter"];
+ if(!chapter_json.isObject())
+ return ImageResult::ERR;
+
+ const Json::Value &hash_json = chapter_json["hash"];
+ if(!hash_json.isString())
+ return ImageResult::ERR;
+
+ const Json::Value &data_json = chapter_json["data"];
+ if(!data_json.isArray())
+ return ImageResult::ERR;
+
std::string base_url = base_url_json.asString();
if(!base_url.empty() && base_url.back() != '/')
base_url += '/';
- auto it = chapter_image_url_templates->find(url);
- if(it == chapter_image_url_templates->end())
- return ImageResult::ERR;
-
- chapter_image_urls.resize(it->second.size());
- for(size_t i = 0; i < it->second.size(); ++i) {
- chapter_image_urls[i] = base_url + "data/" + it->second[i];
+ const std::string hash_str = hash_json.asString();
+ for(const Json::Value &data_item_json : data_json) {
+ if(!data_item_json.isString())
+ continue;
+ chapter_image_urls.push_back(base_url + "data/" + hash_str + "/" + data_item_json.asString());
}
return ImageResult::OK;