|
|
|
@@ -44,16 +44,12 @@ int ProgramManager::start(Settings *settings)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * threadFunction(void * data) {
|
|
|
|
|
ThreadData * myThreadData = reinterpret_cast<struct ThreadData*>(data);
|
|
|
|
|
int threadFunction(ThreadData * myThreadData) {
|
|
|
|
|
myThreadData->returnValue="";
|
|
|
|
|
myThreadData->exitState=0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
return myThreadData->setState(10);
|
|
|
|
|
return 10;
|
|
|
|
|
std::string allLinks = myThreadData->pageManager->getLinks(tmp_reply.html);
|
|
|
|
|
std::string Link = myThreadData->pageManager->chooseHosterLink(allLinks, myThreadData->settings->genaueHoster, myThreadData->settings->languages);
|
|
|
|
|
|
|
|
|
@@ -61,8 +57,6 @@ void * threadFunction(void * data) {
|
|
|
|
|
std::cout << " > Thread " << myThreadData->id << allLinks << std::endl << ( (Link == "") ? "" : " -> Link: 'https://s.to") << Link << ( (Link == "") ? "" : "'\n" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"),
|
|
|
|
@@ -74,7 +68,7 @@ void * threadFunction(void * data) {
|
|
|
|
|
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)
|
|
|
|
|
return myThreadData->setState(14);
|
|
|
|
|
return 14;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
myThreadData->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m" + "\n"
|
|
|
|
@@ -82,53 +76,52 @@ void * threadFunction(void * data) {
|
|
|
|
|
+ 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)
|
|
|
|
|
return myThreadData->setState(15);
|
|
|
|
|
return 15;
|
|
|
|
|
}
|
|
|
|
|
return myThreadData->setState(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= 3; ++i) {
|
|
|
|
|
std::string newUrl = myThreadData->pageManager->getUrlAfterRedirect("https://s.to" + Link);
|
|
|
|
|
if (newUrl == "-1") {
|
|
|
|
|
return myThreadData->setState(16);
|
|
|
|
|
return 16;
|
|
|
|
|
} 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)
|
|
|
|
|
return myThreadData->setState(17);
|
|
|
|
|
return 17;
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + "\033[0m";
|
|
|
|
|
if(myThreadData->settings->outputFilePath != "")
|
|
|
|
|
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0)
|
|
|
|
|
return myThreadData->setState(18);
|
|
|
|
|
return myThreadData->setState(0);
|
|
|
|
|
return 18;
|
|
|
|
|
return 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)
|
|
|
|
|
return myThreadData->setState(19);
|
|
|
|
|
return myThreadData->setState(0);
|
|
|
|
|
return 19;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ProgramManager::waitForThreads()
|
|
|
|
|
{
|
|
|
|
|
for( auto &e : threadList) {
|
|
|
|
|
if( e->exitState != -1 && pthread_join(e->thread, nullptr) == 0) {
|
|
|
|
|
if(e->exitState != 0) {
|
|
|
|
|
if(e->thread.valid()) {
|
|
|
|
|
int ret = e->thread.get();
|
|
|
|
|
if(ret != 0) {
|
|
|
|
|
std::cout << "\33[2K\r => Error: Thread gab error zurück." << std::endl;
|
|
|
|
|
return e->exitState;
|
|
|
|
|
return ret;
|
|
|
|
|
} else
|
|
|
|
|
if(e->returnValue != "")
|
|
|
|
|
std::cout << ("\33[2K\r(T" + std::to_string(e->id) + ")" + e->returnValue ) << std::endl;
|
|
|
|
|
}
|
|
|
|
|
e->exitState = -1;
|
|
|
|
|
e->returnValue = "";
|
|
|
|
|
e->setData(0, 0);
|
|
|
|
|
e->thread = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@@ -212,6 +205,7 @@ int ProgramManager::defaultModus(Settings *settings)
|
|
|
|
|
return 29;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//If Multithreading is Activ init Threads in Vector
|
|
|
|
|
if(settings->maxThreads > 0) {
|
|
|
|
|
for (unsigned i = 0; i < settings->maxThreads; ++i) {
|
|
|
|
|
if(dirExists(settings->cookieFilePath + std::to_string( i ))) {
|
|
|
|
@@ -225,7 +219,7 @@ int ProgramManager::defaultModus(Settings *settings)
|
|
|
|
|
//pm->setProxy(settings->proxy_ip, settings->proxy_port);
|
|
|
|
|
//pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i ));
|
|
|
|
|
|
|
|
|
|
ThreadData * newThreadData = new ThreadData(i, 0, nameInUrl, -1, settings, &accountManager, pm);
|
|
|
|
|
ThreadData * newThreadData = new ThreadData(i, nameInUrl, settings, &accountManager, pm);
|
|
|
|
|
threadList.push_back(newThreadData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -300,12 +294,14 @@ int ProgramManager::defaultModus(Settings *settings)
|
|
|
|
|
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<void*>(threadList[nextThread])) != 0 ) {
|
|
|
|
|
perror("pthread_creat failed");
|
|
|
|
|
return 48;
|
|
|
|
|
//Create Thread:
|
|
|
|
|
threadList[nextThread]->thread = std::async(threadFunction, threadList[nextThread]);// new std::thread(threadFunction, threadList[nextThread]);
|
|
|
|
|
if(!threadList[nextThread]->thread.valid()) {
|
|
|
|
|
perror("Craete Thread failed");
|
|
|
|
|
return 12;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++nextThread;
|
|
|
|
|
} else { // Sonnst warte bis alle Fertig sind und restarte die Folge
|
|
|
|
|
if(waitForThreads() != 0)
|
|
|
|
|