create thread funct & start & waiter -- works but: next-season & more thread than episodes etc...

This commit is contained in:
Markus 2019-08-15 14:20:06 +02:00
parent 825045d5e6
commit 3f06640821
5 changed files with 162 additions and 6 deletions

View File

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

View File

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

View File

@ -53,6 +53,7 @@ struct Settings {
proxy_port = 9050,
default_maxDirs = 20;
char pathSymbol = '/';
unsigned maxThreads = 2;

};


View File

@ -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<struct ka*>(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<void*>(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

View File

@ -9,6 +9,30 @@
#include <sys/types.h>
#include <dirent.h>

#include <pthread.h>


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