2019-01-19 12:40:10 +00:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "filesystem.hpp"
|
|
|
|
#include "functions.hpp"
|
|
|
|
#include "tv_rename.hpp"
|
|
|
|
|
2019-01-23 13:08:40 +00:00
|
|
|
int parseCommandLine(std::string &show, std::set<int> &seasons_num, std::string &path, bool &change_dir, std::string &language, std::string &pattern, bool &linux, bool &trust, int argc, char **argv) {
|
2019-01-19 12:40:10 +00:00
|
|
|
static struct option long_options[] = {
|
|
|
|
{"show", required_argument, 0, 's' },
|
|
|
|
{"season", required_argument, 0, 'n' },
|
|
|
|
{"correct-path", no_argument, 0, 'c' },
|
|
|
|
{"show-path", required_argument, 0, 'p' },
|
|
|
|
{"trust", no_argument, 0, 't' },
|
|
|
|
{"linux", no_argument, 0, 'x' },
|
|
|
|
{"lang", required_argument, 0, 'l' },
|
|
|
|
{"print-langs", no_argument, 0, '0' },
|
2019-01-23 13:08:40 +00:00
|
|
|
{"name-pattern", required_argument, 0, '1' },
|
2019-01-19 12:40:10 +00:00
|
|
|
{"help", no_argument, 0, 'h' }
|
|
|
|
};
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int option_index{0};
|
2019-01-23 13:08:40 +00:00
|
|
|
auto c = getopt_long(argc, argv, "s:n:cp:txl:01:h", long_options, &option_index);
|
2019-01-19 12:40:10 +00:00
|
|
|
if( c == -1 )
|
|
|
|
break;
|
|
|
|
switch(c) {
|
|
|
|
case 's':
|
|
|
|
show = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
parseSeasonNumbers(seasons_num, optarg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
change_dir = false;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
path = std::string(optarg);
|
|
|
|
// if path provided, assume it's correct
|
|
|
|
change_dir = false;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
trust = true;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
linux = true;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if( findLanguage(optarg) ) {
|
|
|
|
language = optarg;
|
|
|
|
} else {
|
|
|
|
std::cerr << "Invalid language choice" << std::endl;
|
|
|
|
printLangs();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
printLangs();
|
|
|
|
return 1;
|
|
|
|
case 'h':
|
|
|
|
printHelp();
|
|
|
|
return 1;
|
2019-01-23 13:08:40 +00:00
|
|
|
case '1':
|
|
|
|
pattern = optarg;
|
|
|
|
break;
|
2019-01-19 12:40:10 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
std::string show{};
|
|
|
|
std::set<int> seasons_num;
|
|
|
|
std::string path{"."};
|
|
|
|
bool change_dir{true};
|
|
|
|
std::string language{"en"};
|
|
|
|
bool linux{false};
|
|
|
|
bool trust{false};
|
2019-01-23 13:08:40 +00:00
|
|
|
std::string pattern{"%file - %epname"};
|
2019-01-19 12:40:10 +00:00
|
|
|
Curl c;
|
|
|
|
|
|
|
|
{
|
2019-01-23 13:08:40 +00:00
|
|
|
auto tmp = parseCommandLine(show, seasons_num, path, change_dir, language, pattern, linux, trust, argc, argv);
|
2019-01-19 12:40:10 +00:00
|
|
|
if( tmp == -1 )
|
|
|
|
return 1;
|
|
|
|
else if ( tmp == 1 )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !FSLib::isDirectory(path) )
|
|
|
|
change_dir = true;
|
|
|
|
|
|
|
|
while( change_dir ) {
|
|
|
|
if( !FSLib::isDirectory(path) ) {
|
|
|
|
std::cout << "This directory doesn't exist, please insert a correct path: " << std::endl;
|
|
|
|
std::getline(std::cin, path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::cout << "Is this the right directory? " << FSLib::canonical(path) << std::endl;
|
|
|
|
std::string response;
|
|
|
|
std::cin >> response;
|
|
|
|
std::cin.ignore(1,'\n');
|
|
|
|
std::cin.clear();
|
|
|
|
if ( response[0] == 'y' || response[0] == 'Y' ) {
|
|
|
|
change_dir = false;
|
|
|
|
} else {
|
|
|
|
std::cout << "Insert correct path:" << std::endl;
|
|
|
|
std::getline(std::cin, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( show.empty() ) {
|
|
|
|
auto pos = show.find_last_of('/');
|
|
|
|
if( pos != std::string::npos )
|
|
|
|
show = show.substr(++pos);
|
|
|
|
std::cout << "Is this the right show name? " << show << std::endl;
|
|
|
|
std::string response;
|
|
|
|
std::cin >> response;
|
|
|
|
std::cin.ignore(1, '\n');
|
|
|
|
std::cin.clear();
|
|
|
|
if( response[0] != 'y' && response[0] != 'Y' ) {
|
|
|
|
std::cout << "Insert the correct show name: " << std::endl;
|
|
|
|
std::getline(std::cin, show);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( seasons_num.size() == 1 ) {
|
2019-01-23 13:08:40 +00:00
|
|
|
singleSeason(path, show, *seasons_num.begin(), "", language, pattern, linux, trust, c);
|
2019-01-19 12:40:10 +00:00
|
|
|
} else if ( seasons_num.size() != 0 ) {
|
2019-01-23 13:08:40 +00:00
|
|
|
multipleSeasons(path, show, seasons_num, language, pattern, linux, trust, c);
|
2019-01-19 12:40:10 +00:00
|
|
|
} else {
|
2019-01-23 13:08:40 +00:00
|
|
|
allSeasons(path, show, language, pattern, linux, trust, c);
|
2019-01-19 12:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|