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