From f30b6fdf5c40a703b5a8d6fb2a21002377ec9067 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2024 20:41:53 +0200 Subject: Reduce local-anime/local-manga disk access for speed up on mechanical harddrives, add local_anime.recursive option to make local-anime much faster when local-anime directory is a downloads directory --- src/plugins/LocalAnime.cpp | 55 ++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/plugins/LocalAnime.cpp') diff --git a/src/plugins/LocalAnime.cpp b/src/plugins/LocalAnime.cpp index c906b9b..59e52ad 100644 --- a/src/plugins/LocalAnime.cpp +++ b/src/plugins/LocalAnime.cpp @@ -190,7 +190,7 @@ namespace QuickMedia { static std::vector get_episodes_in_directory(const Path &directory) { std::vector episodes; - for_files_in_dir_sort_name(directory, [&episodes](const Path &filepath, FileType file_type) -> bool { + for_files_in_dir_sort_name(directory, [&episodes](const Path &filepath, FileType file_type, time_t) -> bool { if(file_type != FileType::REGULAR || !is_video_ext(filepath.ext())) return true; @@ -206,21 +206,28 @@ namespace QuickMedia { static std::vector get_episodes_or_seasons_in_directory(const Path &directory) { std::vector anime_items; - auto callback = [&](const Path &filepath, FileType file_type) -> bool { - time_t modified_time_seconds; - if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &modified_time_seconds)) - return true; - + auto callback = [&](const Path &filepath, FileType file_type, time_t last_modified_seconds) -> bool { if(file_type == FileType::REGULAR) { - if(is_video_ext(filepath.ext())) - anime_items.push_back(LocalAnimeEpisode{ filepath, modified_time_seconds }); + if(is_video_ext(filepath.ext())) { + if(last_modified_seconds == 0) { + if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &last_modified_seconds)) + return true; + } + + anime_items.push_back(LocalAnimeEpisode{ filepath, last_modified_seconds }); + } return true; } + if(last_modified_seconds == 0) { + if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &last_modified_seconds)) + return true; + } + LocalAnimeSeason season; season.name = filepath.filename(); season.episodes = get_episodes_in_directory(filepath); - season.modified_time_seconds = modified_time_seconds; + season.modified_time_seconds = last_modified_seconds; if(season.episodes.empty()) return true; @@ -236,23 +243,33 @@ namespace QuickMedia { return anime_items; } - std::vector get_anime_in_directory(const Path &directory) { + std::vector get_anime_in_directory(const Path &directory, bool recursive) { std::vector anime_items; - auto callback = [&anime_items](const Path &filepath, FileType file_type) -> bool { - time_t modified_time_seconds; - if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &modified_time_seconds)) - return true; - + auto callback = [&anime_items, recursive](const Path &filepath, FileType file_type, time_t last_modified_seconds) -> bool { if(file_type == FileType::REGULAR) { - if(is_video_ext(filepath.ext())) - anime_items.push_back(LocalAnimeEpisode{ filepath, modified_time_seconds }); + if(is_video_ext(filepath.ext())) { + if(last_modified_seconds == 0) { + if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &last_modified_seconds)) + return true; + } + + anime_items.push_back(LocalAnimeEpisode{ filepath, last_modified_seconds }); + } return true; } + + if(!recursive) + return true; + if(last_modified_seconds == 0) { + if(!file_get_last_modified_time_seconds(filepath.data.c_str(), &last_modified_seconds)) + return true; + } + LocalAnime anime; anime.name = filepath.filename(); anime.items = get_episodes_or_seasons_in_directory(filepath); - anime.modified_time_seconds = modified_time_seconds; + anime.modified_time_seconds = last_modified_seconds; if(anime.items.empty()) return true; @@ -352,7 +369,7 @@ namespace QuickMedia { PluginResult LocalAnimeSearchPage::lazy_fetch(BodyItems &result_items) { if(fetch_home_page) { fetch_home_page = false; - anime_items = get_anime_in_directory(get_config().local_anime.directory); + anime_items = get_anime_in_directory(get_config().local_anime.directory, get_config().local_anime.recursive); } std::unordered_map watch_progress = get_watch_progress_for_plugin("local-anime"); -- cgit v1.2.3