Path doesn't require '-p' to be specified, possible to specify file instead of directory
This commit is contained in:
parent
6714d3f437
commit
d2ae8ab94c
@ -128,7 +128,7 @@ bool searchSpecificSeason( const char_t *const path, size_t &ep_pos,
|
|||||||
cur_pos++;
|
cur_pos++;
|
||||||
while ( path[cur_pos] == '0' )
|
while ( path[cur_pos] == '0' )
|
||||||
cur_pos++;
|
cur_pos++;
|
||||||
// if season number is 0, move back because previous while skipped it
|
// if season number is 0, move back because previous loop skipped it
|
||||||
if( number == TEXT("0") )
|
if( number == TEXT("0") )
|
||||||
cur_pos--;
|
cur_pos--;
|
||||||
// make sure season's number is the same as provided in argument
|
// make sure season's number is the same as provided in argument
|
||||||
@ -283,60 +283,58 @@ string getDefUrl( string &show, const string &language, Curl &c ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printHelp() {
|
void printHelp() {
|
||||||
cout << "usage: tv_rename [--help] [--show show name] [--season season "
|
cout << "Usage:" << std::endl;
|
||||||
"number]"
|
cout << " tv_rename [options] [path]" << std::endl << std::endl;
|
||||||
|
cout << " -h, --help show this help message and exit"
|
||||||
|
<< std::endl << std::endl;
|
||||||
|
cout << " path can be either a file or a directory, if it's a directory"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout
|
cout << " all files in it and its subdirectories will be renamed"
|
||||||
<< " [--correct-path] [--show-path show path] [--trust]"
|
<< std::endl << std::endl;
|
||||||
<< std::endl;
|
cout << "OPTIONS" << std::endl;
|
||||||
cout << " [--linux] [--lang language] [--print-langs]"
|
cout << " -s, --show <string> TV show from which you want the";
|
||||||
|
cout << " episode names" << std::endl;
|
||||||
|
cout << " -n, --season <numbers> Season number/s (if multiple seasons,"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << std::endl
|
cout << " must be seperated by one space)"
|
||||||
<< "Rename TV episodes" << std::endl
|
<< " or 'all'" << std::endl;
|
||||||
<< std::endl
|
cout << " for all seasons in selected directory"
|
||||||
<< "optional arguments:" << std::endl;
|
|
||||||
cout << " -h, --help\t\tshow this help message and exit" << std::endl;
|
|
||||||
cout << " --show show name, -s show name" << std::endl;
|
|
||||||
cout << "\t\t\tTV show from which you want episode names (needs to be"
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << "\t\t\tin quotation marks if it has more than one word)"
|
cout << " --name-pattern <string> Pattern to which change the file name."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << " --season season number, -n season number" << std::endl;
|
cout << " Possible sequences are:" << std::endl;
|
||||||
cout << "\t\t\tSeason number/s (if multiple seasons, put them in"
|
cout << " %filename - original filename"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << "\t\t\tquotation marks and seperate by one space)" << std::endl;
|
cout << " (without filetype"
|
||||||
cout << "\t\t\tor 'all' for all seasons in selected subdirectory"
|
<< " extension)" << std::endl;
|
||||||
|
cout << " %show - show name from thetvdb"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << " --show-path show path, -p show path" << std::endl;
|
cout << " %epname - episode name from thetvdb"
|
||||||
cout << "\t\t\tPath of the directory with episodes" << std::endl;
|
|
||||||
cout << " --correct-path, -c\tThis is the correct path, stop asking me!"
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << " --name-pattern pattern" << std::endl;
|
cout << " %season - season number"
|
||||||
cout << "\t\t\tPattern to which change the file name. Possible sequences "
|
|
||||||
"are:"
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << "\t\t\t\t%filename - original filename (without filetype extension)"
|
cout << " it's possible to specify leading"
|
||||||
|
<< " 0 like this:" << std::endl;
|
||||||
|
cout << " %2season (number means how many"
|
||||||
|
<< " zeros)" << std::endl;
|
||||||
|
cout << " %episode - episode number"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << "\t\t\t\t%show - show name from thetvdb" << std::endl;
|
cout << " it's possible to specify leading"
|
||||||
cout << "\t\t\t\t%epname - episode name from thetvdb" << std::endl;
|
<< " 0 like this:" << std::endl;
|
||||||
cout << "\t\t\t\t%season - season number" << std::endl;
|
cout << " %2episode (number means how many"
|
||||||
cout << "\t\t\t\ttpossible to specify leading 0 like this: %2season "
|
<< " zeros)" << std::endl;
|
||||||
"(number means how many leading zeros)"
|
cout << " Default pattern is \"$filename -"
|
||||||
|
<< " $epname\"" << std::endl;
|
||||||
|
cout << " -c, --correct-path This is the correct path,"
|
||||||
|
<< " stop asking me!" << std::endl;
|
||||||
|
cout << " -t, --trust Don't ask whether the names are correct"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cout << "\t\t\t\t%episode - episode number" << std::endl;
|
cout << " -x, --linux Don't replace characters characters"
|
||||||
cout << "\t\t\t\t\tpossible to specify leading 0 like this: %2episode "
|
<< " that are" << std::endl;
|
||||||
"(number means how many leading zeros)"
|
cout << " illegal in Windows" << std::endl;
|
||||||
<< std::endl;
|
cout << " -l, --lang <string> Select which language the episode"
|
||||||
cout << "\t\t\tDefault pattern is \"$filename - $epname\"" << std::endl;
|
<< " names shoud be in" << std::endl;
|
||||||
cout << " --trust, -t\t\tDon't ask whether the names are correct"
|
cout << " --print-langs Pring available languages" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
cout << " --linux, -x\t\tDon't replace characters characters that are "
|
|
||||||
"illegal in Windows"
|
|
||||||
<< std::endl;
|
|
||||||
cout << " --lang language, -l language" << std::endl;
|
|
||||||
cout << "\t\t\tSelect which language the episode names shoud be in"
|
|
||||||
<< std::endl;
|
|
||||||
cout << " --print-langs\t\tPring available language" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse command line argument --seasons (e.g. '1 2 3 4 5')
|
// parse command line argument --seasons (e.g. '1 2 3 4 5')
|
||||||
|
47
main.cpp
47
main.cpp
@ -96,16 +96,16 @@ int handleArgument( char_t c, string &show, std::set< int > &seasons_num,
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
string getOptions( const char_t *option ) {
|
string getOptions( const char_t *option ) {
|
||||||
if ( option[1] != '-' )
|
if ( option[0] != '-' )
|
||||||
|
return L"";
|
||||||
|
else if ( option[1] != '-' )
|
||||||
return option + 1;
|
return option + 1;
|
||||||
if ( !wcscmp( option, L"--show" ) )
|
else if ( !wcscmp( option, L"--show" ) )
|
||||||
return L"s";
|
return L"s";
|
||||||
else if ( !wcscmp( option, L"--season" ) )
|
else if ( !wcscmp( option, L"--season" ) )
|
||||||
return L"n";
|
return L"n";
|
||||||
else if ( !wcscmp( option, L"--correct-path" ) )
|
else if ( !wcscmp( option, L"--correct-path" ) )
|
||||||
return L"c";
|
return L"c";
|
||||||
else if ( !wcscmp( option, L"--show-path" ) )
|
|
||||||
return L"p";
|
|
||||||
else if ( !wcscmp( option, L"--trust" ) )
|
else if ( !wcscmp( option, L"--trust" ) )
|
||||||
return L"t";
|
return L"t";
|
||||||
else if ( !wcscmp( option, L"--linux" ) )
|
else if ( !wcscmp( option, L"--linux" ) )
|
||||||
@ -126,9 +126,16 @@ int parseCommandLine( string &show, std::set< int > &seasons_num, string &path,
|
|||||||
bool &change_dir, string &language, string &pattern,
|
bool &change_dir, string &language, string &pattern,
|
||||||
bool &linux, bool &trust, const int argc,
|
bool &linux, bool &trust, const int argc,
|
||||||
char_t **argv ) {
|
char_t **argv ) {
|
||||||
|
string options{};
|
||||||
|
char_t *optional;
|
||||||
for ( auto i = 1; i < argc; i++ ) {
|
for ( auto i = 1; i < argc; i++ ) {
|
||||||
auto options = getOptions( argv[i] );
|
options = getOptions( argv[i] );
|
||||||
char_t *optional = ( i < argc - 1 ) ? argv[i + 1] : nullptr;
|
if ( options == L"" ) {
|
||||||
|
options = L"p";
|
||||||
|
optional = argv[i];
|
||||||
|
} else {
|
||||||
|
optional = ( i < argc - 1 ) ? argv[i + 1] : nullptr;
|
||||||
|
}
|
||||||
for ( const auto &x : options ) {
|
for ( const auto &x : options ) {
|
||||||
auto res =
|
auto res =
|
||||||
handleArgument( x, show, seasons_num, change_dir, path, trust,
|
handleArgument( x, show, seasons_num, change_dir, path, trust,
|
||||||
@ -150,13 +157,13 @@ int parseCommandLine( string &show, std::set< int > &seasons_num, string &path,
|
|||||||
{ "show", required_argument, 0, 's' },
|
{ "show", required_argument, 0, 's' },
|
||||||
{ "season", required_argument, 0, 'n' },
|
{ "season", required_argument, 0, 'n' },
|
||||||
{ "correct-path", no_argument, 0, 'c' },
|
{ "correct-path", no_argument, 0, 'c' },
|
||||||
{ "show-path", required_argument, 0, 'p' },
|
|
||||||
{ "trust", no_argument, 0, 't' },
|
{ "trust", no_argument, 0, 't' },
|
||||||
{ "linux", no_argument, 0, 'x' },
|
{ "linux", no_argument, 0, 'x' },
|
||||||
{ "lang", required_argument, 0, 'l' },
|
{ "lang", required_argument, 0, 'l' },
|
||||||
{ "print-langs", no_argument, 0, '0' },
|
{ "print-langs", no_argument, 0, '0' },
|
||||||
{ "name-pattern", required_argument, 0, '1' },
|
{ "name-pattern", required_argument, 0, '1' },
|
||||||
{ "help", no_argument, 0, 'h' }
|
{ "help", no_argument, 0, 'h' },
|
||||||
|
{ 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int i{}; // this is useless, but needed for handleArgument
|
int i{}; // this is useless, but needed for handleArgument
|
||||||
@ -173,6 +180,12 @@ int parseCommandLine( string &show, std::set< int > &seasons_num, string &path,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( optind < argc ) {
|
||||||
|
path = string( argv[optind] );
|
||||||
|
// if path provided, assume it's correct
|
||||||
|
change_dir = false;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,8 +222,24 @@ int main
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !FSLib::isDirectory( path ) )
|
if ( !FSLib::isDirectory( path ) && FSLib::exists( path ) ) {
|
||||||
|
// specified file, not directory
|
||||||
|
auto *file_set = new std::set<string>;
|
||||||
|
file_set->insert( path );
|
||||||
|
size_t season_pos{};
|
||||||
|
if ( !searchSeason( path.c_str(), season_pos ) ) {
|
||||||
|
cerr << "Specified file does not conform to filename pattern, "
|
||||||
|
<< "cannot rename." << std::endl;
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
auto season = std::stoi( path.c_str() + season_pos );
|
||||||
|
singleSeason( path, show, season, TEXT(""), language, pattern,
|
||||||
|
linux, trust, c, file_set );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else if ( !FSLib::isDirectory( path ) ) {
|
||||||
change_dir = true;
|
change_dir = true;
|
||||||
|
}
|
||||||
|
|
||||||
while ( change_dir ) {
|
while ( change_dir ) {
|
||||||
if ( !FSLib::isDirectory( path ) ) {
|
if ( !FSLib::isDirectory( path ) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user