Use new functions, slight clean up
This commit is contained in:
parent
ddcb8e3215
commit
c2fd4cd106
@ -26,10 +26,16 @@ std::map<std::string, std::string> languages{
|
|||||||
{"sl", "Slovenian"}, {"hr", "Croatian"}, {"ko","Korea"}
|
{"sl", "Slovenian"}, {"hr", "Croatian"}, {"ko","Korea"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void printLangs() {
|
||||||
|
for( const auto &x : languages ) {
|
||||||
|
std::cout << x.first << " - " << x.second << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parseSeasonNumbers(std::set<int> &seasons_num, const char *argument) {
|
void parseSeasonNumbers(std::set<int> &seasons_num, const char *argument) {
|
||||||
size_t pos{0};
|
size_t pos{0};
|
||||||
|
|
||||||
while((argument[pos] < '0' || argument[pos] > '9') && argument[pos] != ' ' && argument[pos] != '\0')
|
while(!isdigit(argument[pos]) && argument[pos] != '\0')
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
if( argument[pos] == '\0' ) {
|
if( argument[pos] == '\0' ) {
|
||||||
@ -75,8 +81,8 @@ bool parseCommandLine(std::string &show, std::set<int> &seasons_num, std::string
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
path = std::string(optarg);
|
path = std::string(optarg);
|
||||||
if( !FSLib::isDirectory(path) )
|
// if path provided, assume it's correct
|
||||||
change_dir = true;
|
change_dir = false;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
trust = true;
|
trust = true;
|
||||||
@ -89,13 +95,12 @@ bool parseCommandLine(std::string &show, std::set<int> &seasons_num, std::string
|
|||||||
language = optarg;
|
language = optarg;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Invalid language choice" << std::endl;
|
std::cerr << "Invalid language choice" << std::endl;
|
||||||
|
printLangs();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
for( const auto &x : languages ) {
|
printLangs();
|
||||||
std::cout << x.first << " - " << x.second << std::endl;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
case 'h':
|
case 'h':
|
||||||
printHelp();
|
printHelp();
|
||||||
@ -117,6 +122,9 @@ int main(int argc, char** argv) {
|
|||||||
if( !parseCommandLine(show, seasons_num, path, change_dir, argc, argv) )
|
if( !parseCommandLine(show, seasons_num, path, change_dir, argc, argv) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if( !FSLib::isDirectory(path) )
|
||||||
|
change_dir = true;
|
||||||
|
|
||||||
while( change_dir ) {
|
while( change_dir ) {
|
||||||
if( !FSLib::isDirectory(path) ) {
|
if( !FSLib::isDirectory(path) ) {
|
||||||
std::cout << "This directory doesn't exist, please insert a correct path: " << std::endl;
|
std::cout << "This directory doesn't exist, please insert a correct path: " << std::endl;
|
||||||
@ -163,8 +171,7 @@ int main(int argc, char** argv) {
|
|||||||
void singleSeason( const std::string &path, const std::string &show, int season, std::string url) {
|
void singleSeason( const std::string &path, const std::string &show, int season, std::string url) {
|
||||||
if( url.empty() )
|
if( url.empty() )
|
||||||
url = getDefUrl(show, language, c);
|
url = getDefUrl(show, language, c);
|
||||||
url += "/seasons/";
|
url += "/seasons/" + std::to_string(season);
|
||||||
url += std::to_string(season);
|
|
||||||
//get source code of season's page
|
//get source code of season's page
|
||||||
auto season_code = c.execute(url);
|
auto season_code = c.execute(url);
|
||||||
//remove newlines
|
//remove newlines
|
||||||
@ -215,9 +222,9 @@ void singleSeason( const std::string &path, const std::string &show, int season,
|
|||||||
dir = x.substr(0, last);
|
dir = x.substr(0, last);
|
||||||
}
|
}
|
||||||
unsigned long num;
|
unsigned long num;
|
||||||
try {
|
if( searchSpecificSeason(x.c_str(), pos, std::to_string(season)) ) {
|
||||||
num = std::stoi(std::regex_replace(name, std::regex(".*[sS][0]{0,2000}" + std::to_string(season) + "[eE]([0-9]{1,2000}).*"), "$1"));
|
num = atoi(x.c_str()+pos);
|
||||||
} catch (std::exception &e) {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
num -= 1;
|
num -= 1;
|
||||||
@ -234,10 +241,8 @@ void singleSeason( const std::string &path, const std::string &show, int season,
|
|||||||
renamed_episodes[num] = name;
|
renamed_episodes[num] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto orig = files.begin();
|
|
||||||
for(auto renamed = renamed_files.begin(); renamed != renamed_files.end(); ++renamed) {
|
for(auto renamed = renamed_files.begin(); renamed != renamed_files.end(); ++renamed) {
|
||||||
std::cout << *renamed << std::endl;
|
std::cout << *renamed << std::endl;
|
||||||
++orig;
|
|
||||||
}
|
}
|
||||||
if( !trust ) {
|
if( !trust ) {
|
||||||
std::cout << "Does this seem ok? (y/n) ";
|
std::cout << "Does this seem ok? (y/n) ";
|
||||||
@ -248,7 +253,7 @@ void singleSeason( const std::string &path, const std::string &show, int season,
|
|||||||
if( response[0] != 'y' && response[0] != 'Y' )
|
if( response[0] != 'y' && response[0] != 'Y' )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
orig = files.begin();
|
auto orig = files.begin();
|
||||||
for(auto renamed = renamed_files.begin(); renamed != renamed_files.end(); ++renamed) {
|
for(auto renamed = renamed_files.begin(); renamed != renamed_files.end(); ++renamed) {
|
||||||
FSLib::rename(*orig, *renamed);
|
FSLib::rename(*orig, *renamed);
|
||||||
++orig;
|
++orig;
|
||||||
|
Loading…
Reference in New Issue
Block a user