From ce3f65d72ffbfb6eba4fa2dea091d47e28408e55 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 10 Sep 2021 17:42:26 +0200 Subject: Some manga on mangakatana have merged chapters. Only show the merged ones --- src/QuickMedia.cpp | 89 +++++++++++++++++++++---------------------------- src/plugins/Youtube.cpp | 2 +- 2 files changed, 39 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index aef1073..ac56f5d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -784,7 +784,7 @@ namespace QuickMedia { {"//div[id='single_book']//div[class='*summary*']", "text"} }) .authors_handler({{"//div[id='single_book']//a[class='author']", "text", "href", "/author/"}}) - .list_chapters_handler("//div[class='chapters']//div[class='chapter']//a", "text", "href", "/manga/") + .list_chapters_handler("//div[class='chapters']//div[class='chapter']//a[0]", "text", "href", "/manga/") .list_chapters_uploaded_time_handler("//div[class='chapters']//div[class='update_time']", "text", nullptr) .list_page_images_custom_handler([](const std::string &html_source) { std::vector urls; @@ -3530,6 +3530,34 @@ namespace QuickMedia { } } + void Program::save_manga_progress(MangaImagesPage *images_page, Json::Value &json_chapters, Json::Value &json_chapter, int &latest_read) { + image_index = std::max(0, std::min(image_index, num_manga_pages)); + + json_chapters = content_storage_json["chapters"]; + latest_read = image_index + 1; + if(json_chapters.isObject()) { + json_chapter = json_chapters[images_page->get_chapter_name()]; + if(json_chapter.isObject()) { + const Json::Value ¤t = json_chapter["current"]; + if(current.isNumeric()) + latest_read = std::max(latest_read, current.asInt()); + } else { + json_chapter = Json::Value(Json::objectValue); + } + } else { + json_chapters = Json::Value(Json::objectValue); + json_chapter = Json::Value(Json::objectValue); + } + json_chapter["current"] = std::min(latest_read, num_manga_pages); + json_chapter["total"] = num_manga_pages; + json_chapters[images_page->get_chapter_name()] = json_chapter; + content_storage_json["chapters"] = json_chapters; + + if(!save_json_to_file_atomic(content_storage_file, content_storage_json)) { + show_notification("QuickMedia", "Failed to save manga progress", Urgency::CRITICAL); + } + } + int Program::image_page(MangaImagesPage *images_page, Body *chapters_body) { int page_navigation = 0; image_download_cancel = false; @@ -3558,7 +3586,11 @@ namespace QuickMedia { if(current_page != PageType::IMAGES || !window.isOpen()) return 0; - image_index = std::max(0, std::min(image_index, num_manga_pages)); + // TODO: Dont do this every time we change page? + Json::Value json_chapters; + Json::Value json_chapter; + int latest_read; + save_manga_progress(images_page, json_chapters, json_chapter, latest_read); if(image_index < num_manga_pages) { sf::String error_msg; @@ -3572,30 +3604,6 @@ namespace QuickMedia { error_message.setString("End of " + images_page->get_chapter_name()); } - // TODO: Dont do this every time we change page? - Json::Value &json_chapters = content_storage_json["chapters"]; - Json::Value json_chapter; - int latest_read = image_index + 1; - if(json_chapters.isObject()) { - json_chapter = json_chapters[images_page->get_chapter_name()]; - if(json_chapter.isObject()) { - const Json::Value ¤t = json_chapter["current"]; - if(current.isNumeric()) - latest_read = std::max(latest_read, current.asInt()); - } else { - json_chapter = Json::Value(Json::objectValue); - } - } else { - json_chapters = Json::Value(Json::objectValue); - json_chapter = Json::Value(Json::objectValue); - } - json_chapter["current"] = std::min(latest_read, num_manga_pages); - json_chapter["total"] = num_manga_pages; - json_chapters[images_page->get_chapter_name()] = json_chapter; - if(!save_json_to_file_atomic(content_storage_file, content_storage_json)) { - show_notification("QuickMedia", "Failed to save manga progress", Urgency::CRITICAL); - } - bool error = !error_message.getString().isEmpty(); bool redraw = true; @@ -3759,34 +3767,12 @@ namespace QuickMedia { if(current_page != PageType::IMAGES_CONTINUOUS || !window.isOpen()) return; - image_index = std::max(0, std::min(image_index, num_manga_pages)); - - Json::Value &json_chapters = content_storage_json["chapters"]; + Json::Value json_chapters; Json::Value json_chapter; - int latest_read = 1 + image_index; - if(json_chapters.isObject()) { - json_chapter = json_chapters[images_page->get_chapter_name()]; - if(json_chapter.isObject()) { - const Json::Value ¤t = json_chapter["current"]; - if(current.isNumeric()) - latest_read = std::max(latest_read, current.asInt()); - } else { - json_chapter = Json::Value(Json::objectValue); - } - } else { - json_chapters = Json::Value(Json::objectValue); - json_chapter = Json::Value(Json::objectValue); - } - + int latest_read; + save_manga_progress(images_page, json_chapters, json_chapter, latest_read); ImageViewer image_viewer(&window, num_manga_pages, images_page->manga_name, images_page->get_chapter_name(), image_index, content_cache_dir, &fit_image_to_window); - json_chapter["current"] = std::min(latest_read, image_viewer.get_num_pages()); - json_chapter["total"] = image_viewer.get_num_pages(); - json_chapters[images_page->get_chapter_name()] = json_chapter; - if(!save_json_to_file_atomic(content_storage_file, content_storage_json)) { - show_notification("QuickMedia", "Failed to save manga progress", Urgency::CRITICAL); - } - idle_active_handler(); while(current_page == PageType::IMAGES_CONTINUOUS && window.isOpen()) { @@ -3813,6 +3799,7 @@ namespace QuickMedia { latest_read = focused_page; json_chapter["current"] = latest_read; json_chapters[images_page->get_chapter_name()] = json_chapter; + content_storage_json["chapters"] = json_chapters; if(!save_json_to_file_atomic(content_storage_file, content_storage_json)) { show_notification("QuickMedia", "Failed to save manga progress", Urgency::CRITICAL); } diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index c5a6d04..a258325 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -157,7 +157,7 @@ namespace QuickMedia { static std::vector get_cookies() { std::lock_guard lock(cookies_mutex); if(cookies_filepath.empty()) { - YoutubeSignatureDecryptor::get_instance(); + //YoutubeSignatureDecryptor::get_instance(); cpn.resize(16); generate_random_characters(cpn.data(), cpn.size(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_", 64); -- cgit v1.2.3