add debug messages

This commit is contained in:
Markus 2019-10-08 20:03:15 +02:00
parent f4918c5322
commit 6a74f47102
2 changed files with 229 additions and 59 deletions

View File

@ -49,10 +49,16 @@ int setPaths(Settings &settings)
int manageParameter(Settings &settings, int argc, char **argv)
{
//Path settings
if(setPaths(settings) != 0)
if(setPaths(settings) != 0) {
if(settings.debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": setPaths f() failed." << std::endl;
return -1;
if(loadDefaulOptions(settings) != 0)
}
if(loadDefaulOptions(settings) != 0) {
if(settings.debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": loadDefaulOptions f() failed." << std::endl;
return 28;
}

if(argc < 2) {
std::cout << " => Error: Keine Unteroption angegeben." << std::endl;

View File

@ -51,8 +51,11 @@ void * threadFunction(void * data) {

Reply tmp_reply = myThreadData->pageManager->getServerRequest(myThreadData->pageManager->UrlPraefix + myThreadData->nameInUrl
+ "/staffel-" + std::to_string(myThreadData->staffel) + "/episode-" + std::to_string(myThreadData->folge));
if(tmp_reply.html == "-1")
if(tmp_reply.html == "-1") {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": getServerRequest Function reurns -1." << std::endl;
return myThreadData->setState(10);
}
std::string allLinks = myThreadData->pageManager->getLinks(tmp_reply.html);
std::string Link = myThreadData->pageManager->chooseHosterLink(allLinks, myThreadData->settings->genaueHoster, myThreadData->settings->languages);

@ -62,7 +65,8 @@ void * threadFunction(void * data) {



std::string folgenID = std::string((myThreadData->staffel == -1 || myThreadData->folge == -1 ) ? "" : "S" + std::string( (myThreadData->staffel < 10) ? "0" : "" ) + std::to_string(myThreadData->staffel)
std::string folgenID = std::string((myThreadData->staffel == -1 || myThreadData->folge == -1 ) ? "" : "S"
+ std::string( (myThreadData->staffel < 10) ? "0" : "" ) + std::to_string(myThreadData->staffel)
+ "E" + std::string( (myThreadData->folge < 10) ? "0" : "" ) + std::to_string( myThreadData->folge ) );
std::string green = ((myThreadData->settings->colorless) ? "" : "\033[32m"),
red = ((myThreadData->settings->colorless) ? "" : "\033[31m"),
@ -70,45 +74,77 @@ void * threadFunction(void * data) {
blue = ((myThreadData->settings->colorless) ? "" : "\033[34m");

if(Link == "") {
//Wenn gar keine Links vorhanden sind:
if(allLinks == "") {
myThreadData->returnValue = " => " + red + "KEINEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m";
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(14);
}
else {
}
//Wenn nur kein passender Link gefunden wurde:
} else {
myThreadData->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m" + "\n"
+ "Alle Links:" + "\n"
+ myThreadData->pageManager->replace( myThreadData->pageManager->replace( myThreadData->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
+ myThreadData->pageManager->replace(
myThreadData->pageManager->replace( myThreadData->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
"data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\"");
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,
std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(15);
}
}

if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": closeThread, no (good) Link was found." << std::endl;
return myThreadData->setState(0);
}

for (int i = 1; i <= 3; ++i) {
std::string newUrl = myThreadData->pageManager->getUrlAfterRedirect("https://s.to" + Link);
if (newUrl == "-1") {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": getUrlAfterRedirect Function failed: returned -1." << std::endl;
return myThreadData->setState(16);

// Get redirect link after getUrlAfterRedirect function
} else if(newUrl.find("/s.to/redirect/") != std::string::npos ) {
if(myThreadData->settings->debugMode)
std::cout << " > Thread " << myThreadData->id << "Warnung: Redirect Link nach umwandlung (Capcha?) --> Neuer Account" << std::endl;
if(myThreadData->pageManager->login(myThreadData->accountManager->getNextAccount()) != 0)
if(myThreadData->pageManager->login(myThreadData->accountManager->getNextAccount()) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": login Function failed." << std::endl;
return myThreadData->setState(17);
}
continue;

// get NO-Redirect Link after getUrlAfterRedirect Function
} else {
myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + "\033[0m";
if(myThreadData->settings->outputFilePath != "")
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0)
if(myThreadData->settings->outputFilePath != "") {
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(18);
}
}
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": get a NO Redirect Link after function: Good! => return 0." << std::endl;
return myThreadData->setState(0);
}
}

myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + "\033[0m";
if(myThreadData->settings->outputFilePath != "")
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0)
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(19);
}
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": 3 Times to convert fails, but return 0." << std::endl;
return myThreadData->setState(0);

}
@ -135,40 +171,63 @@ int ProgramManager::waitForThreads()
int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName)
{
std::string finds;
if(searchModus(settings, &finds) != 0)
if(searchModus(settings, &finds) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Function searchModus returned error." << std::endl;
return 24;
else if(finds.find("/") == std::string::npos || finds.find("|") == std::string::npos || finds.find("\n") != std::string::npos)
}
else if(finds.find("/") == std::string::npos || finds.find("|") == std::string::npos || finds.find("\n") != std::string::npos) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": searchModus's returnValue contains no / or |, or " << std::endl
<< "\t\t\tcontains an \\n => more than 1 Serie found => error." << std::endl;
return 45;
}
else if ( (finds = finds.substr( finds.find("/") + 1, finds.find("|", finds.find("/")) - finds.find("/") -1) ) == "" ) {
std::cout << " => Error: Konnte den Namen aus der zurückgegebenen Zeile nicht extrahieren." << std::endl;
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Return value from searchModus.subStr(pos(/)-> next |, after /) is ''." << std::endl;
return 46;
} else if ( (newName = pageManager.checkName(finds)) == "-1") {
std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl;
return 47;
}
std::cout << "Ist das deine gewünschte Serie? Drücke nur Enter um fortzufahren: " << std::flush;
std::getline(std::cin, finds);
if ( finds != "") {
std::cout << " => Abbruch..." << std::endl;
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": User tipped an Value => wrong serie." << std::endl;
return 48;
} else if ( (newName = pageManager.checkName(finds)) == "-1") {
std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl;
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Extracted Name from searchModus is invalid." << std::endl;
return 47;
} else {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Use new SerienName: '" << newName << "'." << std::endl;
return 0;
}
return 0;
}

int ProgramManager::checkLastUpdate(Settings *settings)
{
if(settings->updateWarningDays == 0)
if(settings->updateWarningDays == 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": In settings: upDateWaring is deaktivated(seted to 0)." << std::endl;
return 0;
}

std::ifstream ifs(settings->lastUpdateDateFilePath);
if(!ifs.is_open()) {
perror(("Konnte die Datei '" + settings->lastUpdateDateFilePath + "' nicht öffnen").c_str());
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Failed to open Last Update Date File:'" << settings->lastUpdateDateFilePath << "'." << std::endl;
return 1;
}
std::string line;
ssize_t difDays = 0;
if(!std::getline(ifs, line).good()) {
perror("GetLine from Date failed");
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Get the first Line of the LastUpdateDate File failed." << std::endl;
return 2;

} else if( ( ( difDays = static_cast<long long>(pageManager.getDate()) - atoll(line.c_str()) )) >= settings->updateWarningDays) {
@ -176,6 +235,8 @@ int ProgramManager::checkLastUpdate(Settings *settings)
<< std::endl << " Mit '" << settings->programName << " search -u' kannst du die Liste aktualisieren." << "\033[0m" << std::endl;;
}

if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Exit with success." << std::endl;
return 0;
}

@ -212,8 +273,11 @@ int ProgramManager::defaultModus(Settings *settings)
//Liste alle Dateien in dem Ornder von -C auf und speichere diese
std::string dirFiles;
if(settings->default_checkPath != "")
if(listDir(dirFiles, settings->default_checkPath, settings->default_maxDirs ) != 0)
if(listDir(dirFiles, settings->default_checkPath, settings->default_maxDirs ) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": listDir failed." << std::endl;
return 28;
}
if(dirFiles.length() > 0) //Entferne von der liste das \n am ende
dirFiles.pop_back();
if(settings->debugMode && settings->default_checkPath != "") //Wenn Debug Mode, gib die Liste aus
@ -224,8 +288,11 @@ int ProgramManager::defaultModus(Settings *settings)
std::string nameInUrl =pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch && Wenn nur 1ne dacnn frag ob es diese ist.
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0)
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": sucheNach_1_Serien failed or found more options." << std::endl;
return 202;
}
}

/* Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor
@ -255,29 +322,40 @@ int ProgramManager::defaultModus(Settings *settings)

//Write Name to File if -o is set und kein TXT-FILE angegeben wird
if(settings->outputFilePath != "" && !fileExists( settings->default_checkPath ))
if(pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name) != 0)
if(pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": writeToFile Function fails when write Name." << std::endl;
return 31;
}

//Finde die anzahl der staffel heraus:
//download html von der startpage einer serie
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
if(tmp_reply.html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest failed, when download startpage." << std::endl;
return 32;
}

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

if(settings->debugMode)
std::cout << " > Die Serie " << settings->name << " hat " << maxStaffel << " Staffeln." << std::endl;

//For every season
//wenn starterstaffel 0 ist, also letzte staffel, dann ersetzte variable mit maxStaffeln
if(settings->startSeason == 0)
settings->startSeason = maxStaffel;

//For every season
for (int staffel = settings->startSeason; staffel <= maxStaffel; ++staffel) {
//Test for stopping Program caused -E, -S
if(staffel > settings->stopSeason && settings->stopSeason > 0) {
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
if(waitForThreads() != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Wait for the Threads failed." << std::endl;
return 261;
}
if(settings->debugMode)
std::cout << " > Stoppe, weil Staffel: " << staffel << " > StopStaffel " << settings->stopSeason << std::endl;
std::cout << " > Fertig, da Staffel " << staffel << " größer ist als StopStaffel " << settings->stopSeason << std::endl;
@ -285,28 +363,40 @@ int ProgramManager::defaultModus(Settings *settings)
}

//Find out number of all episodes
tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel));
if(tmp_reply.html == "-1")
if( (tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel))).html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest failed when download season page." << std::endl;
return 40;
}
int maxFolge = pageManager.counterContains(tmp_reply.html, "/episode-%i");

//Print seasons
if(settings->debugMode)
std::cout << " > Die Staffel " << staffel << " hat " << maxFolge << " Folgen." << std::endl;

//for every episode
for (int folge = settings->startEpisode; folge <= maxFolge; ++folge) {

// stoppe wenn stopfolge größer der folge ist und stopstaffel nicht gesetzt wurde. und stopepisode gröser 0, also aktiv ist
if(folge > settings->stopEpisode && settings->stopSeason < 1 && settings->stopEpisode > 0) {
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
if(waitForThreads() != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Wait for the Threads failed." << std::endl;
return 261;
}
std::cout << " > Fertig, da Folge " << folge << " größer ist als Stopfolge " << settings->stopEpisode << "."<< std::endl;
return 0;

} else if ( folge > settings->stopEpisode && staffel >= settings->stopSeason && settings->stopEpisode > 0) { // stoppe wenn stopfolge > folge && stopstaffel >= staffel und stopepisode gröser 0, also aktiv ist

// stoppe wenn stopfolge > folge && stopstaffel >= staffel und stopepisode gröser 0, also aktiv ist
} else if ( folge > settings->stopEpisode && staffel >= settings->stopSeason && settings->stopEpisode > 0) {
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
if(waitForThreads() != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Wait for the Threads failed." << std::endl;
return 267;
}
std::cout << " > Fertig, da Folge " << folge << " größer ist als Stopfolge " << settings->stopEpisode << std::endl
<< " und Staffel " << staffel << " größer gleich Stopstaffel " << settings->stopSeason << " ist." << std::endl;
return 0;
@ -330,21 +420,31 @@ int ProgramManager::defaultModus(Settings *settings)
threadList[nextThread]->setData(staffel, folge);
if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast<void*>(threadList[nextThread])) != 0 ) {
perror("pthread_creat failed");
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Create thread for redirect converting failed." << std::endl;
return 48;
}
++nextThread;
} else { // Sonnst warte bis alle Fertig sind und restarte die Folge
if(waitForThreads() != 0)
if(waitForThreads() != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Wait for the Threads failed." << std::endl;
return 231;
}
nextThread=0;
folge--;
continue;
}

} else { // Default Mode

// Default Mode
} else {
tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge));
if(tmp_reply.html == "-1")
if(tmp_reply.html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest failed when download episoden page." << std::endl;
return 50;
}
std::string allLinks = pageManager.getLinks(tmp_reply.html);
if(settings->genaueHoster == "*," && settings->debugMode) {
if(settings->debugMode)
@ -359,10 +459,15 @@ int ProgramManager::defaultModus(Settings *settings)
} else
line.erase(0, pos);
line.erase(line.find("\""));
if(convertLink(line, &accountManager, settings, staffel, folge, allLinks) != 0)
if(convertLink(line, &accountManager, settings, staffel, folge, allLinks) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": convertLink failed." << std::endl;
return 51;
}
}
//Stop beacause same episode every account can only 2 videos not 10-12
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Stop Program, because '*'-Hoster is inperformatnt: Every Account can only 2 Vidoes not 10-12." << std::endl;
return 0;

} else {
@ -370,8 +475,11 @@ int ProgramManager::defaultModus(Settings *settings)

if(settings->debugMode)
std::cout << allLinks << std::endl << ( (Link == "") ? "" : " -> Link: 'https://s.to") << Link << ( (Link == "") ? "" : "'\n" );
if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0)
if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": convert Link failed." << std::endl;
return 51;
}
}


@ -382,8 +490,11 @@ int ProgramManager::defaultModus(Settings *settings)
}

if(settings->maxThreads != 0)
if(waitForThreads() != 0)
if(waitForThreads() != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Wait for the Threads failed." << std::endl;
return 292;
}

std::cout << " > Fertig" << std::endl;
return 0;
@ -411,10 +522,14 @@ int ProgramManager::directLinkModus(Settings *settings)
std::cout << " => Error: Invalid Redirect Link: '" << line << "'" << std::endl;
continue;

} else if(convertLink(line.erase(0, ((line.find("s.to") == std::string::npos) ? 0 : line.find("s.to") + 4 )), &accountManager, settings) != 0)
} else if(convertLink(line.erase(0, ((line.find("s.to") == std::string::npos) ? 0 : line.find("s.to") + 4 )), &accountManager, settings) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": convert Link failed." << std::endl;
return 78;
}
}

if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Success." << std::endl;
return 0;
}

@ -424,8 +539,11 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
int res = searchModus_update(settings) ;
if(res == 0) {
std::cout << "Erfolgreich geupdatet: Die Serienliste ist nun auf dem neusten Stand." << std::endl;
if (settings->name == "")
if (settings->name == "") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": Stop after Update: No Name => Only Updating." << std::endl;
return 0;
}

} else {
std::cout << " => Error: Das updaten der Serienliste ist fehlgeschlagen." << std::endl;
@ -442,8 +560,11 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
std::ifstream ifs(settings->serienListPath);
if(!ifs.is_open()) {
std::cout << " => Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl;
if(searchModus_update(settings) != 0)
if(searchModus_update(settings) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": searchModus_update function failed." << std::endl;
return 354;
}
else {
ifs.open(settings->serienListPath);
if(!ifs.is_open()) {
@ -455,8 +576,11 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
}

//Check for last Update..
if(checkLastUpdate(settings) != 0)
if(checkLastUpdate(settings) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": checkLastUpdate function failed." << std::endl;
return -1;
}

//Save file in string:
std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@ -501,7 +625,8 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
<< "\t[" << line.substr(line.find("/") + 1, line.find("|", line.find("/")) - line.find("/") - 1) << "]"
<< ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl;
}

if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": success." << std::endl;
return 0;
}

@ -518,14 +643,20 @@ int ProgramManager::infoModus(Settings *settings)
std::string nameInUrl = pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch.
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0)
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": sucheNach_1_Serien function failed." << std::endl;
return 28;
}
}

//Finde Anzahl der Staffel heraus:
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
if(tmp_reply.html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest function failed: at homepage." << std::endl;
return 32;
}

//speicher (zahl -1), ab da wo /staffel-x nicht mehr vorkommt
int maxStaffel = pageManager.counterContains(tmp_reply.html, "/staffel-%i");
@ -533,8 +664,11 @@ int ProgramManager::infoModus(Settings *settings)
//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")
if(tmpReply.html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest function failed: at season page." << std::endl;
return 40;
}
std::cout << "Die Staffel " << staffel << " hat " << pageManager.counterContains(tmpReply.html, "/episode-%i") << " Folge(n)." << std::endl;

std::string html = tmpReply.html;
@ -685,7 +819,8 @@ int ProgramManager::infoModus(Settings *settings)
std::cout << std::endl << "\nBeschreibung: " << description << std::endl;



if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": success exit." << std::endl;
return 0;
}

@ -693,8 +828,11 @@ int ProgramManager::newsModus(Settings *settings)
{
size_t pos = 0;
std::string html = pageManager.getServerRequest("https://s.to/neue-episoden").html;
if(html == "-1")
if(html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest function failed." << std::endl;
return 1;
}

if( (pos = html.find("<div class=\"row\">")) == std::string::npos ) {
std::cout << " => Error: Konnte Position von '<div class=\"row\">'' nicht finden" <<std::endl;
@ -756,8 +894,11 @@ int ProgramManager::newsModus(Settings *settings)
int ProgramManager::searchModus_update(Settings *settings)
{
Reply reply = pageManager.getServerRequest("https://s.to/serien");
if(reply.html == "-1")
if(reply.html == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getServerRequest function failed." << std::endl;
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;
@ -768,8 +909,12 @@ int ProgramManager::searchModus_update(Settings *settings)
if(reply.html.find("\" href=\"") == std::string::npos ||
reply.html.find("<li><a data-alternative-title=\"") == std::string::npos ||
reply.html.find("/serie/stream/") == std::string::npos ||
reply.html.find("</a>") == std::string::npos)
reply.html.find("</a>") == std::string::npos) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__
<< ": hatml doesnt contain:' \" href=\" or <li><a data-alternative-title=\" or /serie/stream/ or </a> ' after preparing." << std::endl;
return 51;
}

//...\n<li><a data-alternative-title="" href="/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
serienListe = pageManager.replace(serienListe, "<li><a data-alternative-title=\"", "");
@ -868,6 +1013,7 @@ int ProgramManager::listDir(std::string &list,std::string path, int maxDepth)
return -1;
}
list = std::string((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

return 0;

} // Sonst normal Ordner listen
@ -916,43 +1062,61 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou
if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) {
if(allLinks == "") {
std::cout << " => " << red << "KEINEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl;
if(pageManager.writeToFile(settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
if(pageManager.writeToFile(settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 130;
}
else {
}
} else {
std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl
<< "Alle Links:" << 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) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 138;
}
}
//Remove this return ??
return 0;
}

for (int i = 1; i <= 3; ++i) {
std::string newUrl = pageManager.getUrlAfterRedirect("https://s.to" + redirectLink);
if (newUrl == "-1") {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": getUrlAfterRedirect f() failed." << std::endl;
return 102;
} else if(newUrl.find("/s.to/redirect/") != std::string::npos ) {
if(settings->debugMode)
std::cout << "Warnung: Redirect Link nach umwandlung (Capcha?) --> Neuer Account" << std::endl;
if(pageManager.login(accountManager->getNextAccount()) != 0)
if(pageManager.login(accountManager->getNextAccount()) != 0) {
if(settings->debugMode)
std::cerr << " => Debug In " << __FUNCTION__ << ": login f() failed." << std::endl;
return -1;
}
continue;

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