forked from markus/S_New4
976 lines
42 KiB
C++
976 lines
42 KiB
C++
#include "parameterManager.h"
|
|
|
|
void setPaths(Settings &settings)
|
|
{
|
|
//Path settings
|
|
std::string executablePathTo = getexepath();
|
|
|
|
executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) );
|
|
|
|
if(!dirExists(executablePathTo + "src" + settings.pathSymbol)) {
|
|
if(system(std::string("mkdir \"" + executablePathTo + "src" + settings.pathSymbol + "\"").c_str()) == 0)
|
|
std::cout << " => Erfolgreich Ordner 'src' erstellt." << std::endl;
|
|
else
|
|
std::cout << " => Error: Ordner '" << executablePathTo << "src' konnte nicht erstellt werden." << std::endl;
|
|
}
|
|
if(dirExists(executablePathTo + "src" + settings.pathSymbol))
|
|
executablePathTo+="src" + std::string(1, settings.pathSymbol);
|
|
|
|
settings.cookieFilePath = executablePathTo + "S_New4_cookies";
|
|
settings.accountFilePath = executablePathTo + "Accounts";
|
|
settings.accountNumberPath = executablePathTo + "Account_Number";
|
|
settings.serienListPath = executablePathTo + "SerienListe";
|
|
settings.defaultsFilePath = executablePathTo + "Defaults";
|
|
|
|
}
|
|
|
|
int manageParameter(Settings &settings, int argc, char **argv)
|
|
{
|
|
//Path settings
|
|
setPathSymbol(settings);
|
|
setPaths(settings);
|
|
if(loadDefaulOptions(settings) != 0)
|
|
return 28;
|
|
|
|
if(argc < 2) {
|
|
std::cout << " => Error: Keine Unteroption angegeben." << std::endl;
|
|
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
|
|
std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]);
|
|
if(res != 1) {
|
|
std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" :
|
|
std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl;
|
|
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
|
|
std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
|
|
return 2;
|
|
}
|
|
|
|
if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
return unterOption_help();
|
|
|
|
} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
return unterOption_default(&settings, argc, argv);
|
|
|
|
} else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
return unterOption_url(&settings, argc, argv);
|
|
|
|
} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
|
|
std::cout << "Version: " << settings.version << std::endl;
|
|
return -1;
|
|
|
|
} else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
return unterOption_search(&settings, argc, argv);
|
|
|
|
} else if (strncmp(argv[1], "info", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
return unterOption_info(&settings, argc, argv);
|
|
|
|
} else if (strncmp(argv[1], "clean", strlen(argv[1])) == 0) {
|
|
argv[1][0] = '\0';
|
|
unterOption_clean(&settings, argc, argv);
|
|
return -1;
|
|
|
|
} else {
|
|
std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
|
return 3;
|
|
}
|
|
}
|
|
|
|
int loadDefaulOptions(Settings &settings)
|
|
{
|
|
std::fstream ifs(settings.defaultsFilePath);
|
|
if(!ifs.is_open()) {
|
|
std::ofstream ofs(settings.defaultsFilePath);
|
|
if(!ofs.is_open()) {
|
|
std::cout << " => Error: Konnte Defaults-Datei nicht öffnen: " << errno << std::endl;
|
|
return 89;
|
|
} else {
|
|
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
|
|
ofs << "#Mit # kann man eine Zeile deaktivieren." << std::endl;
|
|
ofs << "DefaultFileVersion="<< settings.defaultFileVersion << std::endl;
|
|
ofs << "#DebugModus=false" << std::endl;
|
|
ofs << std::endl;
|
|
ofs << "#Socks5Proxy=127.0.0.1:9050" << std::endl;
|
|
ofs << "#FarbloseAusgabe=false" << std::endl;
|
|
ofs << "#OutputFile=/tmp/a" << std::endl;
|
|
ofs << std::endl;
|
|
ofs << "#default-GenaueHoster=Vivo,GoUnlimited" << std::endl;
|
|
ofs << "#default-Sprachen=GerDub,GerSub,Eng" << std::endl;
|
|
ofs << "#default-CheckSuchMuster=S%Staffel%E%Folge%" << std::endl;
|
|
ofs << "#default-CheckMaxDirs=20" << std::endl;
|
|
ofs << "#default-maxThreads=0" << std::endl;
|
|
ofs << std::endl;
|
|
ofs << "#search-AchteAufGroßUndKleinschreibung=false" << std::endl;
|
|
|
|
|
|
ofs.close();
|
|
}
|
|
ifs.open(settings.defaultsFilePath);
|
|
if(!ifs.is_open()) {
|
|
std::cout << " => Error: Konnte Defaults-Datei nach dem erstellen nicht öffnen: " << errno << std::endl;
|
|
return 97;
|
|
}
|
|
}
|
|
|
|
std::string line;
|
|
while (std::getline(ifs, line).good()) {
|
|
if(line.find("#") != std::string::npos || line == "")
|
|
continue;
|
|
else if ( line.find("=") == std::string::npos ) {
|
|
std::cout << " => Warnung: Bitte Info-Texte mit '#' am Anfang: Ungültige Option '" << line << "'." << std::endl;
|
|
continue;
|
|
}
|
|
std::string what = line.substr(0, line.find("=")), data = line.substr(line.find("=") + 1, line.length() - line.find("=") -1);
|
|
if(what == "") {
|
|
|
|
} else if (what == "Socks5Proxy") { ///---
|
|
if(data.find(":") == std::string::npos) {
|
|
std::cout << " => Error_Defaults: Ungültiger Socks5 Proxy: '" << data << "'" << std::endl;
|
|
return 31;
|
|
}
|
|
std::string ip = data.substr(0, data.find(":"));
|
|
std::string portStr = data.substr(data.find(":") + 1, data.length() - data.find(":"));
|
|
int port = atoi(portStr.c_str());
|
|
if(std::to_string(port) != portStr || port <= 0) {
|
|
std::cout << " => Error_Defaults: Socks5 Proxy: Invalid Port: " << portStr << std::endl;
|
|
return 32;
|
|
} else if (ip == "") {
|
|
std::cout << " => Error_Defaults: Socks5 Proxy: Invalid Ip Addresse: " << ip << std::endl;
|
|
return 34;
|
|
} else if(settings.debugMode) {
|
|
std::cout << " > Defaults: Proxy Addresse: "<< ip << ":" << port << std::endl;
|
|
}
|
|
settings.proxy_ip = ip;
|
|
settings.proxy_port = port;
|
|
|
|
} else if (what == "DefaultFileVersion") { ///---
|
|
if(data != settings.defaultFileVersion)
|
|
std::cout << " => Warnung: Veraltetes Defaults-File. Löschen sie die Datei, um die neuste Version zu bekommen." << std::endl;
|
|
|
|
} else if (what == "DebugModus") { ///---
|
|
if(data == "true")
|
|
settings.debugMode=true;
|
|
else if (data == "false")
|
|
settings.debugMode=false;
|
|
else {
|
|
std::cout << " => Error_Defaults: DebugModus: Ungültiger Wert für 'true/false': " << data << std::endl;
|
|
return 161;
|
|
}
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: DebugMode: true" << std::endl;
|
|
|
|
} else if (what == "default-GenaueHoster") {
|
|
settings.genaueHoster=data;
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: GenaueHoster: " << settings.genaueHoster << std::endl;
|
|
|
|
} else if (what == "default-Sprachen") {
|
|
settings.languages=data;
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: Sprachen: " << settings.languages << std::endl;
|
|
|
|
} else if (what == "default-CheckSuchMuster") {
|
|
settings.default_Searchmuster=data;
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: SuchMuster: " << settings.default_Searchmuster << std::endl;
|
|
|
|
} else if (what == "default-CheckMaxDirs") {
|
|
settings.default_maxDirs = atoi(data.c_str());
|
|
if(std::to_string(settings.default_maxDirs) != data ) {
|
|
std::cout << " => Error_Defaults: default-CheckMaxDirs: Ungültige Zahl: " << data << std::endl;
|
|
return 18;
|
|
}
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: default-CheckMaxDirs: " << settings.default_maxDirs << std::endl;
|
|
|
|
|
|
} else if (what == "default-maxThreads") {
|
|
settings.maxThreads = static_cast<unsigned>(atoi(data.c_str()));
|
|
if(std::to_string(settings.maxThreads) != data ) {
|
|
std::cout << " => Error_Defaults: Ungültige Zahl: " << data << std::endl;
|
|
return 18;
|
|
}
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: MaxThreads: " << settings.maxThreads << std::endl;
|
|
|
|
} else if (what == "FarbloseAusgabe") {
|
|
if(data == "true")
|
|
settings.colorless=true;
|
|
else if (data == "false")
|
|
settings.colorless=false;
|
|
else {
|
|
std::cout << " => Error_Defaults: FarbloseAusgabe: Ungültiger Wert für 'true/false': " << data << std::endl;
|
|
return 207;
|
|
}
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: FarbloseAusgabe: " << settings.colorless << std::endl;
|
|
|
|
} else if (what == "search-AchteAufGroßUndKleinschreibung") {
|
|
if(data == "true")
|
|
settings.search_IgnoreUpperLower=false;
|
|
else if (data == "false")
|
|
settings.search_IgnoreUpperLower=true;
|
|
else {
|
|
std::cout << " => Error_Defaults: search-AchteAufGroßUndKleinschreibung: Ungültiger Wert für 'true/false': " << data << std::endl;
|
|
return 227;
|
|
}
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: search-AchteAufGroßUndKleinschreibung: " << settings.search_IgnoreUpperLower << std::endl;
|
|
|
|
} else if (what == "OutputFile") {
|
|
settings.outputFilePath = data;
|
|
if(settings.debugMode)
|
|
std::cout << " > Defaults: OutputFile: " << settings.outputFilePath << std::endl;
|
|
|
|
} else if (what == "") {
|
|
|
|
} else if (what == "") {
|
|
|
|
} else if (what == "") {
|
|
|
|
} else if (what == "") {
|
|
|
|
} else {
|
|
std::cout << " => Warnung: Unbekannte Default-Option: '" << what << "'." << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
ifs.close();
|
|
return 0;
|
|
}
|
|
|
|
int unterOption_help()
|
|
{
|
|
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]..." << std::endl << std::endl;
|
|
std::cout << "Beschreibung:" << std::endl
|
|
<< " -> Mit diesem Programm kann man die Download-Urls" << std::endl
|
|
<< " oder Informationen von Serien bekommen." << std::endl
|
|
<< " -> Mit diesem Programm kann man Redirect-Links von" << std::endl
|
|
<< " s.to umwandeln." << std::endl
|
|
<< std::endl;
|
|
|
|
std::cout << "Unteroptionen:" << std::endl
|
|
<< "\t„--help“\tGibt dieses Helpmenue aus." << std::endl
|
|
<< "\t„--version“\tGibt die Version des Programmes aus." << std::endl
|
|
<< "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl
|
|
<< "\t„default“\tModus um Links von Serien zu bekommen." << std::endl
|
|
<< "\t„search“\tModus um Serien zu suchen." << std::endl
|
|
<< "\t„info“\t\tModus um Infos einer Serien zu bekommen." << std::endl
|
|
<< "\t„clean“\t\tModus um Cookie-Files zu löschen." << std::endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
int unterOption_default(Settings *settings, int argc, char ** argv)
|
|
{
|
|
settings->modus = Modus::DEFAULT_MODUS;
|
|
|
|
int c = 0;
|
|
const option long_opts[] = {
|
|
{"socks5-proxy", required_argument, nullptr, 'p'},
|
|
{"genauer-hoster", required_argument, nullptr, 'g'},
|
|
{"languages", required_argument, nullptr, 'l'},
|
|
{"output-file", required_argument, nullptr, 'o'},
|
|
|
|
{"start-episode", required_argument, nullptr, 'e'},
|
|
{"stop-episode", required_argument, nullptr, 'E'},
|
|
{"start-season", required_argument, nullptr, 's'},
|
|
{"stop-season", required_argument, nullptr, 'S'},
|
|
|
|
{"check-dir", required_argument, nullptr, 'C'},
|
|
{"check-muster", required_argument, nullptr, 'm'},
|
|
{"check-max-dirs", required_argument, nullptr, 'D'},
|
|
|
|
{"threads", required_argument, nullptr, 't'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
{"colorless", no_argument, nullptr, 'c'},
|
|
{"debug-mode", no_argument, nullptr, 'd'},
|
|
|
|
{nullptr, no_argument, nullptr, 0}
|
|
|
|
};
|
|
|
|
while( ( c = getopt_long (argc, argv, "p:g:l:o:e:E:s:S:C:m:D:t:hcd", long_opts, nullptr) ) != -1 ) {
|
|
switch(c) {
|
|
case 'p': {
|
|
if(!optarg || std::string(optarg) == "")
|
|
break;
|
|
std::string optarg = ::optarg;
|
|
if(optarg.find(":") == std::string::npos) {
|
|
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
|
|
return 31;
|
|
}
|
|
std::string ip = optarg.substr(0, optarg.find(":"));
|
|
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
|
|
int port = atoi(portStr.c_str());
|
|
if(std::to_string(port) != portStr || port <= 0) {
|
|
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
|
|
return 32;
|
|
} else if (ip == "") {
|
|
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
|
|
return 34;
|
|
} else if(settings->debugMode) {
|
|
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
|
|
}
|
|
settings->proxy_ip = ip;
|
|
settings->proxy_port = port;
|
|
}
|
|
break;
|
|
case 'g':
|
|
if(optarg)
|
|
settings->genaueHoster =+ optarg + std::string(",");
|
|
if(settings->debugMode)
|
|
std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl;
|
|
break;
|
|
case 'l':
|
|
if(optarg)
|
|
settings->languages =+ optarg + std::string(",");
|
|
if(settings->debugMode)
|
|
std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl;
|
|
break;
|
|
case 'o':
|
|
if(optarg)
|
|
settings->outputFilePath = optarg;
|
|
if(settings->debugMode)
|
|
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
|
|
break;
|
|
|
|
case 'e':
|
|
if(!optarg)
|
|
break;
|
|
settings->startEpisode = atoi(optarg);
|
|
if (std::to_string(settings->startEpisode) != optarg) {
|
|
std::cout << "Error: -e [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
|
|
return 11;
|
|
} else if (settings->startEpisode == 0) {
|
|
std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl;
|
|
return 12;
|
|
} else if (settings->startEpisode < 0) {
|
|
std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl;
|
|
return 13;
|
|
}
|
|
if(settings->debugMode)
|
|
std::cout << "StartEpisode: " << settings->startEpisode << std::endl;
|
|
break;
|
|
case 'E':
|
|
if(!optarg)
|
|
break;
|
|
settings->stopEpisode = atoi(optarg);
|
|
if (std::to_string(settings->stopEpisode) != optarg) {
|
|
std::cout << "Error: -E [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
|
|
return 14;
|
|
} else if (settings->debugMode)
|
|
std::cout << "StopEpisode: " << settings->stopEpisode << std::endl;
|
|
break;
|
|
case 's':
|
|
if(!optarg)
|
|
break;
|
|
settings->startSeason = atoi(optarg);
|
|
if (std::to_string(settings->startSeason) != optarg) {
|
|
std::cout << "Error: -s [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
|
|
return 15;
|
|
} else if (settings->startSeason == 0) {
|
|
std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl;
|
|
return 16;
|
|
} else if (settings->startSeason < 0) {
|
|
std::cout << "Error: -s [Staffel]: StartStaffel " << settings->startSeason << " ist kleiner 0." << std::endl;
|
|
return 17;
|
|
} else if(settings->debugMode)
|
|
std::cout << "StartStaffel: " << settings->startSeason << std::endl;
|
|
break;
|
|
case 'S':
|
|
if(!optarg)
|
|
break;
|
|
settings->stopSeason = atoi(optarg);
|
|
if (std::to_string(settings->stopSeason) != optarg) {
|
|
std::cout << "Error: -S [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
|
|
return 18;
|
|
} else if(settings->debugMode)
|
|
std::cout << "StopSeason: " << settings->stopSeason << std::endl;
|
|
break;
|
|
case 'm':
|
|
if(optarg)
|
|
settings->default_Searchmuster = optarg;
|
|
if(settings->debugMode)
|
|
std::cout << " SearchMuster: " << settings->default_Searchmuster << std::endl;
|
|
break;
|
|
case 'D':
|
|
if(!optarg)
|
|
break;
|
|
settings->default_maxDirs = atoi(optarg);
|
|
if(std::to_string(settings->default_maxDirs) != std::string(optarg) ) {
|
|
std::cout << "[-D]: Invalid Count: " << optarg << std::endl;
|
|
return 18;
|
|
}
|
|
if(settings->debugMode)
|
|
std::cout << "CheckMaxDirs: " << settings->default_maxDirs << std::endl;
|
|
|
|
break;
|
|
case 't':
|
|
if(!optarg)
|
|
break;
|
|
settings->maxThreads = static_cast<unsigned>(atoi(optarg));
|
|
if(std::to_string(settings->maxThreads) != std::string(optarg) ) {
|
|
std::cout << "[-t]: Ungültige Zahl: " << optarg << std::endl;
|
|
return 18;
|
|
}
|
|
if(settings->debugMode)
|
|
std::cout << "MaxThreads: " << settings->maxThreads << std::endl;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
if(!optarg)
|
|
break;
|
|
settings->default_checkPath = optarg;
|
|
if(settings->debugMode)
|
|
std::cout << "To check Dir/File: " << settings->default_checkPath << std::endl;
|
|
break;
|
|
case 'c':
|
|
settings->colorless = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Farblos: true" << std::endl;
|
|
if(argc > optind)
|
|
if(argv[optind][0] != '-' && std::string(argv[optind]).find(settings->pathSymbol) != std::string::npos) {
|
|
std::cout << " => Upps: Hast du -c (--colorless) mit -C (--check-dir) verwechselt?" << std::endl
|
|
<< " (Hat “Argument“ mit “"<< settings->pathSymbol << "“: '-c " << std::string(argv[optind]) << "')." << std::endl;
|
|
return -1;
|
|
}
|
|
break;
|
|
case 'd':
|
|
settings->debugMode = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Debug Modus: true" << std::endl;
|
|
break;
|
|
case 'h':
|
|
unterOption_default_help();
|
|
return -1;
|
|
default:
|
|
std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
|
|
std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl;
|
|
return -1;
|
|
}
|
|
}
|
|
//Alle nicht verwendeten Parameter == Name
|
|
while (optind < argc) {
|
|
if(argv[optind][0]) {
|
|
settings->name.append(argv[optind++]).append(" ");
|
|
} else
|
|
optind++;
|
|
}
|
|
|
|
if(settings->name.length() > 0)
|
|
settings->name.pop_back();
|
|
if(settings->debugMode) {
|
|
std::cout << "Name: " << settings->name << std::endl;
|
|
std::cout << "Modus: DEFAULT_MODUS" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void unterOption_default_help()
|
|
{
|
|
std::cout << "Usage: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl
|
|
<< "Parameter:" << std::endl << std::endl
|
|
<< " > Auswahloptionen:" << std::endl
|
|
<< "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl
|
|
<< "\t -> Die Namen der Hoster, deren Links du willst. Der wichtigste zuerst." << std::endl
|
|
<< "\t -> Default: Vivo,GoUnlimited" << std::endl
|
|
<< "\t-l [GerDub/GerSub/Eng,...], --languages [GerDub/GerSub/Eng,...]" << std::endl
|
|
<< "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl
|
|
<< std::endl
|
|
<< " > Proxy-Optionen:" << std::endl
|
|
<< "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl
|
|
<< "\t -> Ip Addresse eines Socks5-Proxys angeben. Default: 127.0.0.1:9050" << std::endl
|
|
<< std::endl
|
|
<< " > Outputoptionen:" << std::endl
|
|
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl
|
|
<< "\t -> Schreibe Links nach Redirect in diese Datei." << std::endl
|
|
<< "\t-c, --colorless" << std::endl
|
|
<< "\t -> Keine Farben beim Output verwenden. Default: false" << std::endl
|
|
<< "\t-d, --debug-mode" << std::endl
|
|
<< "\t -> Debug Nachrichten an. Default: false" << std::endl
|
|
<< std::endl
|
|
<< " > Check-Dir Optionen:" << std::endl
|
|
<< "\t-C [Pfad], --check-dir [Pfad]" << std::endl
|
|
<< "\t +Ordner -> Überprüfe ob in diesem, oder in einen der Unterordnern (beachte -D und -m) die" << std::endl
|
|
<< "\t -> Folge vorkommt. Wenn ja, dann überspringe diese." << std::endl
|
|
<< "\t +Datei -> Überprüfe ob in der angegebenen Textdatei eine Zeile mit dem Muster vorkommt" << std::endl
|
|
<< "\t -> (beachte -D und -m). Wenn ja, dann überspringe diese." << std::endl
|
|
<< "\t-m, --check-muster" << std::endl
|
|
<< "\t -> Muster mit dem Überprüft wird, ob diese Folge in einem Ordner ist. Default: S%Staffel%E%Folge%" << std::endl
|
|
<< "\t -> %Staffel% ist eine Variable für die Staffel mit 0 + Staffel, wenn Staffel < 10. " << std::endl
|
|
<< "\t -> %Folge% ist eine Variable für die Folge mit 0 + Folge, wenn Folge < 10. " << std::endl
|
|
<< "\t-D, --check-max-dirs" << std::endl
|
|
<< "\t -> Maximale Anzahl der Ordner, die auf Dateien untersucht werden. Default: 20" << std::endl
|
|
<< std::endl
|
|
<< " > Durchlaufoptionen:" << std::endl
|
|
<< "\t-e [Folge], --start-episode [Folge]" << std::endl
|
|
<< "\t -> Das Programm startet mit dieser Folge." << std::endl
|
|
<< "\t Default: 1" << std::endl
|
|
<< "\t-E [Folge], --stop-episode [Folge]" << std::endl
|
|
<< "\t -> - Wenn -S nicht verwendet wird, stoppt das Programm sobald die Folge erreicht wurde." << std::endl
|
|
<< "\t - Wenn -S verwendet wird, stoppt es 1. wenn die Folge UND die Staffel erreicht wurden," << std::endl
|
|
<< "\t 2. wenn die die Staffel von -S fertig ist. Zum deaktivieren Folge <= 0 verwenden." << std::endl
|
|
<< "\t Default: 0" << std::endl
|
|
<< "\t-s [Staffel], --start-season [Staffel]" << std::endl
|
|
<< "\t -> Das Programm startet mit dieser Staffel." << std::endl
|
|
<< "\t Default: 1" << std::endl
|
|
<< "\t-S [Staffel], --stop-season [Staffel]" << std::endl
|
|
<< "\t -> Das Programm stopt mit dieser Staffel. Beachte Verwendung mit -E." << std::endl
|
|
<< "\t Zum deaktivieren Staffel <= 0 verwenden. Default: 0" << std::endl
|
|
<< " > Multi-Thrading Optionen:" << std::endl
|
|
<< "\t-t [maxThreads], --threads [maxThreads]" << std::endl
|
|
<< "\t -> Das Programm startet für jede Folge einen eigenen Thread," << std::endl
|
|
<< "\t -> bis die maximale Anzahl ereicht wurde. Dann wartet es auf" << std::endl
|
|
<< "\t -> das enden aller Threads und fängt dann wieder von vorne an." << std::endl
|
|
<< "\t -> Zum deaktivieren von Multithreading '0' verwenden. Default: 0" << std::endl
|
|
<< std::endl
|
|
<< " > Help-Optionen" << std::endl
|
|
<< "\t-h, --help" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
int unterOption_url(Settings *settings, int argc, char **argv)
|
|
{
|
|
settings->modus = Modus::DIRECT_LINK_MODUS;
|
|
|
|
int c = 0;
|
|
const option long_opts[] = {
|
|
{"socks5-proxy", required_argument, nullptr, 'p'},
|
|
{"output-file", required_argument, nullptr, 'o'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
{"colorless", no_argument, nullptr, 'c'},
|
|
{"debug-mode", no_argument, nullptr, 'd'},
|
|
|
|
{nullptr, no_argument, nullptr, 0}
|
|
|
|
};
|
|
|
|
while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) {
|
|
switch(c) {
|
|
case 'p': {
|
|
if(!optarg || std::string(optarg) == "")
|
|
break;
|
|
std::string optarg = ::optarg;
|
|
if(optarg.find(":") == std::string::npos) {
|
|
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
|
|
return 31;
|
|
}
|
|
std::string ip = optarg.substr(0, optarg.find(":"));
|
|
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
|
|
int port = atoi(portStr.c_str());
|
|
if(std::to_string(port) != portStr || port <= 0) {
|
|
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
|
|
return 32;
|
|
} else if (ip == "") {
|
|
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
|
|
return 34;
|
|
} else if(settings->debugMode) {
|
|
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
|
|
}
|
|
settings->proxy_ip = ip;
|
|
settings->proxy_port = port;
|
|
}
|
|
break;
|
|
case 'o':
|
|
if(optarg)
|
|
settings->outputFilePath = optarg;
|
|
if(settings->debugMode)
|
|
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
|
|
break;
|
|
case 'c':
|
|
settings->colorless = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Farblos: true" << std::endl;
|
|
break;
|
|
case 'd':
|
|
settings->debugMode = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Debug Modus: true" << std::endl;
|
|
break;
|
|
case 'h':
|
|
unterOption_url_help();
|
|
return -1;
|
|
default:
|
|
std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
|
|
std::cout << "„" << getProgramName() << " url --help“ liefert weitere Informationen." << std::endl;
|
|
return 21;
|
|
}
|
|
}
|
|
|
|
|
|
//Alle nicht verwendeten Parameter == Name
|
|
while (optind < argc) {
|
|
if(argv[optind][0]) {
|
|
settings->name.append(argv[optind++]).append(",");
|
|
} else
|
|
optind++;
|
|
}
|
|
|
|
if(settings->name.length() > 0)
|
|
settings->name.pop_back();
|
|
if(settings->debugMode) {
|
|
std::cout << "Urls: " << settings->name << std::endl;
|
|
std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void unterOption_url_help()
|
|
{
|
|
std::cout << "Aufruf: " << getProgramName() << "url [OPTION]... [URL]..." << std::endl << std::endl;
|
|
|
|
std::cout << "Beschreibung:" << std::endl
|
|
<< " Mit dieser Unterfunction von " << getProgramName() << " können eigene" << std::endl
|
|
<< " Redirect-Links umgewandelt werden. Beispiel:" << std::endl
|
|
<< " https://s.to/redirect/4449825 -> http://vivo.sx/d20b111ade" << std::endl
|
|
<< " Achtung: Achte, dass Url mit https:// nicht mit http:// beginnt." << std::endl
|
|
<< " Standartwerte können im Defaultfile geändert werden." << std::endl << std::endl;
|
|
|
|
std::cout << "OPTIONEN:" << std::endl
|
|
|
|
<< " -p [Socks5ProxyAddresse], --socks5-proxy [Socks5ProxyAddresse]" << std::endl
|
|
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
|
|
<< " Standart: 127.0.0.1:9050, falls nichts im Defaultfile festgelegt wurde." << std::endl << std::endl
|
|
<< " -o [Pfad], --output-file [Pfad]" << std::endl
|
|
<< " Mit diere Option kann man ein (nichtvorhandenes) Text-Datei angeben," << std::endl
|
|
<< " inwelches die umgewandelten Redirect-Links geschrieben werden." << std::endl << std::endl
|
|
<< " -c, --colorless" << std::endl
|
|
<< " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl
|
|
<< " -d, --debug-mode" << std::endl
|
|
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
|
|
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
|
|
<< " -h, --help" << std::endl
|
|
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
|
|
}
|
|
|
|
|
|
int unterOption_search(Settings *settings, int argc, char **argv)
|
|
{
|
|
settings->modus = Modus::SEARCH_MODUS;
|
|
|
|
int c = 0;
|
|
const option long_opts[] = {
|
|
{"socks5-proxy", required_argument, nullptr, 'p'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
{"colorless", no_argument, nullptr, 'c'},
|
|
{"debug-mode", no_argument, nullptr, 'd'},
|
|
{"exactly-writing", no_argument, nullptr, 'e'},
|
|
{"update", no_argument, nullptr, 'u'},
|
|
|
|
{nullptr, no_argument, nullptr, 0}
|
|
|
|
};
|
|
|
|
while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
|
|
switch(c) {
|
|
case 'p': {
|
|
if(!optarg || std::string(optarg) == "")
|
|
break;
|
|
std::string optarg = ::optarg;
|
|
if(optarg.find(":") == std::string::npos) {
|
|
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
|
|
return 31;
|
|
}
|
|
std::string ip = optarg.substr(0, optarg.find(":"));
|
|
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
|
|
int port = atoi(portStr.c_str());
|
|
if(std::to_string(port) != portStr || port <= 0) {
|
|
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
|
|
return 32;
|
|
} else if (ip == "") {
|
|
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
|
|
return 34;
|
|
} else if(settings->debugMode) {
|
|
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
|
|
}
|
|
settings->proxy_ip = ip;
|
|
settings->proxy_port = port;
|
|
}
|
|
break;
|
|
case 'h':
|
|
unterOption_search_help();
|
|
return -1;
|
|
case 'c':
|
|
settings->colorless = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Farblos: true" << std::endl;
|
|
break;
|
|
case 'd':
|
|
settings->debugMode = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Debug Modus: true" << std::endl;
|
|
break;
|
|
case 'e':
|
|
settings->search_IgnoreUpperLower = false;
|
|
if(settings->debugMode)
|
|
std::cout << "Achte auf Groß und Kleinschreibung: true" << std::endl;
|
|
break;
|
|
case 'u':
|
|
settings->search_wantUpdate = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Update die Liste: true" << std::endl;
|
|
break;
|
|
default:
|
|
std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
|
|
std::cout << "„" << getProgramName() << " search --help“ liefert weitere Informationen." << std::endl;
|
|
return 21;
|
|
}
|
|
}
|
|
|
|
//Alle nicht verwendeten Parameter == Name
|
|
while (optind < argc) {
|
|
if(argv[optind][0]) {
|
|
settings->name.append(argv[optind++]).append(" ");
|
|
} else
|
|
optind++;
|
|
}
|
|
if(settings->name.length() > 0)
|
|
settings->name.pop_back();
|
|
if(settings->debugMode) {
|
|
std::cout << "Name: " << settings->name << std::endl;
|
|
std::cout << "Modus: Search_MODUS" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void unterOption_search_help()
|
|
{
|
|
std::cout << "Aufruf: " << getProgramName() << "search [OPTION]... [NAME]" << std::endl
|
|
<< " " << getProgramName() << "search [-u, --update]" << std::endl << std::endl;
|
|
|
|
std::cout << "Beschreibung:" << std::endl
|
|
<< " Mit dieser Unterfunction des Programms kann man Serien auf s.to suchen." << std::endl
|
|
<< " Tipp: Falls deine Serie nicht gefunden wird, entferne einen Teil" << std::endl
|
|
<< " am Ende deines SuchNamens und wiederhole die Suche." << std::endl
|
|
<< " Tipp: Wenn deine Serie sehr neu auf s.to ist, und deshalb nicht gefunden" << std::endl
|
|
<< " wird, verwende die Option -u, um die Liste zu aktualisieren." << std::endl << std::endl;
|
|
|
|
std::cout << "AKTUALISIERUNG:" << std::endl
|
|
|
|
<< " -u, --update" << std::endl
|
|
<< " Mit dieser Option wird die Liste der Serien, die bei der Suche durchsucht " << std::endl
|
|
<< " wird, aktualisiert." << std::endl << std::endl;
|
|
|
|
std::cout << "OPTIONEN:" << std::endl
|
|
|
|
<< " -p [Socks5ProxyAddresse], --socks5-proxy [Socks5ProxyAddresse]" << std::endl
|
|
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
|
|
<< " Standart: 127.0.0.1:9050, falls nichts im Defaultfile festgelegt wurde." << std::endl << std::endl
|
|
<< " -e, --exactly-writing" << std::endl
|
|
<< " Mit dieser Option achtet das Programm auf Groß- und Kleinschreibung." << std::endl << std::endl
|
|
<< " -c, --colorless" << std::endl
|
|
<< " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl
|
|
<< " -d, --debug-mode" << std::endl
|
|
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
|
|
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
|
|
<< " -h, --help" << std::endl
|
|
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl << std::endl;
|
|
}
|
|
|
|
|
|
int unterOption_info(Settings *settings, int argc, char **argv)
|
|
{
|
|
settings->modus = Modus::INFO_MODUS;
|
|
|
|
int c = 0;
|
|
const option long_opts[] = {
|
|
{"socks5-proxy", required_argument, nullptr, 'p'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
{"colorless", no_argument, nullptr, 'c'},
|
|
{"debug-mode", no_argument, nullptr, 'd'},
|
|
|
|
{nullptr, no_argument, nullptr, 0}
|
|
|
|
};
|
|
|
|
while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
|
|
switch(c) {
|
|
case 'p': {
|
|
if(!optarg || std::string(optarg) == "")
|
|
break;
|
|
std::string optarg = ::optarg;
|
|
if(optarg.find(":") == std::string::npos) {
|
|
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
|
|
return 31;
|
|
}
|
|
std::string ip = optarg.substr(0, optarg.find(":"));
|
|
std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
|
|
int port = atoi(portStr.c_str());
|
|
if(std::to_string(port) != portStr || port <= 0) {
|
|
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
|
|
return 32;
|
|
} else if (ip == "") {
|
|
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
|
|
return 34;
|
|
} else if(settings->debugMode) {
|
|
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
|
|
}
|
|
settings->proxy_ip = ip;
|
|
settings->proxy_port = port;
|
|
}
|
|
break;
|
|
case 'h':
|
|
unterOption_info_help();
|
|
return -1;
|
|
case 'c':
|
|
settings->colorless = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Farblos: true" << std::endl;
|
|
break;
|
|
case 'd':
|
|
settings->debugMode = true;
|
|
if(settings->debugMode)
|
|
std::cout << "Debug Modus: true" << std::endl;
|
|
break;
|
|
default:
|
|
std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl;
|
|
std::cout << "„" << getProgramName() << " info --help“ liefert weitere Informationen." << std::endl;
|
|
return 21;
|
|
}
|
|
}
|
|
|
|
//Alle nicht verwendeten Parameter == Name
|
|
while (optind < argc) {
|
|
if(argv[optind][0]) {
|
|
settings->name.append(argv[optind++]).append(" ");
|
|
} else
|
|
optind++;
|
|
}
|
|
if(settings->name.length() > 0)
|
|
settings->name.pop_back();
|
|
if(settings->debugMode) {
|
|
std::cout << "Name: " << settings->name << std::endl;
|
|
std::cout << "Modus: Search_MODUS" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void unterOption_info_help()
|
|
{
|
|
std::cout << "Usage: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl
|
|
<< "Parameter:" << std::endl
|
|
<< "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl
|
|
<< "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl
|
|
<< "\t-c, --colorless" << std::endl
|
|
<< "\t -> Gib keine Farbigen Infos aus. Default: false" << std::endl
|
|
<< "\t-d, --debug-mode" << std::endl
|
|
<< "\t -> Debug Nachrichten an. Default: false" << std::endl
|
|
<< "\t-h, --help" << std::endl
|
|
<< "\t -> Gibt dieses Helpmenü aus." << std::endl;
|
|
}
|
|
|
|
|
|
void unterOption_clean(Settings * settings, int argc, char **argv)
|
|
{
|
|
if(argc > 2)
|
|
if(strncmp("--help", argv[2], strlen(argv[2])) == 0) {
|
|
std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl;
|
|
std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl;
|
|
return;
|
|
}
|
|
|
|
unsigned count = 0;
|
|
if(fileExists(settings->cookieFilePath)) {
|
|
if(remove(settings->cookieFilePath.c_str()) != 0) {
|
|
std::cout << " => Error: Das löschen von " << settings->cookieFilePath << " ist fehlgeschlagen: " << errno << std::endl;
|
|
return;
|
|
} else
|
|
count++;
|
|
}
|
|
|
|
for (unsigned i = 0; i < UINT_MAX && fileExists(settings->cookieFilePath + std::to_string(i)); i++) {
|
|
if(remove( (settings->cookieFilePath + std::to_string(i)).c_str() ) != 0) {
|
|
std::cout << " => Error: Das löschen von " << settings->cookieFilePath + std::to_string(i) << " ist fehlgeschlagen: " << errno << std::endl;
|
|
return;
|
|
} else {
|
|
count++;
|
|
}
|
|
}
|
|
|
|
if(count == 0)
|
|
std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl;
|
|
else
|
|
std::cout << " => " << count << " Cookie-File(s) gelöscht." << std::endl;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
int compare(std::string All_Options_with_komma_between, std::string input)
|
|
{
|
|
std::istringstream iStrStream( All_Options_with_komma_between + "\n");
|
|
std::string line;
|
|
int allFounds = 0;
|
|
while (getline(iStrStream, line).good())
|
|
if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) {
|
|
allFounds++;
|
|
//std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl;
|
|
}
|
|
return allFounds;
|
|
}
|
|
|
|
bool dirExists(std::string dir)
|
|
{
|
|
struct stat sb;
|
|
return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false;
|
|
}
|
|
|
|
std::string getProgramName()
|
|
{
|
|
return getexepath().erase(0, ( getexepath().find_last_of("/\\") != std::string::npos ) ? getexepath().find_last_of("/\\") +1 : 0 );
|
|
}
|
|
|
|
std::string getexepath()
|
|
{
|
|
#ifdef linux
|
|
char result[ PATH_MAX ];
|
|
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
|
|
return std::string( result, (count > 0) ? static_cast<size_t>(count) : 0 );
|
|
#endif
|
|
#ifdef ABC ///_WIN32
|
|
//wchar_t result[ MAX_PATH ];
|
|
char buffer[MAX_PATH];
|
|
return std::string( result, GetModuleFileName( NULL, buffer, MAX_PATH ) );
|
|
//GetModuleFileName(NULL, result, MAX_PATH) ;
|
|
//return reinterpret_cast<char*>(result);
|
|
#endif
|
|
}
|
|
|
|
void setPathSymbol(Settings &settings)
|
|
{
|
|
#ifdef linux
|
|
settings.pathSymbol = '/';
|
|
#endif
|
|
#ifdef _WIN32
|
|
settings.pathSymbol = '\\';
|
|
#endif
|
|
}
|
|
|
|
bool fileExists (const std::string& name) {
|
|
struct stat buffer;
|
|
return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));
|
|
}
|
|
|