138 lines
4.4 KiB
C++
138 lines
4.4 KiB
C++
#include <getopt.h>
|
|
#include <iostream>
|
|
#include "filesystem.hpp"
|
|
#include "functions.hpp"
|
|
#include "tv_rename.hpp"
|
|
|
|
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) {
|
|
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' },
|
|
{"name-pattern", required_argument, 0, '1' },
|
|
{"help", no_argument, 0, 'h' }
|
|
};
|
|
|
|
while(1) {
|
|
int option_index{0};
|
|
auto c = getopt_long(argc, argv, "s:n:cp:txl:01:h", long_options, &option_index);
|
|
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;
|
|
case '1':
|
|
pattern = optarg;
|
|
break;
|
|
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};
|
|
std::string pattern{"%filename - %epname"};
|
|
Curl c;
|
|
|
|
{
|
|
auto tmp = parseCommandLine(show, seasons_num, path, change_dir, language, pattern, linux, trust, argc, argv);
|
|
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 ) {
|
|
singleSeason(path, show, *seasons_num.begin(), "", language, pattern, linux, trust, c);
|
|
} else if ( seasons_num.size() != 0 ) {
|
|
multipleSeasons(path, show, seasons_num, language, pattern, linux, trust, c);
|
|
} else {
|
|
allSeasons(path, show, language, pattern, linux, trust, c);
|
|
}
|
|
}
|
|
|