#include "parameterManager.h" void setPaths(Settings &settings, std::string executablePathTo) { //Path settings executablePathTo.erase(executablePathTo.find_last_of("/\\") + 1 , executablePathTo.length() - ( executablePathTo.find_last_of("/\\") + 1) ); if(!dirExists(executablePathTo + "src/")) system(std::string("mkdir \"" + executablePathTo + "src/\"").c_str()); if(dirExists(executablePathTo + "src/")) executablePathTo+="src/"; settings.cookieFilePath = executablePathTo + "S_New4_cookies"; settings.accountFilePath = executablePathTo + "Accounts"; settings.accountNumberPath = executablePathTo + "Account_Number"; settings.serienListPath = executablePathTo + "SerienListe"; } int manageParameter(Settings &settings, int argc, char **argv) { //Path settings setPaths(settings, argv[0]); if(argc < 2) { std::cout << " => Keine Unteroption angegeben." << std::endl; std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; return 1; } int res = compare("--help\ndefault\nurl\n--version\nsearch", argv[1]); if(res != 1) { std::cout << " => Unbekannte Unteroption: '" << argv[1] << "': Mehrere oder keine Option gefunden: " << res << " Möglichkeiten." << std::endl; std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; return 2; } if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_help(&settings, argv[0]); } 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 (false) { //return 0; } else { std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; } } int unterOption_help(Settings *, char * argv0) { std::cout << "Aufruf: " << getProgramName(argv0) << " [Unteroption] [PARAMETER]" << std::endl << std::endl; std::cout << "Unteroptionen:" << std::endl << "\t„--help“\tListe aller Unteroptionen" << std::endl << "\t„--version“\tVersion des Programmes" << 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; return -1; } int unterOption_default(Settings *settings, int argc, char ** argv) { settings->modus = Modus::DEFAULT_MODUS; int c = 0; const option long_opts[] = { {"name", required_argument, nullptr, 'n'}, {"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, '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, "n:p:g:l:o:e:E:s:S:C:m:t:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'n': if(optarg) settings->name = optarg; if(settings->debugMode) std::cout << "Name: " << settings->name << std::endl; break; 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 't': if(!optarg) break; settings->default_maxDirs = atoi(optarg); if(std::to_string(settings->default_maxDirs) != std::string(optarg) ) { std::cout << "[-t]: Invalid Count: " << optarg << std::endl; return 18; } if(settings->debugMode) std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; break; case 'C': if(!optarg) break; settings->default_checkDirPath = optarg; if(settings->debugMode) std::cout << "To check Dir: " << settings->default_checkDirPath << 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_default_help(settings, argv[0]); return -1; default: std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl; std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl; return -1; } } if(settings->debugMode) std::cout << "Modus: DEFAULT_MODUS" << std::endl; return 0; } void unterOption_default_help(Settings *, char * argv0) { std::cout << "Usage: " << getProgramName(argv0) << " default [ Parameter & {-n [Name]} ]..." << std::endl << "Parameter:" << std::endl << std::endl << " > Muss-Parameter:" << std::endl << "\t-n [Name], --name [Name]" << std::endl << "\t -> Namen der Serie, deren Links du willst." << 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-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 -> Überprüfe ob in diesem, oder in einen der Unterordnern die Folge vorkommt." << std::endl << "\t -> 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-t, --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 << 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[] = { {"url", required_argument, nullptr, 'u'}, {"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, "u:p:o:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'u': if(optarg) settings->name = optarg; if(settings->debugMode) std::cout << "Urls: " << settings->name << std::endl; break; 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(settings, argv[0]); return -1; default: std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl; std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl; return 21; } } if(settings->debugMode) std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl; return 0; } void unterOption_url_help(Settings *, char * argv0) { std::cout << "Usage: " << getProgramName(argv0) << " url [ Parameter & {-u [Url]} ]..." << std::endl << "Parameter:" << std::endl << "\t-u [Url1,Url2,...], --url [Url1,Url2,...]" << std::endl << "\t -> Die zu umwandelnden redirect-Links." << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl << "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t-c, --colorless" << std::endl << "\t -> Default: false ." << std::endl << "\t-d, --debug-mode" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t-h, --help" << std::endl; } std::string getProgramName(char *argv0) { return std::string(argv0).erase(0, ( (std::string(argv0).find_last_of("/\\") != std::string::npos ) ? std::string(argv0).find_last_of("/\\") +1 : 0 ) ); } 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; } int unterOption_search(Settings *settings, int argc, char **argv) { settings->modus = Modus::Search_MODUS; int c = 0; const option long_opts[] = { {"name", required_argument, nullptr, 'n'}, {"socks5-proxy", required_argument, nullptr, 'p'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, {"debug-mode", no_argument, nullptr, 'd'}, {"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 'n': if(optarg) settings->name = optarg; if(settings->debugMode) std::cout << "Name: " << settings->name << std::endl; break; 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(settings, argv[0]); 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(argv[0]) << " search [PARAMETER]" << std::endl; std::cout << "„" << getProgramName(argv[0]) << " search --help“ liefert weitere Informationen." << std::endl; return 21; } } if(settings->debugMode) std::cout << "Modus: Search_MODUS" << std::endl; return 0; } void unterOption_search_help(Settings *, char *argv0) { std::cout << "Usage: " << getProgramName(argv0) << " search [ Parameter & {-n [Name] / -u} ]..." << std::endl << "Parameter:" << std::endl << "\t-n [Name], --name [Name]" << std::endl << "\t -> (Teil)Namen der gesuchten Serie." << 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-e, --exactly-writing" << std::endl << "\t -> Achte auf Groß und kleinschreibung bei der Suche. Default: false" << std::endl << "\t-u, --update" << std::endl << "\t -> Update die Serienliste. Default: false" << std::endl << "\t-h, --help" << std::endl << "\t -> Gibt dieses Helpmenü aus." << std::endl; } bool dirExists(std::string dir) { struct stat sb; return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false; }