From 3f6c97bda7a40df92a85726696b6e291614aea0a Mon Sep 17 00:00:00 2001 From: zvon Date: Sat, 18 Jan 2020 22:56:47 +0100 Subject: [PATCH] TV_Rename: slight refactor and formatting --- tv_rename.cpp | 45 ++++++++++++++++++++++----------------------- tv_rename.hpp | 8 ++++---- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tv_rename.cpp b/tv_rename.cpp index 4f1fb49..89aa151 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -131,24 +131,23 @@ std::vector< string > getEpisodeNames( const string &id, const string &season, episodes.resize( epdata.size() ); for ( auto &x : epdata ) { if ( x["episodeName"].is_string() ) { - if ( dvd ) { - size_t index = x["dvdEpisodeNumber"].get< size_t >(); - if ( index > episodes.size() ) - episodes.resize( index ); - index--; - episodes[index] = - toString( x["episodeName"].get< std::string >() ); - } else { - size_t index = x["airedEpisodeNumber"].get< size_t >(); - if ( index > episodes.size() ) - episodes.resize( index ); - index--; - episodes[index] = - toString( x["episodeName"].get< std::string >() ); - // some eps have whitespace at the end - while ( isspace( episodes[index].back() ) ) - episodes[index].pop_back(); - } + size_t index = -1; + if ( dvd ) + index = x["dvdEpisodeNumber"].get< size_t >(); + else + index = x["airedEpisodeNumber"].get< size_t >(); + + if ( index == static_cast( -1 ) ) + continue; + + if ( index > episodes.size() ) + episodes.resize( index ); + index--; + episodes[index] = + toString( x["episodeName"].get< std::string >() ); + // some eps have whitespace at the end + while ( isspace( episodes[index].back() ) ) + episodes[index].pop_back(); } } } else { @@ -280,8 +279,8 @@ bool authenticate( const std::string &api_key ) { return true; } -void singleSeason( const string &path, const string &show, int season, string id, - const string &language, const string &pattern, +void singleSeason( const string &path, const string &show, int season, + string id, const string &language, const string &pattern, const bool &linux, const bool &trust, std::map< int, string > *files_ptr, bool print, bool dvd ) { #ifndef GUI @@ -306,7 +305,7 @@ void singleSeason( const string &path, const string &show, int season, string id auto renamed_files = getRenamedFiles( show, season, id, language, pattern, linux, *files_ptr, dvd ); - if( renamed_files.empty() ) + if ( renamed_files.empty() ) goto end; if ( print || !trust ) { @@ -344,8 +343,8 @@ end: } } -void singleSeason( const string &path, const string &show, int season, string id, - const string &language, const string &pattern, +void singleSeason( const string &path, const string &show, int season, + string id, const string &language, const string &pattern, const size_t &flags, std::map< int, string > *files_ptr, bool print ) { singleSeason( path, show, season, id, language, pattern, flags & TV_LINUX, diff --git a/tv_rename.hpp b/tv_rename.hpp index 1036830..d244b3e 100644 --- a/tv_rename.hpp +++ b/tv_rename.hpp @@ -25,14 +25,14 @@ using char_t = char; #endif -void singleSeason( const string &path, const string &show, int season, string id, - const string &language, const string &pattern, +void singleSeason( const string &path, const string &show, int season, + string id, const string &language, const string &pattern, const bool &linux, const bool &trust, std::map< int, string > *files_ptr = nullptr, bool print = true, bool dvd = false ); -void singleSeason( const string &path, const string &show, int season, string id, - const string &language, const string &pattern, +void singleSeason( const string &path, const string &show, int season, + string id, const string &language, const string &pattern, const size_t &flags, std::map< int, string > *files_ptr = nullptr, bool print = true );