From 825045d5e64352df4f5cddd03b32a71844d54aeb Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 15 Aug 2019 12:50:27 +0200 Subject: [PATCH 01/10] bevore start --- programManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/programManager.h b/programManager.h index 35ac267..11af9fa 100644 --- a/programManager.h +++ b/programManager.h @@ -9,6 +9,7 @@ #include #include + class ProgramManager { public: From 3f0664082145672a0ff010c017dc31d31a24404c Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 15 Aug 2019 14:20:06 +0200 Subject: [PATCH 02/10] create thread funct & start & waiter -- works but: next-season & more thread than episodes etc... --- S_New4.pro | 4 +- pageManager.cpp | 4 +- parameterManager.h | 1 + programManager.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++- programManager.h | 26 +++++++++ 5 files changed, 162 insertions(+), 6 deletions(-) diff --git a/S_New4.pro b/S_New4.pro index 4fad636..67761ac 100644 --- a/S_New4.pro +++ b/S_New4.pro @@ -1,8 +1,8 @@ QT -= gui -#LIBS += -lcurl +LIBS += -lcurl #LIBS += -LC:\Users\Markus\Desktop\S_New4\S_New4\curl -lcurl -LIBS += -L/home/markus/Qt/S_New4/curl -lcurl +#LIBS += -L/home/markus/Qt/S_New4/curl -lcurl CONFIG += c++11 console diff --git a/pageManager.cpp b/pageManager.cpp index 9042f81..2bd6a47 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -3,12 +3,14 @@ PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) : sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath) { - + curl_global_init(CURL_GLOBAL_ALL); } PageManager::~PageManager() { remove(cookieFilePath.c_str()); + curl_global_cleanup(); + } void PageManager::setProxy(std::string ip, int port) diff --git a/parameterManager.h b/parameterManager.h index 2d2f23c..b0244d2 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -53,6 +53,7 @@ struct Settings { proxy_port = 9050, default_maxDirs = 20; char pathSymbol = '/'; + unsigned maxThreads = 2; }; diff --git a/programManager.cpp b/programManager.cpp index ef60211..c2fed99 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -1,6 +1,8 @@ #include "programManager.h" + ProgramManager::ProgramManager() + : nextThread(0) { } @@ -30,10 +32,83 @@ int ProgramManager::start(Settings *settings) } } +void * threadFunction(void * KA) { + ka * myka = reinterpret_cast(KA); + myka->returnValue=""; + myka->exitState=0; + + + + Reply tmp_reply = myka->pageManager->getServerRequest(myka->pageManager->UrlPraefix + myka->nameInUrl + "/staffel-" + std::to_string(myka->staffel) + "/episode-" + std::to_string(myka->folge)); + if(tmp_reply.html == "-1") + return myka->setState(10); + std::string allLinks = myka->pageManager->getLinks(tmp_reply.html); + std::string Link = myka->pageManager->chooseHosterLink(allLinks, myka->settings->genaueHoster, myka->settings->languages); + + if(myka->settings->debugMode) + std::cout << " > Thread " << myka->id << allLinks << std::endl << ( (Link == "") ? "" : " -> Link: 'https://s.to") << Link << ( (Link == "") ? "" : "'\n" ); + + + + + std::string folgenID = std::string((myka->staffel == -1 || myka->folge == -1 ) ? "" : "S" + std::string( (myka->staffel < 10) ? "0" : "" ) + std::to_string(myka->staffel) + + "E" + std::string( (myka->folge < 10) ? "0" : "" ) + std::to_string( myka->folge ) ); + std::string green = ((myka->settings->colorless) ? "" : "\033[32m"), + red = ((myka->settings->colorless) ? "" : "\033[31m"), + orange =((myka->settings->colorless) ? "" : "\033[33m"), + blue = ((myka->settings->colorless) ? "" : "\033[34m"); + + if(Link == "") { + if(allLinks == "") { + myka->returnValue = " => " + red + "KEINEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m"; + if(myka->pageManager->writeToFile(myka->settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) + return myka->setState(14); + } + else { + myka->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m" + "\n" + + "Alle Links:" + "\n" + + myka->pageManager->replace( myka->pageManager->replace( myka->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ), + "data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\""); + if(myka->pageManager->writeToFile(myka->settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) + return myka->setState(15); + } + return myka->setState(0); + } + + for (int i = 1; i <= 3; ++i) { + std::string newUrl = myka->pageManager->getUrlAfterRedirect("https://s.to" + Link); + if (newUrl == "-1") { + return myka->setState(16); + } else if(newUrl.find("/s.to/redirect/") != std::string::npos ) { + if(myka->settings->debugMode) + std::cout << " > Thread " << myka->id << "Warnung: Redirect Link nach umwandlung (Capcha?) --> Neuer Account" << std::endl; + if(myka->pageManager->login(myka->accountManager->getNextAccount()) != 0) + return myka->setState(17); + continue; + + } else { + myka->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + "\033[0m"; + if(myka->settings->outputFilePath != "") + if(myka->pageManager->writeToFile(myka->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) + return myka->setState(18); + return myka->setState(0); + } + } + myka->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + "\033[0m"; + if(myka->settings->outputFilePath != "") + if(myka->pageManager->writeToFile(myka->settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0) + return myka->setState(19); + return myka->setState(0); + +} + + + int ProgramManager::defaultModus(Settings *settings) { AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); + //Wenn kein Name mit -n Angegeben wurde: if(settings->name == "") { if(settings->default_checkDirPath != "") { @@ -81,8 +156,28 @@ int ProgramManager::defaultModus(Settings *settings) searchModus(settings); return 25; } - //Sonst melde sich bei s.to an und speicher cookies. - else if (pageManager.login(accountManager.getNextAccount()) != 0) + + + for (unsigned i = 0; i < settings->maxThreads; ++i) { + ka * newKa = new ka(i); + PageManager * pm = new PageManager; + pm->setProxy(settings->proxy_ip, settings->proxy_port); + pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + pm->setDebugMode(settings->debugMode); + newKa->pageManager = pm; + + newKa->settings = settings; + newKa->accountManager = &accountManager; + newKa->nameInUrl = nameInUrl; + threadList.push_back(newKa); + } + + + + + + // melde bei s.to an und speicher cookies. + if (pageManager.login(accountManager.getNextAccount()) != 0) //---------------------------------------- return 29; pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name); @@ -122,9 +217,34 @@ int ProgramManager::defaultModus(Settings *settings) } } + + if(nextThread < threadList.size()) { + threadList[nextThread]->setData(staffel, folge); + if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast(threadList[nextThread])) != 0 ) { + perror("pthread_creat failed"); + return 48; + } + nextThread++; + } else { + for( auto &e : threadList) { + pthread_join(e->thread, nullptr); + if(e->exitState != 0) { + std::cout << "Error: Thread gab error zurück." << std::endl; + return e->exitState; + } + std::cout << "NachThread: " << e->returnValue << std::endl; + } + nextThread=0; + folge--; + continue; + } + + + + /* tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge)); if(tmp_reply.html == "-1") - return 47; + return 50; std::string allLinks = pageManager.getLinks(tmp_reply.html); std::string Link = pageManager.chooseHosterLink(allLinks, settings->genaueHoster, settings->languages); @@ -133,6 +253,13 @@ int ProgramManager::defaultModus(Settings *settings) if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0) return 51; + + */ + + + + + if(folge == settings->stopEpisode && settings->stopSeason < 1) // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde. return 0; else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) // stoppe wenn stopfolge = folge && stopstaffel == staffel diff --git a/programManager.h b/programManager.h index 11af9fa..f2bafa5 100644 --- a/programManager.h +++ b/programManager.h @@ -9,6 +9,30 @@ #include #include +#include + + +struct ka +{ + ka(unsigned id) : id(id) {} + unsigned id; + pthread_t thread; + std::string nameInUrl, returnValue; + int staffel, folge, exitState; + Settings * settings; + AccountManager * accountManager; + PageManager * pageManager; + + void * setState(int state) { + this->exitState = state; + return nullptr; + } + void setData(int staffel, int folge) { this->staffel = staffel; this->folge = folge; } + + +}; + + class ProgramManager { @@ -25,6 +49,8 @@ private: int infoModus(Settings * settings); PageManager pageManager; + std::vector threadList; + unsigned nextThread; int convertLink(std::string redirectLink, AccountManager *accountManager, Settings * settings, int Staffel = -1, int Folge = -1, std::string allLinks = "NOT_EMPTY"); int searchModus_update(Settings * settings); From 2cafff45a15b6511d9625197ccccb0b09cdaf88a Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 15 Aug 2019 14:37:16 +0200 Subject: [PATCH 03/10] fix stop --- parameterManager.h | 2 +- programManager.cpp | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/parameterManager.h b/parameterManager.h index b0244d2..ea05108 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -53,7 +53,7 @@ struct Settings { proxy_port = 9050, default_maxDirs = 20; char pathSymbol = '/'; - unsigned maxThreads = 2; + unsigned maxThreads = 4; }; diff --git a/programManager.cpp b/programManager.cpp index c2fed99..b4a41fd 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -218,6 +218,7 @@ int ProgramManager::defaultModus(Settings *settings) } + //Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector... if(nextThread < threadList.size()) { threadList[nextThread]->setData(staffel, folge); if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast(threadList[nextThread])) != 0 ) { @@ -225,7 +226,7 @@ int ProgramManager::defaultModus(Settings *settings) return 48; } nextThread++; - } else { + } else { // Sonnst warte bis alle Fertig sind und restarte die Folge for( auto &e : threadList) { pthread_join(e->thread, nullptr); if(e->exitState != 0) { @@ -260,10 +261,28 @@ int ProgramManager::defaultModus(Settings *settings) - if(folge == settings->stopEpisode && settings->stopSeason < 1) // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde. + if(folge == settings->stopEpisode && settings->stopSeason < 1) { // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde. + for( auto &e : threadList) { + pthread_join(e->thread, nullptr); + if(e->exitState != 0) { + std::cout << "Error: Thread gab error zurück." << std::endl; + return e->exitState; + } + std::cout << "NachThread: " << e->returnValue << std::endl; + } return 0; - else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) // stoppe wenn stopfolge = folge && stopstaffel == staffel + } + else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) { // stoppe wenn stopfolge = folge && stopstaffel == staffel + for( auto &e : threadList) { + pthread_join(e->thread, nullptr); + if(e->exitState != 0) { + std::cout << "Error: Thread gab error zurück." << std::endl; + return e->exitState; + } + std::cout << "NachThread: " << e->returnValue << std::endl; + } return 0; + } } //Setzte Startepisode zurück für nächste Staffel settings->startEpisode = 1; @@ -275,6 +294,18 @@ int ProgramManager::defaultModus(Settings *settings) } } + + for( auto &e : threadList) { + pthread_join(e->thread, nullptr); + if(e->exitState != 0) { + std::cout << "Error: Thread gab error zurück." << std::endl; + return e->exitState; + } + std::cout << "NachThread: " << e->returnValue << std::endl; + } + + + std::cout << " > Fertig" << std::endl; return 0; } From 34ec60e6a2bae8137c405b4f56e04ac4b9b17764 Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 12:29:18 +0200 Subject: [PATCH 04/10] add new accounts --- accountManager.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/accountManager.cpp b/accountManager.cpp index d752946..b2cf290 100644 --- a/accountManager.cpp +++ b/accountManager.cpp @@ -66,7 +66,29 @@ int AccountManager::writeDefault(std::string path) std::cout << "Erstelle Datei mit Accounts unter: " << path << "..." < Date: Fri, 16 Aug 2019 13:32:13 +0200 Subject: [PATCH 05/10] works ok; but needs tests --- pageManager.cpp | 2 +- parameterManager.cpp | 1 - parameterManager.h | 2 +- programManager.cpp | 171 ++++++++++++++++++++----------------------- programManager.h | 5 +- 5 files changed, 87 insertions(+), 94 deletions(-) diff --git a/pageManager.cpp b/pageManager.cpp index 2bd6a47..4d190a4 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -43,7 +43,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin char *url; std::string returnUrl; - std::cout << "Lade: '" << Url << "'..." << std::flush; + std::cout << "\33[2K\r" << "Lade: '" << Url << "'..." << std::flush; curl = curl_easy_init(); if(!curl) { diff --git a/parameterManager.cpp b/parameterManager.cpp index 2367128..c56df48 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -4,7 +4,6 @@ void setPaths(Settings &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) ); diff --git a/parameterManager.h b/parameterManager.h index ea05108..26dc80b 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -53,7 +53,7 @@ struct Settings { proxy_port = 9050, default_maxDirs = 20; char pathSymbol = '/'; - unsigned maxThreads = 4; + unsigned maxThreads = 5; }; diff --git a/programManager.cpp b/programManager.cpp index b4a41fd..600fdc6 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -103,12 +103,10 @@ void * threadFunction(void * KA) { } - int ProgramManager::defaultModus(Settings *settings) { AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); - //Wenn kein Name mit -n Angegeben wurde: if(settings->name == "") { if(settings->default_checkDirPath != "") { @@ -157,28 +155,30 @@ int ProgramManager::defaultModus(Settings *settings) return 25; } + //Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor + if(settings->maxThreads == 0) { + // melde bei s.to an und speicher cookies. + if (pageManager.login(accountManager.getNextAccount()) != 0) //---------------------------------------- + return 29; + } else { + for (unsigned i = 0; i < settings->maxThreads; ++i) { + ka * newKa = new ka(i); + PageManager * pm = new PageManager; + pm->setProxy(settings->proxy_ip, settings->proxy_port); + pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + pm->setDebugMode(settings->debugMode); + newKa->pageManager = pm; - for (unsigned i = 0; i < settings->maxThreads; ++i) { - ka * newKa = new ka(i); - PageManager * pm = new PageManager; - pm->setProxy(settings->proxy_ip, settings->proxy_port); - pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); - pm->setDebugMode(settings->debugMode); - newKa->pageManager = pm; - - newKa->settings = settings; - newKa->accountManager = &accountManager; - newKa->nameInUrl = nameInUrl; - threadList.push_back(newKa); + newKa->settings = settings; + newKa->accountManager = &accountManager; + newKa->nameInUrl = nameInUrl; + newKa->thread = 0; // Sonst error wenn join & nicht gesetzt + newKa->exitState = -1; + threadList.push_back(newKa); + } } - - - - - // melde bei s.to an und speicher cookies. - if (pageManager.login(accountManager.getNextAccount()) != 0) //---------------------------------------- - return 29; + //Write Name to File if -o is set pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name); //Finde die anzahl der staffel heraus: @@ -217,70 +217,49 @@ int ProgramManager::defaultModus(Settings *settings) } } - - //Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector... - if(nextThread < threadList.size()) { - threadList[nextThread]->setData(staffel, folge); - if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast(threadList[nextThread])) != 0 ) { - perror("pthread_creat failed"); - return 48; - } - nextThread++; - } else { // Sonnst warte bis alle Fertig sind und restarte die Folge - for( auto &e : threadList) { - pthread_join(e->thread, nullptr); - if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; - return e->exitState; + //Multihreading Mode + if(settings->maxThreads > 0) { + //Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector... + if(nextThread < threadList.size()) { + threadList[nextThread]->exitState = 0; + threadList[nextThread]->setData(staffel, folge); + if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast(threadList[nextThread])) != 0 ) { + perror("pthread_creat failed"); + return 48; } - std::cout << "NachThread: " << e->returnValue << std::endl; + nextThread++; + } else { // Sonnst warte bis alle Fertig sind und restarte die Folge + if(waitForThreads() != 0) + return 231; + nextThread=0; + folge--; + continue; } - nextThread=0; - folge--; - continue; + + } else { // Default Mode + tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge)); + if(tmp_reply.html == "-1") + return 50; + std::string allLinks = pageManager.getLinks(tmp_reply.html); + std::string Link = pageManager.chooseHosterLink(allLinks, settings->genaueHoster, settings->languages); + + 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) + return 51; + } - - - /* - tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge)); - if(tmp_reply.html == "-1") - return 50; - std::string allLinks = pageManager.getLinks(tmp_reply.html); - std::string Link = pageManager.chooseHosterLink(allLinks, settings->genaueHoster, settings->languages); - - 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) - return 51; - - - */ - - - - - if(folge == settings->stopEpisode && settings->stopSeason < 1) { // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde. - for( auto &e : threadList) { - pthread_join(e->thread, nullptr); - if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; - return e->exitState; - } - std::cout << "NachThread: " << e->returnValue << std::endl; - } + if(settings->maxThreads != 0) + if(waitForThreads() != 0) + return 261; return 0; - } - else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) { // stoppe wenn stopfolge = folge && stopstaffel == staffel - for( auto &e : threadList) { - pthread_join(e->thread, nullptr); - if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; - return e->exitState; - } - std::cout << "NachThread: " << e->returnValue << std::endl; - } + + } else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) { // stoppe wenn stopfolge = folge && stopstaffel == staffel + if(settings->maxThreads != 0) + if(waitForThreads() != 0) + return 267; return 0; } } @@ -294,22 +273,34 @@ int ProgramManager::defaultModus(Settings *settings) } } - - for( auto &e : threadList) { - pthread_join(e->thread, nullptr); - if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; - return e->exitState; - } - std::cout << "NachThread: " << e->returnValue << std::endl; - } - - + if(settings->maxThreads != 0) + if(waitForThreads() != 0) + return 292; std::cout << " > Fertig" << std::endl; return 0; } +int ProgramManager::waitForThreads() +{ + for( auto &e : threadList) { + if( e->exitState != -1 && pthread_join(e->thread, nullptr) == 0) { + if(e->exitState != 0) { + std::cout << "Error: Thread gab error zurück." << std::endl; + return e->exitState; + } else + if(e->returnValue != "") + std::cout << "(T" << e->id << ")" << e->returnValue << std::endl; + } + e->exitState = -1; + e->returnValue = ""; + e->setData(0, 0); + e->thread = 0; + } + return 0; +} + + int ProgramManager::directLinkModus(Settings *settings) { AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); diff --git a/programManager.h b/programManager.h index f2bafa5..8067407 100644 --- a/programManager.h +++ b/programManager.h @@ -15,6 +15,8 @@ struct ka { ka(unsigned id) : id(id) {} + ~ka() { std::cout << "Deskrtuktor" << std::endl; } + unsigned id; pthread_t thread; std::string nameInUrl, returnValue; @@ -29,7 +31,6 @@ struct ka } void setData(int staffel, int folge) { this->staffel = staffel; this->folge = folge; } - }; @@ -54,6 +55,8 @@ private: int convertLink(std::string redirectLink, AccountManager *accountManager, Settings * settings, int Staffel = -1, int Folge = -1, std::string allLinks = "NOT_EMPTY"); int searchModus_update(Settings * settings); + int waitForThreads(); + }; From ef88786e5763a83d148a916caccc7efc056a8c5c Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 14:34:44 +0200 Subject: [PATCH 06/10] setup getops --- pageManager.cpp | 1 - parameterManager.cpp | 33 +++++++++++++++++++++++++++------ parameterManager.h | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pageManager.cpp b/pageManager.cpp index 4d190a4..0222bd1 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -10,7 +10,6 @@ PageManager::~PageManager() { remove(cookieFilePath.c_str()); curl_global_cleanup(); - } void PageManager::setProxy(std::string ip, int port) diff --git a/parameterManager.cpp b/parameterManager.cpp index c56df48..8e54e01 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -79,7 +79,8 @@ int unterOption_help() << "\t„--version“\tVersion des Programmes" << std::endl << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl - << "\t„search“\tModus um Serien zu suchen." << std::endl; + << "\t„search“\tModus um Serien zu suchen." << std::endl + << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl; return -1; } @@ -103,8 +104,9 @@ int unterOption_default(Settings *settings, int argc, char ** argv) {"check-dir", required_argument, nullptr, 'C'}, {"check-muster", required_argument, nullptr, 'm'}, - {"check-max-dirs", required_argument, nullptr, 't'}, + {"check-max-dirs", required_argument, nullptr, 'D'}, + {"threads", required_argument, nullptr, 't'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, @@ -114,7 +116,7 @@ int unterOption_default(Settings *settings, int argc, char ** argv) }; - while( ( c = getopt_long (argc, argv, "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:D:t:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': { if(!optarg || std::string(optarg) == "") @@ -218,18 +220,31 @@ int unterOption_default(Settings *settings, int argc, char ** argv) if(settings->debugMode) std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; break; - case 't': + case 'D': if(!optarg) break; settings->default_maxDirs = atoi(optarg); if(std::to_string(settings->default_maxDirs) != std::string(optarg) ) { - std::cout << "[-t]: Invalid Count: " << optarg << std::endl; + std::cout << "[-D]: Invalid Count: " << optarg << std::endl; return 18; } if(settings->debugMode) std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; break; + case 't': + if(!optarg) + break; + settings->maxThreads = static_cast(atoi(optarg)); + if(std::to_string(settings->maxThreads) != std::string(optarg) ) { + std::cout << "[-t]: Ungültige Zahl: " << optarg << std::endl; + return 18; + } + if(settings->debugMode) + std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; + + break; + case 'C': if(!optarg) break; @@ -311,7 +326,7 @@ void unterOption_default_help() << "\t -> Muster mit dem Überprüft wird, ob diese Folge in einem Ordner ist. Default: S%Staffel%E%Folge%" << std::endl << "\t -> %Staffel% ist eine Variable für die Staffel mit 0 + Staffel, wenn Staffel < 10. " << std::endl << "\t -> %Folge% ist eine Variable für die Folge mit 0 + Folge, wenn Folge < 10. " << std::endl - << "\t-t, --check-max-dirs" << std::endl + << "\t-D, --check-max-dirs" << std::endl << "\t -> Maximale Anzahl der Ordner, die auf Dateien untersucht werden. Default: 20" << std::endl << std::endl << " > Durchlaufoptionen:" << std::endl @@ -329,6 +344,12 @@ void unterOption_default_help() << "\t-S [Staffel], --stop-season [Staffel]" << std::endl << "\t -> Das Programm stopt mit dieser Staffel. Beachte Verwendung mit -E." << std::endl << "\t Zum deaktivieren Staffel <= 0 verwenden. Default: 0" << std::endl + << " > Multi-Thrading Optionen:" << std::endl + << "\t-t [maxThreads], --threads [maxThreads]" << std::endl + << "\t -> Das Programm startet für jede Folge einen eigenen Thread," << std::endl + << "\t -> bis die maximale Anzahl ereicht wurde. Dann wartet es auf" << std::endl + << "\t -> das enden aller Threads und fängt dann wieder von vorne an." << std::endl + << "\t -> Zum deaktivieren von Multithreading '0' verwenden. Default: 0" << std::endl << std::endl << " > Help-Optionen" << std::endl << "\t-h, --help" << std::endl; diff --git a/parameterManager.h b/parameterManager.h index 26dc80b..f218d7c 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -53,7 +53,7 @@ struct Settings { proxy_port = 9050, default_maxDirs = 20; char pathSymbol = '/'; - unsigned maxThreads = 5; + unsigned maxThreads = 0; }; From 031a0b2bc984360789cec3de4f7332719737c9d7 Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 14:35:12 +0200 Subject: [PATCH 07/10] fix debug message --- parameterManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parameterManager.cpp b/parameterManager.cpp index 8e54e01..2bf1eed 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -241,7 +241,7 @@ int unterOption_default(Settings *settings, int argc, char ** argv) return 18; } if(settings->debugMode) - std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; + std::cout << "MaxThreads: " << settings->maxThreads << std::endl; break; From 4194eafb9c1ea9ad86552a88a141a42bbb66d2a2 Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 20:12:25 +0200 Subject: [PATCH 08/10] add clen function & delete threadVector & remove remove in desteructor --- pageManager.cpp | 11 +++++----- pageManager.h | 6 ++---- parameterManager.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++-- parameterManager.h | 2 ++ programManager.cpp | 25 +++++++++++----------- programManager.h | 8 +++---- 6 files changed, 73 insertions(+), 30 deletions(-) diff --git a/pageManager.cpp b/pageManager.cpp index 0222bd1..697b7cb 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -8,8 +8,8 @@ PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) PageManager::~PageManager() { - remove(cookieFilePath.c_str()); curl_global_cleanup(); + std::cout << "des" << std::endl; } void PageManager::setProxy(std::string ip, int port) @@ -42,7 +42,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin char *url; std::string returnUrl; - std::cout << "\33[2K\r" << "Lade: '" << Url << "'..." << std::flush; + std::cout << ( "\33[2K\rLade: '" + Url + "'..." ) << std::flush; curl = curl_easy_init(); if(!curl) { @@ -68,14 +68,13 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin for (int timeout = 1; timeout <= maxTimeout; ++timeout) { /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); - std::cout << "\33[2K\r" << std::flush; if(res != CURLE_OK) { if(timeout == maxTimeout) { - perror((std::string(" => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str()); + perror((std::string("\33[2K\r => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str()); return Reply("-1"); } else { - std::cout << "\33[2K\r" << " => Warning: Versuch " << timeout << " von " << maxTimeout << ": curl_easy_perform() failed: " << curl_easy_strerror(res) << std::flush; + std::cout << std::string( "\33[2K\r => Warning: Versuch " + std::to_string(timeout) + " von " + std::to_string(maxTimeout) + ": curl_easy_perform() failed: " + curl_easy_strerror(res) )<< std::flush; sleep(1); } } else { @@ -87,7 +86,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin //Get Url res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); if( res != CURLE_OK || !url ) { - perror((std::string(" => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); + perror((std::string("\33[2K\r => Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str()); return Reply("-1"); } else returnUrl=url; diff --git a/pageManager.h b/pageManager.h index 5e41e2c..679b8d4 100644 --- a/pageManager.h +++ b/pageManager.h @@ -1,16 +1,14 @@ #ifndef MANAGEPAGE_H #define MANAGEPAGE_H -#include -// if complied for windows; everything is in */projectfolder/curl/ +#include "accountManager.h" + #include #include #include #include - #include -#include "accountManager.h" struct Reply { Reply() {} diff --git a/parameterManager.cpp b/parameterManager.cpp index 2bf1eed..ac01e68 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -32,7 +32,7 @@ int manageParameter(Settings &settings, int argc, char **argv) return 1; } - int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo", argv[1]); + int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); if(res != 1) { std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" : std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl; @@ -65,6 +65,11 @@ int manageParameter(Settings &settings, int argc, char **argv) argv[1][0] = '\0'; return unterOption_info(&settings, argc, argv); + } else if (strncmp(argv[1], "clean", strlen(argv[1])) == 0) { + argv[1][0] = '\0'; + unterOption_clean(&settings, argc, argv); + return -1; + } else { std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; @@ -80,7 +85,8 @@ int unterOption_help() << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl << "\t„search“\tModus um Serien zu suchen." << std::endl - << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl; + << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl + << "\t„clean“\tModus um Cookie-Files zu löschen." << std::endl; return -1; } @@ -717,3 +723,44 @@ void setPathSymbol(Settings &settings) settings.pathSymbol = '\\'; #endif } + +bool fileExists (const std::string& name) { + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode)); +} + +void unterOption_clean(Settings * settings, int argc, char **argv) +{ + if(argc > 1) + if(strcmp(argv[1], "--help") == 0) { + std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl; + std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl; + return; + } + + unsigned count = 0; + if(fileExists(settings->cookieFilePath)) { + if(remove(settings->cookieFilePath.c_str()) != 0) { + std::cout << "Das löschen von " << settings->cookieFilePath << " ist fehlgeschlagen: " << errno << std::endl; + return; + } else { + count++; + } + } + + for (unsigned i = 0; i < UINT_MAX && fileExists(settings->cookieFilePath + std::to_string(i)); i++) { + if(remove( (settings->cookieFilePath + std::to_string(i)).c_str() ) != 0) { + std::cout << "Das löschen von " << settings->cookieFilePath + std::to_string(i) << " ist fehlgeschlagen: " << errno << std::endl; + return; + } else { + count++; + } + } + + if(count == 0) + std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl; + else + std::cout << " => " << count << " Cookie-Files gelöscht." << std::endl; + + return; +} diff --git a/parameterManager.h b/parameterManager.h index f218d7c..340d7e6 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -81,5 +81,7 @@ void unterOption_search_help(); int unterOption_info(Settings * settings, int argc, char **argv); void unterOption_info_help(); +void unterOption_clean(Settings * settings, int argc, char **argv); + #endif // PARAMETERMANAGER_H diff --git a/programManager.cpp b/programManager.cpp index 600fdc6..a5d30d9 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -9,7 +9,11 @@ ProgramManager::ProgramManager() ProgramManager::~ProgramManager() { - + for(auto e : threadList) { + delete e->pageManager; + delete e; + e = nullptr; + } } int ProgramManager::start(Settings *settings) @@ -162,18 +166,13 @@ int ProgramManager::defaultModus(Settings *settings) return 29; } else { for (unsigned i = 0; i < settings->maxThreads; ++i) { - ka * newKa = new ka(i); - PageManager * pm = new PageManager; - pm->setProxy(settings->proxy_ip, settings->proxy_port); - pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + PageManager * pm = new PageManager("socks5://" + settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i )); pm->setDebugMode(settings->debugMode); - newKa->pageManager = pm; - newKa->settings = settings; - newKa->accountManager = &accountManager; - newKa->nameInUrl = nameInUrl; - newKa->thread = 0; // Sonst error wenn join & nicht gesetzt - newKa->exitState = -1; + //pm->setProxy(settings->proxy_ip, settings->proxy_port); + //pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + + ka * newKa = new ka(i, 0, nameInUrl, -1, settings, &accountManager, pm); threadList.push_back(newKa); } } @@ -286,11 +285,11 @@ int ProgramManager::waitForThreads() for( auto &e : threadList) { if( e->exitState != -1 && pthread_join(e->thread, nullptr) == 0) { if(e->exitState != 0) { - std::cout << "Error: Thread gab error zurück." << std::endl; + std::cout << "\33[2K\r => Error: Thread gab error zurück." << std::endl; return e->exitState; } else if(e->returnValue != "") - std::cout << "(T" << e->id << ")" << e->returnValue << std::endl; + std::cout << ("\33[2K\r(T" + std::to_string(e->id) + ")" + e->returnValue ) << std::endl; } e->exitState = -1; e->returnValue = ""; diff --git a/programManager.h b/programManager.h index 8067407..5673f86 100644 --- a/programManager.h +++ b/programManager.h @@ -4,18 +4,16 @@ #include "pageManager.h" #include "parameterManager.h" #include "accountManager.h" -#include - #include -#include +#include #include struct ka { - ka(unsigned id) : id(id) {} - ~ka() { std::cout << "Deskrtuktor" << std::endl; } + ka(unsigned id, pthread_t init, std::string nameinUrl,int exitStateInit, Settings * settings, AccountManager * accountMg, PageManager * pM) + : id(id), thread(init), nameInUrl(nameinUrl), exitState(exitStateInit), settings(settings), accountManager(accountMg), pageManager(pM) {} unsigned id; pthread_t thread; From eb951fb1655132c2a6e533a908e1cb2681a5780c Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 20:15:35 +0200 Subject: [PATCH 09/10] melde nicht mehr am anfang immer an, da versucht wird letztes cookiefile zu verwenden --- pageManager.cpp | 1 - parameterManager.cpp | 6 +++--- programManager.cpp | 10 ++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pageManager.cpp b/pageManager.cpp index 697b7cb..a71d8ad 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -9,7 +9,6 @@ PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) PageManager::~PageManager() { curl_global_cleanup(); - std::cout << "des" << std::endl; } void PageManager::setProxy(std::string ip, int port) diff --git a/parameterManager.cpp b/parameterManager.cpp index ac01e68..5a87db0 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -85,8 +85,8 @@ int unterOption_help() << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl << "\t„search“\tModus um Serien zu suchen." << std::endl - << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl - << "\t„clean“\tModus um Cookie-Files zu löschen." << std::endl; + << "\t„info“\t\tModus um Infos einer Serien zu bekommen." << std::endl + << "\t„clean“\t\tModus um Cookie-Files zu löschen." << std::endl; return -1; } @@ -760,7 +760,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv) if(count == 0) std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl; else - std::cout << " => " << count << " Cookie-Files gelöscht." << std::endl; + std::cout << " => " << count << " Cookie-File(s) gelöscht." << std::endl; return; } diff --git a/programManager.cpp b/programManager.cpp index a5d30d9..ff3ec41 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -159,12 +159,14 @@ int ProgramManager::defaultModus(Settings *settings) return 25; } - //Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor + /* Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor if(settings->maxThreads == 0) { // melde bei s.to an und speicher cookies. if (pageManager.login(accountManager.getNextAccount()) != 0) //---------------------------------------- return 29; - } else { + }*/ + + if(settings->maxThreads > 0) { for (unsigned i = 0; i < settings->maxThreads; ++i) { PageManager * pm = new PageManager("socks5://" + settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i )); pm->setDebugMode(settings->debugMode); @@ -314,8 +316,8 @@ int ProgramManager::directLinkModus(Settings *settings) std::istringstream iStrStream( pageManager.replace( settings->name, ",", "\n" ) + "\n" ); std::string line; - if(pageManager.login(accountManager.getNextAccount()) != 0) - return 71; + //if(pageManager.login(accountManager.getNextAccount()) != 0) + // return 71; while (getline(iStrStream, line).good()) { if(line.find("https://s.to/redirect/") == std::string::npos) { From b1bd343a8529efa4e7de7e8fef561a40de57954b Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 Aug 2019 20:15:54 +0200 Subject: [PATCH 10/10] v2.2.0 --- parameterManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parameterManager.h b/parameterManager.h index 340d7e6..e48b17b 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -36,7 +36,7 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng", genaueHoster = "Vivo,GoUnlimited", - version = "2.1.2", + version = "2.2.0", outputFilePath = "", default_checkDirPath = "", default_Searchmuster = "S%Staffel%E%Folge%";