aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Mangadex.hpp10
-rw-r--r--src/plugins/Mangadex.cpp60
2 files changed, 32 insertions, 38 deletions
diff --git a/plugins/Mangadex.hpp b/plugins/Mangadex.hpp
index b92489d..c9f9515 100644
--- a/plugins/Mangadex.hpp
+++ b/plugins/Mangadex.hpp
@@ -25,8 +25,8 @@ namespace QuickMedia {
class MangadexChaptersPage : public MangaChaptersPage {
public:
- MangadexChaptersPage(Program *program, MangadexSearchPage *search_page, std::string manga_name, std::string manga_url, ChapterImageUrls chapter_image_urls) :
- MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), search_page(search_page), chapter_image_urls(std::move(chapter_image_urls)) {}
+ MangadexChaptersPage(Program *program, MangadexSearchPage *search_page, std::string manga_name, std::string manga_url) :
+ MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), search_page(search_page) {}
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
const char* get_bookmark_name() const override { return "mangadex"; }
@@ -35,7 +35,6 @@ namespace QuickMedia {
const char* get_service_name() const override { return "mangadex"; }
private:
MangadexSearchPage *search_page;
- ChapterImageUrls chapter_image_urls;
};
class MangadexCreatorPage : public LazyFetchPage {
@@ -52,8 +51,8 @@ namespace QuickMedia {
class MangadexImagesPage : public MangaImagesPage {
public:
- MangadexImagesPage(Program *program, MangadexSearchPage *search_page, std::string manga_name, std::string chapter_id, std::string chapter_name, ChapterImageUrls *chapter_image_url_templates) :
- MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(chapter_id)), search_page(search_page), chapter_image_url_templates(chapter_image_url_templates) {}
+ MangadexImagesPage(Program *program, MangadexSearchPage *search_page, std::string manga_name, std::string chapter_id, std::string chapter_name) :
+ MangaImagesPage(program, std::move(manga_name), std::move(chapter_name), std::move(chapter_id)), search_page(search_page) {}
ImageResult get_number_of_images(int &num_images) override;
ImageResult for_each_page_in_chapter(PageCallback callback) override;
const char* get_service_name() const override { return "mangadex"; }
@@ -62,6 +61,5 @@ namespace QuickMedia {
ImageResult get_image_urls_for_chapter(const std::string &url);
private:
MangadexSearchPage *search_page;
- ChapterImageUrls *chapter_image_url_templates;
};
} \ No newline at end of file
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;