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 --- depends/html-search | 2 +- include/QuickMedia.hpp | 1 + src/QuickMedia.cpp | 89 +++++++++++++++++++++---------------------------- src/plugins/Youtube.cpp | 2 +- 4 files changed, 41 insertions(+), 53 deletions(-) diff --git a/depends/html-search b/depends/html-search index 95c189f..2f5dd50 160000 --- a/depends/html-search +++ b/depends/html-search @@ -1 +1 @@ -Subproject commit 95c189f7445e6deca85130b7b8fa25dc76fabe12 +Subproject commit 2f5dd509c4a82873b4bf626e55d9c6624ec43dfc diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index db3dd09..9ca86fb 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -119,6 +119,7 @@ namespace QuickMedia { void video_page_download_video(const std::string &url, sf::WindowHandle video_player_window = None); bool video_download_if_non_streamable(std::string &video_url, std::string &audio_url, bool &is_audio_only, bool &has_embedded_audio, PageType previous_page); void video_content_page(Page *parent_page, VideoPage *video_page, std::string video_title, bool download_if_streaming_fails, Body *parent_body, int play_index, int *parent_body_page = nullptr, const std::string &parent_page_search = ""); + void save_manga_progress(MangaImagesPage *images_page, Json::Value &json_chapters, Json::Value &json_chapter, int &latest_read); // Returns -1 to go to previous chapter, 0 to stay on same chapter and 1 to go to next chapter int image_page(MangaImagesPage *images_page, Body *chapters_body); void image_continuous_page(MangaImagesPage *images_page); 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