forked from markus/S_New4
create thread funct & start & waiter -- works but: next-season & more thread than episodes etc...
This commit is contained in:
parent
825045d5e6
commit
3f06640821
@ -1,8 +1,8 @@
|
|||||||
QT -= gui
|
QT -= gui
|
||||||
|
|
||||||
#LIBS += -lcurl
|
LIBS += -lcurl
|
||||||
#LIBS += -LC:\Users\Markus\Desktop\S_New4\S_New4\curl -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
|
CONFIG += c++11 console
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath)
|
PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath)
|
||||||
: sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath)
|
: sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath)
|
||||||
{
|
{
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
PageManager::~PageManager()
|
PageManager::~PageManager()
|
||||||
{
|
{
|
||||||
remove(cookieFilePath.c_str());
|
remove(cookieFilePath.c_str());
|
||||||
|
curl_global_cleanup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageManager::setProxy(std::string ip, int port)
|
void PageManager::setProxy(std::string ip, int port)
|
||||||
|
@ -53,6 +53,7 @@ struct Settings {
|
|||||||
proxy_port = 9050,
|
proxy_port = 9050,
|
||||||
default_maxDirs = 20;
|
default_maxDirs = 20;
|
||||||
char pathSymbol = '/';
|
char pathSymbol = '/';
|
||||||
|
unsigned maxThreads = 2;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "programManager.h"
|
#include "programManager.h"
|
||||||
|
|
||||||
|
|
||||||
ProgramManager::ProgramManager()
|
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)
|
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 != "") {
|
||||||
@ -81,8 +156,28 @@ int ProgramManager::defaultModus(Settings *settings)
|
|||||||
searchModus(settings);
|
searchModus(settings);
|
||||||
return 25;
|
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;
|
return 29;
|
||||||
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);
|
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));
|
tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge));
|
||||||
if(tmp_reply.html == "-1")
|
if(tmp_reply.html == "-1")
|
||||||
return 47;
|
return 50;
|
||||||
std::string allLinks = pageManager.getLinks(tmp_reply.html);
|
std::string allLinks = pageManager.getLinks(tmp_reply.html);
|
||||||
std::string Link = pageManager.chooseHosterLink(allLinks, settings->genaueHoster, settings->languages);
|
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)
|
if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0)
|
||||||
return 51;
|
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.
|
||||||
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
|
||||||
|
@ -9,6 +9,30 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.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
|
class ProgramManager
|
||||||
{
|
{
|
||||||
@ -25,6 +49,8 @@ private:
|
|||||||
int infoModus(Settings * settings);
|
int infoModus(Settings * settings);
|
||||||
|
|
||||||
PageManager pageManager;
|
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 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user