diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/FileManager.cpp | 1 | ||||
-rw-r--r-- | src/plugins/Fourchan.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Manga.cpp | 6 | ||||
-rw-r--r-- | src/plugins/Mangadex.cpp | 13 | ||||
-rw-r--r-- | src/plugins/Manganelo.cpp | 159 | ||||
-rw-r--r-- | src/plugins/Mangatown.cpp | 20 | ||||
-rw-r--r-- | src/plugins/NyaaSi.cpp | 2 |
7 files changed, 121 insertions, 82 deletions
diff --git a/src/plugins/FileManager.cpp b/src/plugins/FileManager.cpp index 5fac79c..f65486e 100644 --- a/src/plugins/FileManager.cpp +++ b/src/plugins/FileManager.cpp @@ -48,7 +48,6 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - body->draw_thumbnails = true; result_tabs.push_back(Tab{std::move(body), nullptr, nullptr}); return PluginResult::OK; } diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 7f8008c..d042a2a 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -267,7 +267,6 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - body->draw_thumbnails = true; result_tabs.push_back(Tab{std::move(body), std::make_unique<FourchanThreadListPage>(program, title, url), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); return PluginResult::OK; } @@ -459,7 +458,6 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - body->draw_thumbnails = true; result_tabs.push_back(Tab{std::move(body), std::make_unique<FourchanThreadPage>(program, board_id, url, std::move(cached_media_urls)), nullptr}); return PluginResult::OK; } diff --git a/src/plugins/Manga.cpp b/src/plugins/Manga.cpp index 70a1664..323794c 100644 --- a/src/plugins/Manga.cpp +++ b/src/plugins/Manga.cpp @@ -9,4 +9,10 @@ namespace QuickMedia { else return TrackResult::ERR; } + + void MangaChaptersPage::on_navigate_to_page() { + std::string manga_id; + if(extract_id_from_url(content_url, manga_id)) + load_manga_content_storage(get_service_name(), content_title, manga_id); + } }
\ No newline at end of file diff --git a/src/plugins/Mangadex.cpp b/src/plugins/Mangadex.cpp index 3574914..e798b60 100644 --- a/src/plugins/Mangadex.cpp +++ b/src/plugins/Mangadex.cpp @@ -112,8 +112,7 @@ namespace QuickMedia { } PluginResult MangadexSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { - std::string manga_id = title_url_extract_manga_id(url); - std::string request_url = "https://mangadex.org/api/?id=" + manga_id + "&type=manga"; + std::string request_url = "https://mangadex.org/api/?id=" + title_url_extract_manga_id(url) + "&type=manga"; rapidjson::Document json_root; DownloadResult result = download_to_json(request_url, json_root, {}, is_tor_enabled(), true); @@ -169,10 +168,7 @@ namespace QuickMedia { } result_tabs.push_back(Tab{std::move(body), std::make_unique<MangadexChaptersPage>(program, title, url), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); - - if(load_manga_content_storage("mangadex", title, manga_id)) - return PluginResult::OK; - return PluginResult::ERR; + return PluginResult::OK; } bool MangadexSearchPage::get_rememberme_token(std::string &rememberme_token_output) { @@ -212,6 +208,11 @@ namespace QuickMedia { return PluginResult::OK; } + bool MangadexChaptersPage::extract_id_from_url(const std::string &url, std::string &manga_id) const { + manga_id = title_url_extract_manga_id(url); + return true; + } + ImageResult MangadexImagesPage::get_number_of_images(int &num_images) { num_images = 0; ImageResult image_result = get_image_urls_for_chapter(url); diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp index b260dea..7f0a2f9 100644 --- a/src/plugins/Manganelo.cpp +++ b/src/plugins/Manganelo.cpp @@ -25,49 +25,12 @@ namespace QuickMedia { return true; } - SearchResult ManganeloSearchPage::search(const std::string &str, BodyItems &result_items) { - std::string url = "https://manganelo.com/getstorysearchjson"; - std::string search_term = "searchword="; - search_term += url_param_encode(str); - CommandArg data_arg = { "--data", std::move(search_term) }; - - Json::Value json_root; - DownloadResult result = download_json(json_root, url, {data_arg}, true); - if(result != DownloadResult::OK) return download_result_to_search_result(result); - - if(json_root.isNull()) - return SearchResult::OK; - - if(!json_root.isArray()) - return SearchResult::ERR; - - for(const Json::Value &child : json_root) { - if(!child.isObject()) - continue; - - Json::Value name = child.get("name", ""); - Json::Value nameunsigned = child.get("nameunsigned", ""); - if(name.isString() && name.asCString()[0] != '\0' && nameunsigned.isString() && nameunsigned.asCString()[0] != '\0') { - std::string name_str = name.asString(); - while(remove_html_span(name_str)) {} - auto item = BodyItem::create(strip(name_str)); - item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString()); - Json::Value image = child.get("image", ""); - if(image.isString() && image.asCString()[0] != '\0') - item->thumbnail_url = image.asString(); - result_items.push_back(std::move(item)); - } - } - - return SearchResult::OK; - } - - PluginResult ManganeloSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { + static PluginResult submit_manga(Page *page, const std::string &title, const std::string &url, std::vector<Tab> &result_tabs, bool use_tor) { BodyItems chapters_items; std::vector<Creator> creators; std::string website_data; - if(download_to_string(url, website_data, {}, is_tor_enabled(), true) != DownloadResult::OK) + if(download_to_string(url, website_data, {}, use_tor, true) != DownloadResult::OK) return PluginResult::NET_ERR; QuickMediaHtmlSearch html_search; @@ -105,23 +68,64 @@ namespace QuickMedia { if(result != 0) return PluginResult::ERR; - auto chapters_body = create_body(); + auto chapters_body = page->create_body(); chapters_body->items = std::move(chapters_items); - result_tabs.push_back(Tab{std::move(chapters_body), std::make_unique<ManganeloChaptersPage>(program, title, url), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + result_tabs.push_back(Tab{std::move(chapters_body), std::make_unique<ManganeloChaptersPage>(page->program, title, url), page->create_search_bar("Search...", SEARCH_DELAY_FILTER)}); for(Creator &creator : creators) { - result_tabs.push_back(Tab{create_body(), std::make_unique<ManganeloCreatorPage>(program, std::move(creator)), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + result_tabs.push_back(Tab{page->create_body(), std::make_unique<ManganeloCreatorPage>(page->program, std::move(creator)), page->create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } - std::string manga_id; - if(extract_id_from_url(url, manga_id)) { - if(load_manga_content_storage("manganelo", title, manga_id)) - return PluginResult::OK; + return PluginResult::OK; + } + + SearchResult ManganeloSearchPage::search(const std::string &str, BodyItems &result_items) { + std::string url = "https://manganelo.com/getstorysearchjson"; + std::string search_term = "searchword="; + search_term += url_param_encode(str); + CommandArg data_arg = { "--data", std::move(search_term) }; + + Json::Value json_root; + DownloadResult result = download_json(json_root, url, {data_arg}, true); + if(result != DownloadResult::OK) return download_result_to_search_result(result); + + if(json_root.isNull()) + return SearchResult::OK; + + if(!json_root.isArray()) + return SearchResult::ERR; + + for(const Json::Value &child : json_root) { + if(!child.isObject()) + continue; + + Json::Value name = child.get("name", ""); + Json::Value nameunsigned = child.get("nameunsigned", ""); + if(name.isString() && name.asCString()[0] != '\0' && nameunsigned.isString() && nameunsigned.asCString()[0] != '\0') { + std::string name_str = name.asString(); + while(remove_html_span(name_str)) {} + auto item = BodyItem::create(strip(name_str)); + item->url = "https://manganelo.com/manga/" + url_param_encode(nameunsigned.asString()); + Json::Value image = child.get("image", ""); + if(image.isString() && image.asCString()[0] != '\0') + item->thumbnail_url = image.asString(); + result_items.push_back(std::move(item)); + } } - return PluginResult::ERR; + + return SearchResult::OK; + } + + PluginResult ManganeloSearchPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { + return submit_manga(this, title, url, result_tabs, is_tor_enabled()); + } + + PluginResult ManganeloChaptersPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { + result_tabs.push_back(Tab{create_body(), std::make_unique<ManganeloImagesPage>(program, content_title, title, url), nullptr}); + return PluginResult::OK; } - - bool ManganeloSearchPage::extract_id_from_url(const std::string &url, std::string &manga_id) const { + + bool ManganeloChaptersPage::extract_id_from_url(const std::string &url, std::string &manga_id) const { bool manganelo_website = false; if(url.find("mangakakalot") != std::string::npos || url.find("manganelo") != std::string::npos) manganelo_website = true; @@ -154,17 +158,56 @@ namespace QuickMedia { } } - PluginResult ManganeloChaptersPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { - result_tabs.push_back(Tab{create_body(), std::make_unique<ManganeloImagesPage>(program, content_title, title, url), nullptr}); - return PluginResult::OK; + PluginResult ManganeloCreatorPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { + return submit_manga(this, title, url, result_tabs, is_tor_enabled()); } - PluginResult ManganeloCreatorPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { - (void)title; - (void)url; - (void)result_tabs; - // TODO: Implement - return PluginResult::ERR; + PluginResult ManganeloCreatorPage::lazy_fetch(BodyItems &result_items) { + std::string website_data; + if(download_to_string(creator.url, website_data, {}, is_tor_enabled(), true) != DownloadResult::OK) + return PluginResult::NET_ERR; + + QuickMediaHtmlSearch html_search; + int result = quickmedia_html_search_init(&html_search, website_data.c_str()); + if(result != 0) + goto cleanup; + + result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='search-story-item']//a[class='item-img']", + [](QuickMediaHtmlNode *node, void *userdata) { + auto *item_data = (BodyItems*)userdata; + const char *href = quickmedia_html_node_get_attribute_value(node, "href"); + const char *title = quickmedia_html_node_get_attribute_value(node, "title"); + if(href && title && strstr(href, "/manga/")) { + auto body_item = BodyItem::create(title); + body_item->url = href; + item_data->push_back(std::move(body_item)); + } + }, &result_items); + + if(result != 0) + goto cleanup; + + BodyItemImageContext body_item_image_context; + body_item_image_context.body_items = &result_items; + body_item_image_context.index = 0; + + result = quickmedia_html_find_nodes_xpath(&html_search, "//div[class='search-story-item']//a[class='item-img']//img", + [](QuickMediaHtmlNode *node, void *userdata) { + auto *item_data = (BodyItemImageContext*)userdata; + const char *src = quickmedia_html_node_get_attribute_value(node, "src"); + if(src && item_data->index < item_data->body_items->size()) { + (*item_data->body_items)[item_data->index]->thumbnail_url = src; + item_data->index++; + } + }, &body_item_image_context); + + cleanup: + quickmedia_html_search_deinit(&html_search); + if(result != 0) { + result_items.clear(); + return PluginResult::ERR; + } + return PluginResult::OK; } ImageResult ManganeloImagesPage::get_number_of_images(int &num_images) { diff --git a/src/plugins/Mangatown.cpp b/src/plugins/Mangatown.cpp index d9013f7..89bf447 100644 --- a/src/plugins/Mangatown.cpp +++ b/src/plugins/Mangatown.cpp @@ -106,16 +106,15 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(chapters_items); result_tabs.push_back(Tab{std::move(body), std::make_unique<MangatownChaptersPage>(program, title, url), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + return PluginResult::OK; + } - std::string manga_id; - if(extract_id_from_url(url, manga_id)) { - if(load_manga_content_storage("mangatown", title, manga_id)) - return PluginResult::OK; - } - return PluginResult::ERR; + PluginResult MangatownChaptersPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { + result_tabs.push_back(Tab{create_body(), std::make_unique<MangatownImagesPage>(program, content_title, title, url), nullptr}); + return PluginResult::OK; } - - bool MangatownSearchPage::extract_id_from_url(const std::string &url, std::string &manga_id) const { + + bool MangatownChaptersPage::extract_id_from_url(const std::string &url, std::string &manga_id) const { size_t start_index = url.find("/manga/"); if(start_index == std::string::npos) return false; @@ -131,11 +130,6 @@ namespace QuickMedia { return true; } - PluginResult MangatownChaptersPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) { - result_tabs.push_back(Tab{create_body(), std::make_unique<MangatownImagesPage>(program, content_title, title, url), nullptr}); - return PluginResult::OK; - } - ImageResult MangatownImagesPage::get_number_of_images(int &num_images) { num_images = 0; ImageResult image_result = get_image_urls_for_chapter(url); diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index fa4e94f..b6a6488 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -184,7 +184,6 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - body->draw_thumbnails = true; result_tabs.push_back(Tab{std::move(body), std::make_unique<NyaaSiSearchPage>(program, strip(title), url), create_search_bar("Search...", 200)}); return PluginResult::OK; } @@ -372,7 +371,6 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - body->draw_thumbnails = true; result_tabs.push_back(Tab{std::move(body), std::make_unique<NyaaSiTorrentPage>(program), nullptr}); return PluginResult::OK; } |