From 769f8508a40bfdefd9a9a6e5a928e2a7ff81e169 Mon Sep 17 00:00:00 2001 From: zvon Date: Thu, 17 Jan 2019 17:23:15 +0100 Subject: [PATCH] Fewer filesystem operations when using multipleSeasons --- functions.cpp | 16 ++++++++++++++++ functions.hpp | 1 + tv_rename.cpp | 13 ++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/functions.cpp b/functions.cpp index 30b96b7..ac6c1da 100644 --- a/functions.cpp +++ b/functions.cpp @@ -104,6 +104,22 @@ void findSeason(std::set &files, int season, const std::string &pat } } +void findSeasons(std::map> &seasons, const std::string &path, const std::set &season_numbers) { + size_t season_pos{std::string::npos}; // season_pos - position of first digit of the season + for( const auto p: FSLib::Directory(path) ) { + if(FSLib::isDirectory(path + "/" + p)) { + iterateFS(seasons, path + "/" + p); + continue; + } + + if( searchSeason(p, season_pos) ) { + auto num = atoi(p+season_pos); + if( season_numbers.find(num) != season_numbers.end() ) + seasons[num].insert(path + "/" + p); + } + } +} + void iterateFS(std::map> &seasons, const std::string &path) { size_t season_pos{std::string::npos}; // season_pos - position of first digit of the season for( const auto p: FSLib::Directory(path) ) { diff --git a/functions.hpp b/functions.hpp index 36affef..f09a130 100644 --- a/functions.hpp +++ b/functions.hpp @@ -17,6 +17,7 @@ private: std::string getDefUrl( std::string show, const std::string &language, Curl &c ); void findSeason(std::set &files, int season, const std::string &path); +void findSeasons(std::map> &seasons, const std::string &path, const std::set &season_numbers); void iterateFS(std::map> &seasons, const std::string &path); void iterateFS(std::set &seasons, const std::string &path); void printHelp(); diff --git a/tv_rename.cpp b/tv_rename.cpp index a041dd5..a40ac0c 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -303,13 +303,6 @@ void singleSeason( const std::string &path, const std::string &show, int season, } } -void multipleSeasons( const std::string &path, const std::string &show, const std::set seasons, const std::string &language, const bool &linux, const bool &trust, Curl &c) { - auto url = getDefUrl(show, language, c); - for( const auto &x : seasons ) { - singleSeason( path, show, x, url, language, linux, trust, c); - } -} - void multipleSeasons( const std::string &path, const std::string &show, const std::map> &seasons, const std::string &language, const bool &linux, const bool &trust, Curl &c) { auto url = getDefUrl(show, language, c); for( const auto &x : seasons ) { @@ -317,6 +310,12 @@ void multipleSeasons( const std::string &path, const std::string &show, const st } } +void multipleSeasons( const std::string &path, const std::string &show, const std::set seasons, const std::string &language, const bool &linux, const bool &trust, Curl &c) { + std::map> season_map; + findSeasons(season_map, path, seasons); + multipleSeasons(path, show, season_map, language, linux, trust, c); +} + void allSeasons( const std::string &path, const std::string &show, const std::string &language, const bool &linux, const bool &trust, Curl &c) { std::map> seasons; //get all season number from this directory and subdirectories