mingw tests

This commit is contained in:
Markus 2019-08-13 18:59:01 +02:00
parent 0461e82257
commit 382e2283b7
14 changed files with 785 additions and 199 deletions

View File

@ -1,5 +1,5 @@
#include "parameterManager.h"
#include "programManager.h" #include "programManager.h"
#include "parameterManager.h"




int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -10,5 +10,5 @@ int main(int argc, char *argv[])
if(res != 0) if(res != 0)
return (res == -1) ? 0 : res; return (res == -1) ? 0 : res;


return mainProgram.start(settings); return mainProgram.start(&settings);
} }

View File

@ -274,7 +274,7 @@ int PageManager::writeToFile(std::string path, std::string text)
std::ofstream of; std::ofstream of;
of.open(path, std::ios::out | std::ios::app); of.open(path, std::ios::out | std::ios::app);
if(!of.is_open()) { if(!of.is_open()) {
perror(" => Error: Konnte output Datei nicht öffnen"); perror(" => Error: Konnte Output Datei nicht öffnen");
return -1; return -1;
} }
of << text << std::endl; of << text << std::endl;

View File

@ -3,7 +3,7 @@


#include <iostream> #include <iostream>
// if complied for windows; everything is in */projectfolder/curl/ // if complied for windows; everything is in */projectfolder/curl/
#include </home/markus/Qt/S_New4/curl/curl.h> #include </home/markus/Qt/S_New4/g++/curl/curl.h>
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>

View File

@ -1,8 +1,11 @@
#include "parameterManager.h" #include "parameterManager.h"


void setPaths(Settings &settings, std::string executablePathTo) void setPaths(Settings &settings)
{ {
//Path settings //Path settings
std::string executablePathTo = getexepath();
std::cout << "Path " << executablePathTo << std::endl;

executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) ); 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(!dirExists(executablePathTo + "src" + settings.pathSymbol))
@ -17,30 +20,31 @@ void setPaths(Settings &settings, std::string executablePathTo)


} }



int manageParameter(Settings &settings, int argc, char **argv) int manageParameter(Settings &settings, int argc, char **argv)
{ {
//Path settings //Path settings
setPaths(settings, argv[0]); setPathSymbol(settings);
setPaths(settings);


if(argc < 2) { if(argc < 2) {
std::cout << " => Keine Unteroption angegeben." << std::endl; std::cout << " => Error: Keine Unteroption angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
return 1; return 1;
} }


int res = compare("--help\ndefault\nurl\n--version\nsearch", argv[1]); int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo", argv[1]);
if(res != 1) { if(res != 1) {
std::cout << " => Unbekannte Unteroption: '" << argv[1] << "': Mehrere oder keine Option gefunden: " << res << " Möglichkeiten." << std::endl; std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" :
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
return 2; return 2;
} }


if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
return unterOption_help(&settings, argv[0]); return unterOption_help();


} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) { } else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
@ -58,9 +62,9 @@ int manageParameter(Settings &settings, int argc, char **argv)
argv[1][0] = '\0'; argv[1][0] = '\0';
return unterOption_search(&settings, argc, argv); return unterOption_search(&settings, argc, argv);


} else if (false) { } else if (strncmp(argv[1], "info", strlen(argv[1])) == 0) {

argv[1][0] = '\0';
//return 0; return unterOption_info(&settings, argc, argv);


} else { } else {
std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
@ -68,9 +72,9 @@ int manageParameter(Settings &settings, int argc, char **argv)
} }
} }


int unterOption_help(Settings *, char * argv0) int unterOption_help()
{ {
std::cout << "Aufruf: " << getProgramName(argv0) << " [Unteroption] [PARAMETER]" << std::endl << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl << std::endl;
std::cout << "Unteroptionen:" << std::endl std::cout << "Unteroptionen:" << std::endl
<< "\t„--help“\tListe aller Unteroptionen" << std::endl << "\t„--help“\tListe aller Unteroptionen" << std::endl
<< "\t„--version“\tVersion des Programmes" << std::endl << "\t„--version“\tVersion des Programmes" << std::endl
@ -88,7 +92,6 @@ int unterOption_default(Settings *settings, int argc, char ** argv)


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"name", required_argument, nullptr, 'n'},
{"socks5-proxy", required_argument, nullptr, 'p'}, {"socks5-proxy", required_argument, nullptr, 'p'},
{"genauer-hoster", required_argument, nullptr, 'g'}, {"genauer-hoster", required_argument, nullptr, 'g'},
{"languages", required_argument, nullptr, 'l'}, {"languages", required_argument, nullptr, 'l'},
@ -112,14 +115,8 @@ int unterOption_default(Settings *settings, int argc, char ** argv)


}; };


while( ( c = getopt_long (argc, argv, "n:p:g:l:o:e:E:s:S:C:m:t:hcd", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "p:g:l:o:e:E:s:S:C:m:t:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'n':
if(optarg)
settings->name = optarg;
if(settings->debugMode)
std::cout << "Name: " << settings->name << std::endl;
break;
case 'p': { case 'p': {
if(!optarg || std::string(optarg) == "") if(!optarg || std::string(optarg) == "")
break; break;
@ -245,6 +242,12 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
settings->colorless = true; settings->colorless = true;
if(settings->debugMode) if(settings->debugMode)
std::cout << "Farblos: true" << std::endl; 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; break;
case 'd': case 'd':
settings->debugMode = true; settings->debugMode = true;
@ -252,30 +255,40 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_default_help(settings, argv[0]); unterOption_default_help();
return -1; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl;
return -1; return -1;
} }
} }
if(settings->debugMode) //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; std::cout << "Modus: DEFAULT_MODUS" << std::endl;
}

return 0; return 0;
} }


void unterOption_default_help(Settings *, char * argv0) void unterOption_default_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " default [ Parameter & {-n [Name]} ]..." << std::endl std::cout << "Usage: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl
<< "Parameter:" << std::endl << 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 << " > Auswahloptionen:" << std::endl
<< "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << 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 -> 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-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 << "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl
<< std::endl << std::endl
@ -330,7 +343,6 @@ int unterOption_url(Settings *settings, int argc, char **argv)


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"url", required_argument, nullptr, 'u'},
{"socks5-proxy", required_argument, nullptr, 'p'}, {"socks5-proxy", required_argument, nullptr, 'p'},
{"output-file", required_argument, nullptr, 'o'}, {"output-file", required_argument, nullptr, 'o'},


@ -342,15 +354,8 @@ int unterOption_url(Settings *settings, int argc, char **argv)


}; };


while( ( c = getopt_long (argc, argv, "u:p:o:hcd", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'u':
if(optarg)
settings->name = optarg;
if(settings->debugMode)
std::cout << "Urls: " << settings->name << std::endl;
break;

case 'p': { case 'p': {
if(!optarg || std::string(optarg) == "") if(!optarg || std::string(optarg) == "")
break; break;
@ -392,30 +397,43 @@ int unterOption_url(Settings *settings, int argc, char **argv)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_url_help(settings, argv[0]); unterOption_url_help();
return -1; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " url --help“ liefert weitere Informationen." << std::endl;
return 21; return 21;
} }
} }
if(settings->debugMode)

//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; std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl;
}

return 0; return 0;
} }


void unterOption_url_help(Settings *, char * argv0) void unterOption_url_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " url [ Parameter & {-u [Url]} ]..." << std::endl std::cout << "Usage: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl
<< "Parameter:" << 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-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl
<< "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl << "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl
<< "\t-c, --colorless" << std::endl << "\t-c, --colorless" << std::endl
<< "\t -> Default: false ." << std::endl << "\t -> Default: false" << std::endl
<< "\t-d, --debug-mode" << std::endl << "\t-d, --debug-mode" << std::endl
<< "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl
<< "\t-h, --help" << std::endl; << "\t-h, --help" << std::endl;
@ -423,37 +441,17 @@ void unterOption_url_help(Settings *, char * argv0)
} }




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) int unterOption_search(Settings *settings, int argc, char **argv)
{ {
settings->modus = Modus::Search_MODUS; settings->modus = Modus::SEARCH_MODUS;


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"name", required_argument, nullptr, 'n'},
{"socks5-proxy", required_argument, nullptr, 'p'}, {"socks5-proxy", required_argument, nullptr, 'p'},


{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"colorless", no_argument, nullptr, 'c'}, {"colorless", no_argument, nullptr, 'c'},
{"debug-mode", no_argument, nullptr, 'd'}, {"debug-mode", no_argument, nullptr, 'd'},
{"debug-mode", no_argument, nullptr, 'd'},
{"exactly-writing", no_argument, nullptr, 'e'}, {"exactly-writing", no_argument, nullptr, 'e'},
{"update", no_argument, nullptr, 'u'}, {"update", no_argument, nullptr, 'u'},


@ -463,12 +461,6 @@ int unterOption_search(Settings *settings, int argc, char **argv)


while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'n':
if(optarg)
settings->name = optarg;
if(settings->debugMode)
std::cout << "Name: " << settings->name << std::endl;
break;
case 'p': { case 'p': {
if(!optarg || std::string(optarg) == "") if(!optarg || std::string(optarg) == "")
break; break;
@ -494,7 +486,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
} }
break; break;
case 'h': case 'h':
unterOption_search_help(settings, argv[0]); unterOption_search_help();
return -1; return -1;
case 'c': case 'c':
settings->colorless = true; settings->colorless = true;
@ -517,23 +509,34 @@ int unterOption_search(Settings *settings, int argc, char **argv)
std::cout << "Update die Liste: true" << std::endl; std::cout << "Update die Liste: true" << std::endl;
break; break;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " search [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " search --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " search --help“ liefert weitere Informationen." << std::endl;
return 21; return 21;
} }
} }
if(settings->debugMode)
std::cout << "Modus: Search_MODUS" << std::endl;
return 0;


//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(Settings *, char *argv0) void unterOption_search_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " search [ Parameter & {-n [Name] / -u} ]..." << std::endl std::cout << "Usage: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl
<< " " << getProgramName() << " search [-u, --update]" << std::endl
<< "Parameter:" << 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-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl
<< "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl << "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl
<< "\t-c, --colorless" << std::endl << "\t-c, --colorless" << std::endl
@ -550,8 +553,147 @@ void unterOption_search_help(Settings *, char *argv0)
} }




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) bool dirExists(std::string dir)
{ {
struct stat sb; struct stat sb;
return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false; 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 );
}


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;
}


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
}

View File

@ -7,11 +7,19 @@
#include <sstream> #include <sstream>
#include <sys/stat.h> #include <sys/stat.h>


#include <limits.h> // PATH_MAX
#include <unistd.h> // readlink()

#ifdef _WIN32
#include <windows.h>
#endif

enum Modus { enum Modus {
EXIT = -1, EXIT = -1,
DEFAULT_MODUS = 0, DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1, DIRECT_LINK_MODUS = 1,
Search_MODUS = 2, SEARCH_MODUS = 2,
INFO_MODUS = 3


}; };


@ -27,8 +35,8 @@ struct Settings {
serienListPath = "/tmp/SerienListe", serienListPath = "/tmp/SerienListe",
proxy_ip = "127.0.0.1", proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng", languages = "GerDub,GerSub,Eng",
genaueHoster = "", genaueHoster = "Vivo,GoUnlimited",
version = "2.0.0", version = "2.1.2",
outputFilePath = "", outputFilePath = "",
default_checkDirPath = "", default_checkDirPath = "",
default_Searchmuster = "S%Staffel%E%Folge%"; default_Searchmuster = "S%Staffel%E%Folge%";
@ -44,27 +52,33 @@ struct Settings {
stopSeason = 0, stopSeason = 0,
proxy_port = 9050, proxy_port = 9050,
default_maxDirs = 20; default_maxDirs = 20;
const char pathSymbol = '/'; char pathSymbol = '/';


}; };


int manageParameter(Settings &settings, int argc, char ** argv); int manageParameter(Settings &settings, int argc, char ** argv);
std::string getProgramName(char * argv0); std::string getProgramName();
int compare(std::string All_Options_with_komma_between, std::string input); int compare(std::string All_Options_with_komma_between, std::string input);
void setPaths(Settings &settings, std::string executablePathTo); void setPaths(Settings &settings);
bool dirExists(std::string dir); bool dirExists(std::string dir);


int unterOption_help(Settings * settings, char *argv0); std::string getexepath();
void setPathSymbol(Settings &settings);


int unterOption_help();


int unterOption_default(Settings * settings, int argc, char **argv); int unterOption_default(Settings * settings, int argc, char **argv);
void unterOption_default_help(Settings * settings, char * argv0); void unterOption_default_help();


int unterOption_url(Settings * settings, int argc, char **argv); int unterOption_url(Settings * settings, int argc, char **argv);
void unterOption_url_help(Settings * settings, char *argv0); void unterOption_url_help();


int unterOption_search(Settings * settings, int argc, char **argv); int unterOption_search(Settings * settings, int argc, char **argv);
void unterOption_search_help(Settings * settings, char *argv0); void unterOption_search_help();


int unterOption_info(Settings * settings, int argc, char **argv);
void unterOption_info_help();




#endif // PARAMETERMANAGER_H #endif // PARAMETERMANAGER_H

View File

@ -10,19 +10,21 @@ ProgramManager::~ProgramManager()


} }


int ProgramManager::start(Settings settings) int ProgramManager::start(Settings *settings)
{ {
pageManager.setProxy(settings.proxy_ip, settings.proxy_port); pageManager.setProxy(settings->proxy_ip, settings->proxy_port);
pageManager.setCookieFilePath(settings.cookieFilePath); pageManager.setCookieFilePath(settings->cookieFilePath);
pageManager.setDebugMode(settings.debugMode); pageManager.setDebugMode(settings->debugMode);


switch (settings.modus) { switch (settings->modus) {
case Modus::DEFAULT_MODUS: case Modus::DEFAULT_MODUS:
return defaultModus(&settings); return defaultModus(settings);
case Modus::DIRECT_LINK_MODUS: case Modus::DIRECT_LINK_MODUS:
return directLinkModus(&settings); return directLinkModus(settings);
case Modus::Search_MODUS: case Modus::SEARCH_MODUS:
return searchModus(&settings); return searchModus(settings);
case Modus::INFO_MODUS:
return infoModus(settings);
default: default:
return -1; return -1;
} }
@ -44,22 +46,32 @@ int ProgramManager::defaultModus(Settings *settings)
std::cout << " > Use Path for Name: " << settings->default_checkDirPath << " -> " << settings->name << std::endl; std::cout << " > Use Path for Name: " << settings->default_checkDirPath << " -> " << settings->name << std::endl;
} }
} if(settings->name == "") { } if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben: Missing Parameter -n [Name]." << std::endl; std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl;
return 27; return 27;
} }
} }


//Überprüfe ob ein Muster existiert:
if(settings->default_Searchmuster == "") {
std::cout << " => Error: [-m]: Kein Muster angegeben." << std::endl;
return 31;
}


//Liste alle Dateien in dem Ornder von -C auf und speichere diese //Liste alle Dateien in dem Ornder von -C auf und speichere diese
std::string dirFiles; std::string dirFiles;
if(settings->default_checkDirPath != "") if(settings->default_checkDirPath != "")
if(listDir(dirFiles, settings->default_checkDirPath, settings->default_maxDirs ) != 0) if(listDir(dirFiles, settings->default_checkDirPath, settings->default_maxDirs ) != 0)
return 28; return 28;

//Entferne von der liste das \n am ende //Entferne von der liste das \n am ende
if(dirFiles.length() > 0) if(dirFiles.length() > 0)
dirFiles.pop_back(); dirFiles.pop_back();


//Wenn Debug Mode, gib die Liste aus //Wenn Debug Mode, gib die Liste aus
if(settings->debugMode) if(settings->debugMode && settings->default_checkDirPath != "")
std::cout << " > [-C] Files:\n" << dirFiles << std::endl; std::cout << " > [-C] Files:\n" << dirFiles << std::endl;


//Führe Function aus, die überprüft ob die serie existiert //Führe Function aus, die überprüft ob die serie existiert
@ -145,7 +157,9 @@ int ProgramManager::directLinkModus(Settings *settings)
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);


if(settings->name == "") { if(settings->name == "") {
std::cout << "Kein(e) Link(s) angegeben: Missing Parameter -u [Url]." << std::endl; std::cout << " => Error: Kein(e) Link(s) angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "„" << getProgramName() << " url --help“ liefert weitere Informationen." << std::endl;
return 76; return 76;
} }


@ -157,7 +171,7 @@ int ProgramManager::directLinkModus(Settings *settings)


while (getline(iStrStream, line).good()) { while (getline(iStrStream, line).good()) {
if(line.find("https://s.to/redirect/") == std::string::npos) { if(line.find("https://s.to/redirect/") == std::string::npos) {
std::cout << "Invalid Redirect Link: '" << line << "'" << std::endl; std::cout << " => Error: Invalid Redirect Link: '" << line << "'" << std::endl;
continue; continue;
} }
else if(convertLink(pageManager.replace(line, "https://s.to", ""), &accountManager, settings) != 0) else if(convertLink(pageManager.replace(line, "https://s.to", ""), &accountManager, settings) != 0)
@ -169,17 +183,18 @@ int ProgramManager::directLinkModus(Settings *settings)


int ProgramManager::searchModus(Settings *settings) int ProgramManager::searchModus(Settings *settings)
{ {

if(settings->search_wantUpdate) { if(settings->search_wantUpdate) {
int res = searchModus_update(settings) ; int res = searchModus_update(settings) ;
if( res == 0) if( res == 0)
std::cout << "Erfolgreich geupdatet: Die Serienliste ist nun auf dem neusten Stand." << std::endl; std::cout << "Erfolgreich geupdatet: Die Serienliste ist nun auf dem neusten Stand." << std::endl;
else else
std::cout << "Das updaten der Serienliste ist fehlgeschlagen." << std::endl; std::cout << "Error: Das updaten der Serienliste ist fehlgeschlagen." << std::endl;
return res; return res;


} else if(settings->name == "") { } else if(settings->name == "") {
std::cout << "Kein Name angegeben: Missing Parameter -n [Name]." << std::endl; std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName() << " search --help“ liefert weitere Informationen." << std::endl;
return 27; return 27;
} }


@ -191,7 +206,7 @@ int ProgramManager::searchModus(Settings *settings)
else { else {
ifs.open(settings->serienListPath); ifs.open(settings->serienListPath);
if(!ifs.is_open()) { if(!ifs.is_open()) {
perror("Couldn't open SerienList file after update again."); perror(" => Error: Couldn't open SerienList file after update again.");
return 434; return 434;
} }
std::cout << "Erfolgreich gedownloadet." << std::endl; std::cout << "Erfolgreich gedownloadet." << std::endl;
@ -201,9 +216,11 @@ int ProgramManager::searchModus(Settings *settings)
//Save file in string: //Save file in string:
std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());


//Suche alle Möglichkeiten
std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower); std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower);
serienListe.clear(); serienListe.clear(); // Speicher freigeben


//Text mit Farben versehen
if(!settings->colorless) { if(!settings->colorless) {
for (size_t pos = pageManager.upper_string( finds ).find( pageManager.upper_string( settings->name ), 0); for (size_t pos = pageManager.upper_string( finds ).find( pageManager.upper_string( settings->name ), 0);
pos != std::string::npos; pos != std::string::npos;
@ -211,12 +228,16 @@ int ProgramManager::searchModus(Settings *settings)
finds.insert(pos, ( (finds.find(settings->name, pos) == pos) ? "\033[32m" : "\033[36m" ) ).insert(pos + settings->name.length() + strlen("\033[37m"), "\033[0m"); finds.insert(pos, ( (finds.find(settings->name, pos) == pos) ? "\033[32m" : "\033[36m" ) ).insert(pos + settings->name.length() + strlen("\033[37m"), "\033[0m");
} }



//Ausgabe
if(finds == "") {
std::cout << " => Für '" << settings->name << "' wurde(n) keine Serie(n) gefunden." << std::endl;
return 0;
}
std::stringstream strstream(finds); std::stringstream strstream(finds);
std::string line; std::string line;
std::cout << "Für '" << settings->name << "' wurde(n) folgende Serie(n) gefunden: " << std::endl; std::cout << " => Für '" << settings->name << "' wurde(n) folgende Serie(n) gefunden: " << std::endl;
while (getline(strstream, line)) { while (getline(strstream, line)) {
std::cout << " > " << line.substr(line.find("|", line.find("/")) + 1, line.length() - line.find("|", line.find("/")) -1 ) std::cout << " > " << line.substr(line.find("|", line.find("/")) + 1, line.length() - line.find("|", line.find("/")) -1 )
<< "\t[" << line.substr(line.find("/") + 1, line.find("|", line.find("/")) - line.find("/") - 1) << "]" << "\t[" << line.substr(line.find("/") + 1, line.find("|", line.find("/")) - line.find("/") - 1) << "]"
<< ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl; << ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl;
} }
@ -224,11 +245,138 @@ int ProgramManager::searchModus(Settings *settings)
return 0; return 0;
} }


int ProgramManager::infoModus(Settings *settings)
{
if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName() << " info --help“ liefert weitere Informationen." << std::endl;
return 27;
}

//Führe Function aus, die überprüft ob die serie existiert
std::string nameInUrl = pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch.
searchModus(settings);
return 25;
}

//Finde Anzahl der Staffel heraus:
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
return 32;

//speicher (zahl -1), ab da wo /staffel-x nicht mehr vorkommt
int maxStaffel = pageManager.counterContains(tmp_reply.html, "/staffel-%i");

//Um namen der Folge für jede Staffel zu bekommen
for (int staffel = 1; staffel <= maxStaffel; ++staffel) {
Reply tmpReply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel));
if(tmpReply.html == "-1")
return 40;
std::cout << " > Die Staffel " << staffel << " hat " << pageManager.counterContains(tmp_reply.html, "/episode-%i") << " Folge(n)." << std::endl;

}

//Datum & FSK
std::string line = pageManager.grep(tmp_reply.html, "<small> (<span itemprop=\"startDate\"><a");
if(line == "") {
std::cout << " => Error: Konnte '<small> (<span itemprop=\"startDate\"><a' nicht finden." << std::endl;
return 83;
}

std::string startStopDates[2];
size_t pos = 0, pos2 = 0;

for (int i = 0; i < 2; ++i) {
if( (pos = line.find("href=")) == std::string::npos ) {
std::cout << " => Error: Konnte 'href=' nicht finden." << std::endl;
return 84;
} else
line.erase(0, pos + 5);

if( (pos = line.find(">")) == std::string::npos ) {
std::cout << " => Error: Konnte '>' nicht finden." << std::endl;
return 85;
} else if ((pos2 = line.find("</a>")) == std::string::npos ) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 86;
}
startStopDates[i] = line.substr(pos + 1, pos2 - pos -1);
}

if( (pos = line.find("data-fsk=\"")) == std::string::npos ) {
std::cout << " => Error: Konnte 'data-fsk=\"' nicht finden." << std::endl;
return 87;
} else if ((pos2 = line.find("\" class=\"fsk")) == std::string::npos ) {
std::cout << " => Error: Konnte '\" class=\"fsk' nicht finden." << std::endl;
return 86;
}
std::string fsk = line.substr(pos + 10, pos2 -pos - 10);

//Deskription
if( (pos = tmp_reply.html.find("data-full-description=")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-full-description=' nicht finden." << std::endl;
return 83;
} else if ((pos2 = tmp_reply.html.find("\">", pos)) == std::string::npos ) {
std::cout << " => Error: Konnte '\">' nicht finden." << std::endl;
return 86;
}
std::string description = pageManager.replace( pageManager.replace( tmp_reply.html.substr(pos + 23, pos2 - pos - 23), "\n", "" ), "<br />", "" );

//Genres
std::vector<std::string> genres;
line = pageManager.grep(tmp_reply.html, "\"genre\">");
if(line == "") {
std::cout << " => Error: Konnte '\"genre\">' nicht finden." << std::endl;
return 87;
}
for (pos = line.find("\"genre\">"); pos != std::string::npos; pos = line.find("\"genre\">", pos + 7)) {
if( (pos2 = line.find("</a>", pos)) == std::string::npos) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 89;
}
genres.push_back(line.substr(pos + 8, pos2 - pos - 8));
}

//CoverLink
line = pageManager.grep(tmp_reply.html, "title=\"Cover");
if( (pos = line.find("data-src=\"")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-src=\"' nicht finden." << std::endl;
return 90;
} else if ((pos2 = line.find("\"", pos + 10)) == std::string::npos ) {
std::cout << " => Error: Konnte '\"' nicht finden." << std::endl;
return 86;
}
std::string coverLink = line.substr(pos + 10, pos2 - pos -10);




std::cout << "Produktion von " << startStopDates[0] << " bis " << startStopDates[1] << std::endl
<< "FSK: " << fsk << std::endl
<< "Cover Bild: " << coverLink << std::endl
<< "Genre(s): " << std::flush;
for( const auto &e : genres)
std::cout << e << " ";

std::cout << std::endl << "\nBeschreibung: " << description << std::endl;



return 0;
}

int ProgramManager::searchModus_update(Settings *settings) int ProgramManager::searchModus_update(Settings *settings)
{ {
Reply reply = pageManager.getServerRequest("https://s.to/serien"); Reply reply = pageManager.getServerRequest("https://s.to/serien");
if(reply.html == "-1") if(reply.html == "-1")
return 21; return 21;
else if(reply.html.find("</html>") == std::string::npos ) {
std::cout << " => Error: Konnte </html> in searchModus_update() nicht finden." << std::endl;
return 22;
}


std::string serienListe = pageManager.replace( pageManager.grep( reply.html, "data-alternative-title" ), "</li>", "\n" ); std::string serienListe = pageManager.replace( pageManager.grep( reply.html, "data-alternative-title" ), "</li>", "\n" );


@ -260,8 +408,18 @@ int ProgramManager::searchModus_update(Settings *settings)
//...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n... //...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n...


serienListe += line + "\n"; serienListe += line + "\n";
} serienListe.pop_back(); }
if(serienListe.length() > 0)
serienListe.pop_back();


//Anzahl der Serien/Zeilen vorher:
ssize_t countBef = 0;
std::ifstream myFileBef(settings->serienListPath);
if(myFileBef.is_open())
for(countBef = 0; std::getline(myFileBef,line); countBef++);
myFileBef.close();

//Schreibe die Liste in das TextFile
std::ofstream ofs(settings->serienListPath, std::ios::trunc); std::ofstream ofs(settings->serienListPath, std::ios::trunc);
if(!ofs.is_open()) { if(!ofs.is_open()) {
perror("Konnte SerienListe-Datei nicht öffnen"); perror("Konnte SerienListe-Datei nicht öffnen");
@ -270,6 +428,14 @@ int ProgramManager::searchModus_update(Settings *settings)
ofs << serienListe << std::endl; ofs << serienListe << std::endl;
ofs.close(); ofs.close();


//Anzahl der Zeile nachher
ssize_t countAf = 0;
std::ifstream myFileAf(settings->serienListPath);
if(myFileAf.is_open())
for(countAf = 0; std::getline(myFileAf,line); countAf++);
myFileAf.close();

std::cout << "Serienunterschied: " << ( ((countAf - countBef) > 0) ? "+" : "") << countAf - countBef << " Serien." << std::endl;
return 0; return 0;
} }


@ -326,7 +492,8 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou
else { else {
std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl
<< "Alle Links:" << std::endl << "Alle Links:" << std::endl
<< allLinks << std::endl; << pageManager.replace( pageManager.replace( pageManager.replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
"data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\"") << std::endl;
if(pageManager.writeToFile(settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) if(pageManager.writeToFile(settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
return 138; return 138;
} }
@ -345,16 +512,16 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou
continue; continue;


} else { } else {
std::cout << " => " << folgenID << ": " << green << newUrl << "\033[0m" << std::endl; std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << green << newUrl << "\033[0m" << std::endl;
if(settings->outputFilePath != "") if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath,folgenID + newUrl) != 0) if(pageManager.writeToFile(settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0)
return 108; return 108;
return 0; return 0;
} }
} }
std::cout << " => " << folgenID << ": " << red << "https://s.to" << redirectLink << "\033[0m" << std::endl; std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << red << "https://s.to" << redirectLink << "\033[0m" << std::endl;
if(settings->outputFilePath != "") if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath, folgenID + redirectLink) != 0) if(pageManager.writeToFile(settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0)
return 114; return 114;
return 0; return 0;
} }

View File

@ -1,8 +1,8 @@
#ifndef MANAGEPROGRAM_H #ifndef MANAGEPROGRAM_H
#define MANAGEPROGRAM_H #define MANAGEPROGRAM_H


#include "parameterManager.h"
#include "pageManager.h" #include "pageManager.h"
#include "parameterManager.h"
#include "accountManager.h" #include "accountManager.h"
#include <unistd.h> #include <unistd.h>


@ -14,13 +14,14 @@ class ProgramManager
public: public:
ProgramManager(); ProgramManager();
~ProgramManager(); ~ProgramManager();
int start(Settings setting); int start(Settings *setting);
int listDir(std::string &list, std::string path, int maxDepth); int listDir(std::string &list, std::string path, int maxDepth);


private: private:
int defaultModus(Settings * settings); int defaultModus(Settings * settings);
int directLinkModus(Settings * settings); int directLinkModus(Settings * settings);
int searchModus(Settings * settings); int searchModus(Settings * settings);
int infoModus(Settings * settings);


PageManager pageManager; PageManager pageManager;



View File

@ -1,5 +1,5 @@
#include "parameterManager.h"
#include "programManager.h" #include "programManager.h"
#include "parameterManager.h"




int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -3,7 +3,7 @@


#include <iostream> #include <iostream>
// if complied for windows; everything is in */projectfolder/curl/ // if complied for windows; everything is in */projectfolder/curl/
#include </home/markus/Qt/S_New4/curl/curl.h> #include <curl/curl.h>
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>

View File

@ -1,8 +1,11 @@
#include "parameterManager.h" #include "parameterManager.h"


void setPaths(Settings &settings, std::string executablePathTo) void setPaths(Settings &settings)
{ {
//Path settings //Path settings
std::string executablePathTo = getexepath();
std::cout << "Path " << executablePathTo << std::endl;

executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) ); 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(!dirExists(executablePathTo + "src" + settings.pathSymbol))
@ -17,32 +20,31 @@ void setPaths(Settings &settings, std::string executablePathTo)


} }



int manageParameter(Settings &settings, int argc, char **argv) int manageParameter(Settings &settings, int argc, char **argv)
{ {
//Path settings //Path settings
setPaths(settings, argv[0]); setPathSymbol(settings);
settings.argv0 = argv[0]; setPaths(settings);


if(argc < 2) { if(argc < 2) {
std::cout << " => Error: Keine Unteroption angegeben." << std::endl; std::cout << " => Error: Keine Unteroption angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
return 1; return 1;
} }


int res = compare("--help\ndefault\nurl\n--version\nsearch", argv[1]); int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo", argv[1]);
if(res != 1) { if(res != 1) {
std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[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::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl;
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl;
return 2; return 2;
} }


if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
return unterOption_help(&settings, argv[0]); return unterOption_help();


} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) { } else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
@ -60,9 +62,9 @@ int manageParameter(Settings &settings, int argc, char **argv)
argv[1][0] = '\0'; argv[1][0] = '\0';
return unterOption_search(&settings, argc, argv); return unterOption_search(&settings, argc, argv);


} else if (false) { } else if (strncmp(argv[1], "info", strlen(argv[1])) == 0) {

argv[1][0] = '\0';
//return 0; return unterOption_info(&settings, argc, argv);


} else { } else {
std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
@ -70,9 +72,9 @@ int manageParameter(Settings &settings, int argc, char **argv)
} }
} }


int unterOption_help(Settings *, char * argv0) int unterOption_help()
{ {
std::cout << "Aufruf: " << getProgramName(argv0) << " [Unteroption] [PARAMETER]" << std::endl << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl << std::endl;
std::cout << "Unteroptionen:" << std::endl std::cout << "Unteroptionen:" << std::endl
<< "\t„--help“\tListe aller Unteroptionen" << std::endl << "\t„--help“\tListe aller Unteroptionen" << std::endl
<< "\t„--version“\tVersion des Programmes" << std::endl << "\t„--version“\tVersion des Programmes" << std::endl
@ -253,11 +255,11 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_default_help(settings, argv[0]); unterOption_default_help();
return -1; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl;
return -1; return -1;
} }
} }
@ -279,9 +281,9 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
return 0; return 0;
} }


void unterOption_default_help(Settings *, char * argv0) void unterOption_default_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " default [OPTION]... [NAME]..." << std::endl std::cout << "Usage: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl
<< "Parameter:" << std::endl << std::endl << "Parameter:" << std::endl << std::endl
<< " > Auswahloptionen:" << std::endl << " > Auswahloptionen:" << std::endl
<< "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl << "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl
@ -395,11 +397,11 @@ int unterOption_url(Settings *settings, int argc, char **argv)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_url_help(settings, argv[0]); unterOption_url_help();
return -1; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " url --help“ liefert weitere Informationen." << std::endl;
return 21; return 21;
} }
} }
@ -423,9 +425,9 @@ int unterOption_url(Settings *settings, int argc, char **argv)
return 0; return 0;
} }


void unterOption_url_help(Settings *, char * argv0) void unterOption_url_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " url [OPTION]... [URL]..." << std::endl std::cout << "Usage: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl
<< "Parameter:" << std::endl << "Parameter:" << std::endl
<< "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl
<< "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl << "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl
@ -438,22 +440,10 @@ void unterOption_url_help(Settings *, char * argv0)


} }


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) int unterOption_search(Settings *settings, int argc, char **argv)
{ {
settings->modus = Modus::Search_MODUS; settings->modus = Modus::SEARCH_MODUS;


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
@ -462,7 +452,6 @@ int unterOption_search(Settings *settings, int argc, char **argv)
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"colorless", no_argument, nullptr, 'c'}, {"colorless", no_argument, nullptr, 'c'},
{"debug-mode", no_argument, nullptr, 'd'}, {"debug-mode", no_argument, nullptr, 'd'},
{"debug-mode", no_argument, nullptr, 'd'},
{"exactly-writing", no_argument, nullptr, 'e'}, {"exactly-writing", no_argument, nullptr, 'e'},
{"update", no_argument, nullptr, 'u'}, {"update", no_argument, nullptr, 'u'},


@ -497,7 +486,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
} }
break; break;
case 'h': case 'h':
unterOption_search_help(settings, argv[0]); unterOption_search_help();
return -1; return -1;
case 'c': case 'c':
settings->colorless = true; settings->colorless = true;
@ -520,8 +509,8 @@ int unterOption_search(Settings *settings, int argc, char **argv)
std::cout << "Update die Liste: true" << std::endl; std::cout << "Update die Liste: true" << std::endl;
break; break;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " search [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " search --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " search --help“ liefert weitere Informationen." << std::endl;
return 21; return 21;
} }
} }
@ -543,10 +532,10 @@ int unterOption_search(Settings *settings, int argc, char **argv)
return 0; return 0;
} }


void unterOption_search_help(Settings *, char *argv0) void unterOption_search_help()
{ {
std::cout << "Usage: " << getProgramName(argv0) << " search [OPTION]... [NAME]" << std::endl std::cout << "Usage: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl
<< " " << getProgramName(argv0) << " search [-u, --update]" << std::endl << " " << getProgramName() << " search [-u, --update]" << std::endl
<< "Parameter:" << std::endl << "Parameter:" << std::endl
<< "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl << "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl
<< "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl << "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl
@ -564,13 +553,147 @@ void unterOption_search_help(Settings *, char *argv0)
} }




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) bool dirExists(std::string dir)
{ {
struct stat sb; struct stat sb;
return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false; return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false;
} }


std::string getProgramName(const char *argv0) std::string getProgramName()
{ {
return std::string(argv0).erase(0, ( (std::string(argv0).find_last_of("/\\") != std::string::npos ) ? std::string(argv0).find_last_of("/\\") +1 : 0 ) ); return getexepath().erase(0, ( getexepath().find_last_of("/\\") != std::string::npos ) ? getexepath().find_last_of("/\\") +1 : 0 );
}


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;
}


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
} }

View File

@ -7,11 +7,19 @@
#include <sstream> #include <sstream>
#include <sys/stat.h> #include <sys/stat.h>


#include <limits.h> // PATH_MAX
#include <unistd.h> // readlink()

#ifdef _WIN32
#include <windows.h>
#endif

enum Modus { enum Modus {
EXIT = -1, EXIT = -1,
DEFAULT_MODUS = 0, DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1, DIRECT_LINK_MODUS = 1,
Search_MODUS = 2, SEARCH_MODUS = 2,
INFO_MODUS = 3


}; };


@ -31,8 +39,7 @@ struct Settings {
version = "2.1.2", version = "2.1.2",
outputFilePath = "", outputFilePath = "",
default_checkDirPath = "", default_checkDirPath = "",
default_Searchmuster = "S%Staffel%E%Folge%", default_Searchmuster = "S%Staffel%E%Folge%";
argv0 = "";


Modus modus = Modus::DEFAULT_MODUS; Modus modus = Modus::DEFAULT_MODUS;
bool colorless = false, bool colorless = false,
@ -45,27 +52,33 @@ struct Settings {
stopSeason = 0, stopSeason = 0,
proxy_port = 9050, proxy_port = 9050,
default_maxDirs = 20; default_maxDirs = 20;
const char pathSymbol = '/'; char pathSymbol = '/';


}; };


int manageParameter(Settings &settings, int argc, char ** argv); int manageParameter(Settings &settings, int argc, char ** argv);
std::string getProgramName(const char * argv0); std::string getProgramName();
int compare(std::string All_Options_with_komma_between, std::string input); int compare(std::string All_Options_with_komma_between, std::string input);
void setPaths(Settings &settings, std::string executablePathTo); void setPaths(Settings &settings);
bool dirExists(std::string dir); bool dirExists(std::string dir);


int unterOption_help(Settings * settings, char *argv0); std::string getexepath();
void setPathSymbol(Settings &settings);


int unterOption_help();


int unterOption_default(Settings * settings, int argc, char **argv); int unterOption_default(Settings * settings, int argc, char **argv);
void unterOption_default_help(Settings * settings, char * argv0); void unterOption_default_help();


int unterOption_url(Settings * settings, int argc, char **argv); int unterOption_url(Settings * settings, int argc, char **argv);
void unterOption_url_help(Settings * settings, char *argv0); void unterOption_url_help();


int unterOption_search(Settings * settings, int argc, char **argv); int unterOption_search(Settings * settings, int argc, char **argv);
void unterOption_search_help(Settings * settings, char *argv0); void unterOption_search_help();


int unterOption_info(Settings * settings, int argc, char **argv);
void unterOption_info_help();




#endif // PARAMETERMANAGER_H #endif // PARAMETERMANAGER_H

View File

@ -21,8 +21,10 @@ int ProgramManager::start(Settings *settings)
return defaultModus(settings); return defaultModus(settings);
case Modus::DIRECT_LINK_MODUS: case Modus::DIRECT_LINK_MODUS:
return directLinkModus(settings); return directLinkModus(settings);
case Modus::Search_MODUS: case Modus::SEARCH_MODUS:
return searchModus(settings); return searchModus(settings);
case Modus::INFO_MODUS:
return infoModus(settings);
default: default:
return -1; return -1;
} }
@ -45,8 +47,8 @@ int ProgramManager::defaultModus(Settings *settings)
} }
} if(settings->name == "") { } if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl; std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(settings->argv0.c_str()) << " default [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(settings->argv0.c_str()) << " default --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl;
return 27; return 27;
} }
} }
@ -156,8 +158,8 @@ int ProgramManager::directLinkModus(Settings *settings)


if(settings->name == "") { if(settings->name == "") {
std::cout << " => Error: Kein(e) Link(s) angegeben." << std::endl; std::cout << " => Error: Kein(e) Link(s) angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(settings->argv0.c_str()) << " url [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "„" << getProgramName(settings->argv0.c_str()) << " url --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " url --help“ liefert weitere Informationen." << std::endl;
return 76; return 76;
} }


@ -191,8 +193,8 @@ int ProgramManager::searchModus(Settings *settings)


} else if(settings->name == "") { } else if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl; std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(settings->argv0.c_str()) << " search [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName(settings->argv0.c_str()) << " search --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName() << " search --help“ liefert weitere Informationen." << std::endl;
return 27; return 27;
} }


@ -243,6 +245,129 @@ int ProgramManager::searchModus(Settings *settings)
return 0; return 0;
} }


int ProgramManager::infoModus(Settings *settings)
{
if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "„" << getProgramName() << " info --help“ liefert weitere Informationen." << std::endl;
return 27;
}

//Führe Function aus, die überprüft ob die serie existiert
std::string nameInUrl = pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch.
searchModus(settings);
return 25;
}

//Finde Anzahl der Staffel heraus:
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
return 32;

//speicher (zahl -1), ab da wo /staffel-x nicht mehr vorkommt
int maxStaffel = pageManager.counterContains(tmp_reply.html, "/staffel-%i");

//Um namen der Folge für jede Staffel zu bekommen
for (int staffel = 1; staffel <= maxStaffel; ++staffel) {
Reply tmpReply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel));
if(tmpReply.html == "-1")
return 40;
std::cout << " > Die Staffel " << staffel << " hat " << pageManager.counterContains(tmp_reply.html, "/episode-%i") << " Folge(n)." << std::endl;

}

//Datum & FSK
std::string line = pageManager.grep(tmp_reply.html, "<small> (<span itemprop=\"startDate\"><a");
if(line == "") {
std::cout << " => Error: Konnte '<small> (<span itemprop=\"startDate\"><a' nicht finden." << std::endl;
return 83;
}

std::string startStopDates[2];
size_t pos = 0, pos2 = 0;

for (int i = 0; i < 2; ++i) {
if( (pos = line.find("href=")) == std::string::npos ) {
std::cout << " => Error: Konnte 'href=' nicht finden." << std::endl;
return 84;
} else
line.erase(0, pos + 5);

if( (pos = line.find(">")) == std::string::npos ) {
std::cout << " => Error: Konnte '>' nicht finden." << std::endl;
return 85;
} else if ((pos2 = line.find("</a>")) == std::string::npos ) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 86;
}
startStopDates[i] = line.substr(pos + 1, pos2 - pos -1);
}

if( (pos = line.find("data-fsk=\"")) == std::string::npos ) {
std::cout << " => Error: Konnte 'data-fsk=\"' nicht finden." << std::endl;
return 87;
} else if ((pos2 = line.find("\" class=\"fsk")) == std::string::npos ) {
std::cout << " => Error: Konnte '\" class=\"fsk' nicht finden." << std::endl;
return 86;
}
std::string fsk = line.substr(pos + 10, pos2 -pos - 10);

//Deskription
if( (pos = tmp_reply.html.find("data-full-description=")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-full-description=' nicht finden." << std::endl;
return 83;
} else if ((pos2 = tmp_reply.html.find("\">", pos)) == std::string::npos ) {
std::cout << " => Error: Konnte '\">' nicht finden." << std::endl;
return 86;
}
std::string description = pageManager.replace( pageManager.replace( tmp_reply.html.substr(pos + 23, pos2 - pos - 23), "\n", "" ), "<br />", "" );

//Genres
std::vector<std::string> genres;
line = pageManager.grep(tmp_reply.html, "\"genre\">");
if(line == "") {
std::cout << " => Error: Konnte '\"genre\">' nicht finden." << std::endl;
return 87;
}
for (pos = line.find("\"genre\">"); pos != std::string::npos; pos = line.find("\"genre\">", pos + 7)) {
if( (pos2 = line.find("</a>", pos)) == std::string::npos) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 89;
}
genres.push_back(line.substr(pos + 8, pos2 - pos - 8));
}

//CoverLink
line = pageManager.grep(tmp_reply.html, "title=\"Cover");
if( (pos = line.find("data-src=\"")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-src=\"' nicht finden." << std::endl;
return 90;
} else if ((pos2 = line.find("\"", pos + 10)) == std::string::npos ) {
std::cout << " => Error: Konnte '\"' nicht finden." << std::endl;
return 86;
}
std::string coverLink = line.substr(pos + 10, pos2 - pos -10);




std::cout << "Produktion von " << startStopDates[0] << " bis " << startStopDates[1] << std::endl
<< "FSK: " << fsk << std::endl
<< "Cover Bild: " << coverLink << std::endl
<< "Genre(s): " << std::flush;
for( const auto &e : genres)
std::cout << e << " ";

std::cout << std::endl << "\nBeschreibung: " << description << std::endl;



return 0;
}

int ProgramManager::searchModus_update(Settings *settings) int ProgramManager::searchModus_update(Settings *settings)
{ {
Reply reply = pageManager.getServerRequest("https://s.to/serien"); Reply reply = pageManager.getServerRequest("https://s.to/serien");

View File

@ -1,8 +1,8 @@
#ifndef MANAGEPROGRAM_H #ifndef MANAGEPROGRAM_H
#define MANAGEPROGRAM_H #define MANAGEPROGRAM_H


#include "parameterManager.h"
#include "pageManager.h" #include "pageManager.h"
#include "parameterManager.h"
#include "accountManager.h" #include "accountManager.h"
#include <unistd.h> #include <unistd.h>


@ -21,6 +21,7 @@ private:
int defaultModus(Settings * settings); int defaultModus(Settings * settings);
int directLinkModus(Settings * settings); int directLinkModus(Settings * settings);
int searchModus(Settings * settings); int searchModus(Settings * settings);
int infoModus(Settings * settings);


PageManager pageManager; PageManager pageManager;



BIN
release/LIBCURL.DLL Executable file

Binary file not shown.