forked from markus/S_New4
works ok; but needs tests
This commit is contained in:
parent
34ec60e6a2
commit
50a7e12f80
@ -43,7 +43,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin
|
|||||||
char *url;
|
char *url;
|
||||||
std::string returnUrl;
|
std::string returnUrl;
|
||||||
|
|
||||||
std::cout << "Lade: '" << Url << "'..." << std::flush;
|
std::cout << "\33[2K\r" << "Lade: '" << Url << "'..." << std::flush;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(!curl) {
|
if(!curl) {
|
||||||
|
@ -4,7 +4,6 @@ void setPaths(Settings &settings)
|
|||||||
{
|
{
|
||||||
//Path settings
|
//Path settings
|
||||||
std::string executablePathTo = getexepath();
|
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) );
|
executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) );
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ struct Settings {
|
|||||||
proxy_port = 9050,
|
proxy_port = 9050,
|
||||||
default_maxDirs = 20;
|
default_maxDirs = 20;
|
||||||
char pathSymbol = '/';
|
char pathSymbol = '/';
|
||||||
unsigned maxThreads = 4;
|
unsigned maxThreads = 5;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,12 +103,10 @@ void * threadFunction(void * KA) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ProgramManager::defaultModus(Settings *settings)
|
int ProgramManager::defaultModus(Settings *settings)
|
||||||
{
|
{
|
||||||
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
||||||
|
|
||||||
|
|
||||||
//Wenn kein Name mit -n Angegeben wurde:
|
//Wenn kein Name mit -n Angegeben wurde:
|
||||||
if(settings->name == "") {
|
if(settings->name == "") {
|
||||||
if(settings->default_checkDirPath != "") {
|
if(settings->default_checkDirPath != "") {
|
||||||
@ -157,28 +155,30 @@ int ProgramManager::defaultModus(Settings *settings)
|
|||||||
return 25;
|
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) {
|
newKa->settings = settings;
|
||||||
ka * newKa = new ka(i);
|
newKa->accountManager = &accountManager;
|
||||||
PageManager * pm = new PageManager;
|
newKa->nameInUrl = nameInUrl;
|
||||||
pm->setProxy(settings->proxy_ip, settings->proxy_port);
|
newKa->thread = 0; // Sonst error wenn join & nicht gesetzt
|
||||||
pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i ));
|
newKa->exitState = -1;
|
||||||
pm->setDebugMode(settings->debugMode);
|
threadList.push_back(newKa);
|
||||||
newKa->pageManager = pm;
|
}
|
||||||
|
|
||||||
newKa->settings = settings;
|
|
||||||
newKa->accountManager = &accountManager;
|
|
||||||
newKa->nameInUrl = nameInUrl;
|
|
||||||
threadList.push_back(newKa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write Name to File if -o is set
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// melde bei s.to an und speicher cookies.
|
|
||||||
if (pageManager.login(accountManager.getNextAccount()) != 0) //----------------------------------------
|
|
||||||
return 29;
|
|
||||||
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);
|
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);
|
||||||
|
|
||||||
//Finde die anzahl der staffel heraus:
|
//Finde die anzahl der staffel heraus:
|
||||||
@ -217,70 +217,49 @@ int ProgramManager::defaultModus(Settings *settings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Multihreading Mode
|
||||||
//Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector...
|
if(settings->maxThreads > 0) {
|
||||||
if(nextThread < threadList.size()) {
|
//Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector...
|
||||||
threadList[nextThread]->setData(staffel, folge);
|
if(nextThread < threadList.size()) {
|
||||||
if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast<void*>(threadList[nextThread])) != 0 ) {
|
threadList[nextThread]->exitState = 0;
|
||||||
perror("pthread_creat failed");
|
threadList[nextThread]->setData(staffel, folge);
|
||||||
return 48;
|
if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast<void*>(threadList[nextThread])) != 0 ) {
|
||||||
}
|
perror("pthread_creat failed");
|
||||||
nextThread++;
|
return 48;
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
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--;
|
} else { // Default Mode
|
||||||
continue;
|
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.
|
if(folge == settings->stopEpisode && settings->stopSeason < 1) { // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde.
|
||||||
for( auto &e : threadList) {
|
if(settings->maxThreads != 0)
|
||||||
pthread_join(e->thread, nullptr);
|
if(waitForThreads() != 0)
|
||||||
if(e->exitState != 0) {
|
return 261;
|
||||||
std::cout << "Error: Thread gab error zurück." << std::endl;
|
|
||||||
return e->exitState;
|
|
||||||
}
|
|
||||||
std::cout << "NachThread: " << e->returnValue << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
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) {
|
if(settings->maxThreads != 0)
|
||||||
pthread_join(e->thread, nullptr);
|
if(waitForThreads() != 0)
|
||||||
if(e->exitState != 0) {
|
return 267;
|
||||||
std::cout << "Error: Thread gab error zurück." << std::endl;
|
|
||||||
return e->exitState;
|
|
||||||
}
|
|
||||||
std::cout << "NachThread: " << e->returnValue << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,22 +273,34 @@ int ProgramManager::defaultModus(Settings *settings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(settings->maxThreads != 0)
|
||||||
for( auto &e : threadList) {
|
if(waitForThreads() != 0)
|
||||||
pthread_join(e->thread, nullptr);
|
return 292;
|
||||||
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;
|
std::cout << " > Fertig" << std::endl;
|
||||||
return 0;
|
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)
|
int ProgramManager::directLinkModus(Settings *settings)
|
||||||
{
|
{
|
||||||
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
struct ka
|
struct ka
|
||||||
{
|
{
|
||||||
ka(unsigned id) : id(id) {}
|
ka(unsigned id) : id(id) {}
|
||||||
|
~ka() { std::cout << "Deskrtuktor" << std::endl; }
|
||||||
|
|
||||||
unsigned id;
|
unsigned id;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
std::string nameInUrl, returnValue;
|
std::string nameInUrl, returnValue;
|
||||||
@ -29,7 +31,6 @@ struct ka
|
|||||||
}
|
}
|
||||||
void setData(int staffel, int folge) { this->staffel = staffel; this->folge = folge; }
|
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 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 searchModus_update(Settings * settings);
|
||||||
|
int waitForThreads();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user