fix direkt link modus + default modus fixes

This commit is contained in:
Your Name 2021-03-01 13:59:37 +01:00
parent 0162441d26
commit bb5571b20b
4 changed files with 111 additions and 73 deletions

View File

@ -1,7 +1,7 @@
#include "pageManager.h"

PageManager::PageManager(std::string sock5ProxyOnlyAddress, std::string cookieFilePath)
: sock5Proxy("socks5://" + sock5ProxyOnlyAddress), cookieFilePath(cookieFilePath)
: sock5Proxy("socks5://" + sock5ProxyOnlyAddress)
{
curl_global_init(CURL_GLOBAL_ALL);
}
@ -24,10 +24,7 @@ void PageManager::setProxy(std::string ip, int port)
}
}

void PageManager::setCookieFilePath(std::string path)
{
this->cookieFilePath = path;
}


void PageManager::setDebugMode(bool status)
{
@ -77,7 +74,7 @@ void PageManager::get_terminal_size(int& width) {
#endif // Windows/Linux
}

Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::string data, bool generateCookieFile, bool UrlAfterRedirectOnlyNeeded)
Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::string data, bool generateCookieFile, bool UrlAfterRedirectOnlyNeeded, std::string cookieFilePath)
{
CURL *curl;
CURLcode res;
@ -285,17 +282,25 @@ int PageManager::login(PAGE page, Account account)
return -1;
}

std::string PageManager::getUrlAfterRedirect(std::string Url)
Reply PageManager::getUrlAfterRedirect(std::string Url, std::string cookieFilePath)
{
return getServerRequest(Url, true, "", false, true).url;
return getServerRequest(Url, true, "", false, true, cookieFilePath);
}

checkNameRply PageManager::checkName(std::vector<PAGE> pages, std::string Name)
checkNameRply PageManager::checkName(std::vector<PAGE> pages, std::string Name, bool useFirstPage)
{
if(pages.size() < 1) {
std::cout << " => Error Keine Internet Seiten vorhanden." << std::endl;
return checkNameRply("", PAGE(), checkNameRply::FAILED);
}

//überprüfe, auf welchen seite die serie existiert, wenn parameter
//für automatisch erste Seite aktiv ist, dann wähl aus, sonst manuel auswahl

int count = 0;
std::string name = replace(Name, " ", "-");
std::string pagesonExist;
PAGE Page("", "");
PAGE Page;

//für jede Seite
for ( const auto &p : pages ) {
@ -306,16 +311,22 @@ checkNameRply PageManager::checkName(std::vector<PAGE> pages, std::string Name)

} else if (html.find("404 - Seite nicht gefunden") != std::string::npos) {
std::cout << "\33[2K\r => Ungültiger Name: '" << Name << "'" << std::endl;
return checkNameRply("", PAGE("", ""), checkNameRply::NOTHING_FOUND);
return checkNameRply("", PAGE(), checkNameRply::NOTHING_FOUND);

} else if (html == "-1" || html == "") {
return checkNameRply("", PAGE("", ""), checkNameRply::FAILED);
return checkNameRply("", PAGE(), checkNameRply::FAILED);

}
else {
count ++;
pagesonExist += p.url + " ";
Page = p;

if(useFirstPage) {
if(debugMode)
std::cerr << "Nimm gleiche diese Seite, da useFirstPage auf true ist" << std::endl;
break; // nimm gleich das erste
}
}
}

@ -324,11 +335,11 @@ checkNameRply PageManager::checkName(std::vector<PAGE> pages, std::string Name)
std::cout << "\33[2K\r > Name: " << name << std::endl;
return checkNameRply(name, Page, checkNameRply::SUCCESS);;
} else if ( count > 1) {
std::cout << "\33[2K\r => Die Serie existiert auf mehreren Seiten " << pagesonExist << ": '" << name << "'" << std::endl;
return checkNameRply("", PAGE("", ""), checkNameRply::NOTHING_FOUND);; //MULTIPLE OPTIONS FOUND!!!!
std::cout << "\33[2K\r => Die Serie existiert auf mehreren Seiten " << name << ": '" << pagesonExist << "'" << std::endl;
return checkNameRply("", PAGE(), checkNameRply::NOTHING_FOUND); //MULTIPLE OPTIONS FOUND!!!!
} else {
std::cout << "\33[2K\r => Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: '" << Name << "'" << std::endl;
return checkNameRply("", PAGE("", ""), checkNameRply::NOTHING_FOUND);;
return checkNameRply("", PAGE(), checkNameRply::NOTHING_FOUND);
}

}

View File

@ -27,7 +27,7 @@ struct Reply {
struct checkNameRply {
std::string name;
PAGE pageInUse;
enum STATUS { SUCCESS, FAILED, NOTHING_FOUND, MULTIPLE_OPTIONS_FOUND } status;
enum STATUS { SUCCESS, FAILED, NOTHING_FOUND } status;

checkNameRply(const std::string &name, const PAGE &p, const checkNameRply::STATUS &s )
: name(name), pageInUse(p), status(s) {}
@ -41,17 +41,16 @@ public:
~PageManager();

void setProxy(std::string ip, int port);
void setCookieFilePath(std::string path);
void setDebugMode(bool status);

void get_terminal_size(int& width);

Reply getServerRequest(std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false, bool UrlAfterRedirectOnlyNeeded = false);
Reply getServerRequest(std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false, bool UrlAfterRedirectOnlyNeeded = false, std::string cookieFilePath = "");
int downLoadToFile(std::string filePath, std::string url);

int login(PAGE page, Account account);
std::string getUrlAfterRedirect(std::string Url);
checkNameRply checkName(std::vector<PAGE> pages, std::string Name);
Reply getUrlAfterRedirect(std::string Url, std::string cookieFilePath);
checkNameRply checkName(std::vector<PAGE> pages, std::string Name, bool useFirstPage);
std::string getLinks(std::string HTML);
std::string chooseHosterLink(std::string HosterList, std::string Hoster_with_Highst_Priority_at_First, std::string languages_with_highst_priority_at_first, bool withWarnMsg);
std::string getLinkAfterHosterBasedOperation(std::string url);
@ -68,7 +67,6 @@ public:

std::string sock5Proxy;
private:
std::string cookieFilePath;
bool debugMode = false;
};


View File

@ -48,32 +48,30 @@ enum Modus {
};

struct PAGE {
PAGE( std::string url, std::string nameID )
: name_id(nameID), url(url) {}
PAGE() {}
PAGE( std::string url, std::string nameID, std::string urlAphabetSerienList, std::string urlDir )
: name_id(nameID), url(url), urlAlphabetSerienList(urlAphabetSerienList), UrlDir(urlDir)
{

std::string name_id,
url;
std::string urlAlphabetSerienList,
UrlDir;
}
std::string name_id, url, urlAlphabetSerienList, UrlDir;
};

struct Settings {
Settings() {
PAGE sto( "serienstream.sx", "Normale_Serien");
sto.urlAlphabetSerienList = "/serien-alphabet";
sto.UrlDir = "/serie/stream/";

pages.push_back( sto );

PAGE anicio ( "anicloud.io", "Animes");
anicio.urlAlphabetSerienList = "/animes-alphabet";
anicio.UrlDir = "/anime/stream/";

pages.push_back( anicio );


}
const std::string programName = "S_New4";
PAGE sto = PAGE( "serienstream.sx", "Normale_Serien", "/serien-alphabet", "/serie/stream/");
PAGE anicio = PAGE( "anicloud.io", "Animes", "/animes-alphabet", "/anime/stream/");
std::vector<PAGE> pages; // Priority sorted
bool useFirstPage = false;

PAGE direktLink_explizitPage;


Settings() {
pages.push_back( sto );
pages.push_back( anicio );
}

// Wenn das Betriebsystem x86 ist:
#if defined (_X86_) || defined (__amd64__) || defined (_M_IX86)
@ -107,9 +105,6 @@ struct Settings {
#endif
#endif

std::vector<PAGE> pages;
enum MULTIPAGEFOUND_HANDLE { STOP, USE_PAGE_PRIORITY_HIGHEST, MANUEL_HANDLE } mpfH = MANUEL_HANDLE;
std::string pagePriority;


std::string name,

View File

@ -20,7 +20,6 @@ int ProgramManager::start(Settings *settings)
{
pageManager.setDebugMode(settings->debugMode);
pageManager.setProxy(settings->proxy_ip, settings->proxy_port);
pageManager.setCookieFilePath(settings->cookieFilePath);
if(dirExists(settings->cookieFilePath)) {
std::cout << " => Error: Kann Cokkie-File nicht erstellen: Es existiert bereits ein Ordner mit diesem Namen: \n '"
<< settings->cookieFilePath << "'." << std::endl;
@ -111,7 +110,8 @@ void * threadFunction(void * data) {
}

for (int i = 1; i <= 3; ++i) {
std::string newUrl = myThreadData->pageManager->getUrlAfterRedirect("https://" + myThreadData->page.url + Link);
auto REPLy = myThreadData->pageManager->getUrlAfterRedirect("https://" + myThreadData->page.url + Link, myThreadData->settings->cookieFilePath + "_" + myThreadData->page.name_id);
std::string newUrl = REPLy.url;
if (newUrl == "-1") {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": getUrlAfterRedirect Function failed: returned -1." << std::endl;
@ -129,6 +129,11 @@ void * threadFunction(void * data) {
continue;

// get NO-Redirect Link after getUrlAfterRedirect Function
}else if ( REPLy.html.find("404 - Seite nicht gefunden") != std::string::npos) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": getUrlAfterRedirect Function failed: 404 - Seite nicht gefunden." << std::endl;
return myThreadData->setState(404);

} else {
if( (newUrl = myThreadData->pageManager->getLinkAfterHosterBasedOperation(newUrl)) == "") {
if(myThreadData->settings->debugMode)
@ -188,6 +193,11 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana
std::string finds;
std::string gewollteSeitenUrl;

if(settings->pages.size() < 1) {
std::cout << " => Error Keine Internet Seiten vorhanden." << std::endl;
return 1290;
}

//Führe unterfunction zum suchen von Serien aus, aber ohne suche auszugeben und speichere datein in variable
if(searchModus(settings, &finds, true) != 0) {
if(settings->debugMode)
@ -333,7 +343,9 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana
std::vector<PAGE> pages;
pages.push_back( newNameAndPage.pageInUse );

auto ret = pageManager.checkName( pages /*settings->pages dann glaub ich immer fehler, wenn serie auf 2 seiten excistiert*/, finds);
auto ret = pageManager.checkName( pages /*settings->pages dann glaub
ich immer fehler, wenn serie auf 2 seiten excistiert*/,
finds, settings->useFirstPage);
if(ret.status == ret.FAILED)
return 23;
else if( ret.status == ret.NOTHING_FOUND ) {
@ -440,7 +452,7 @@ int ProgramManager::defaultModus(Settings *settings)


//Führe Function aus, die überprüft ob die serie existiert
auto retVal = pageManager.checkName(settings->pages, settings->name);
auto retVal = pageManager.checkName(settings->pages, settings->name, settings->useFirstPage);

if(retVal.status == retVal.FAILED)
return 67;
@ -452,28 +464,11 @@ int ProgramManager::defaultModus(Settings *settings)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": sucheNach_1_Serien failed or found more options." << std::endl;
return (res == -10101) ? 0 : 202;
}
} else if (retVal.status == retVal.MULTIPLE_OPTIONS_FOUND) {
switch (settings->mpfH) {
case Settings::STOP:
break;
case Settings::MANUEL_HANDLE: {
int res = 0;
if( ( res = sucheNach_1_Serien(settings, pageManager, retVal) ) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": sucheNach_1_Serien failed or found more options." << std::endl;
return (res == -10101) ? 0 : 202;
}
break;
} case Settings::USE_PAGE_PRIORITY_HIGHEST:
break;

}
}

std::string nameInUrl = retVal.name;
PAGE page = retVal.pageInUse;
AccountManager accountManager(settings->accountFilePath + "_" + page.name_id, settings->accountNumberPath + "_" + page.name_id, page);
pageManager.setCookieFilePath(settings->cookieFilePath + "_" + page.name_id);
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath, page);


/* Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor
@ -684,7 +679,6 @@ int ProgramManager::defaultModus(Settings *settings)

int ProgramManager::directLinkModus(Settings *settings)
{
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath, PAGE("", ""));

if(settings->name == "") {
std::cout << " => Kein(e) Link(s) angegeben." << std::endl;
@ -700,14 +694,48 @@ int ProgramManager::directLinkModus(Settings *settings)
// return 71;

while (getline(iStrStream, line).good()) {
//extrahiere redirekt und page
std::string redL;
PAGE page;

if(line.find("/redirect/") == std::string::npos) {
std::cout << " => Error: Invalid Redirect Link: '" << line << "'" << std::endl;
continue;

} else if(convertLink(PAGE("", ""), line.erase(0, line.find("/redirect/") ), &accountManager, settings) != 0) {
} else if(line.find("://") == std::string::npos) {
if(settings->direktLink_explizitPage.url == "") {
std::cout << " => Kann '://' bei '" << line << "' nicht finden: Benutze -e [PAGE], --explizit [PAGE], um /redirect/xyz umzuwandeln" << std::endl;
continue;
}
redL = line.erase(0, line.find("/redirect/"));
page = settings->direktLink_explizitPage;


} else {
line.erase(0, line.find("://") + 3); // remove http(s)://
std::string url = line.substr(0, line.find("/redirect/"));
bool found = false;
for( const auto &p : settings->pages ) {
if(p.url == url) {
found = true;
page = p;
break;
}
}
if( !found ) {
std::cout << " => Error: Unbekannte Seite: '" << url << "'" << std::endl;
continue;
}
redL = line.erase(0, line.find("/redirect/"));
}

AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath, page);
std::cout << "CONVERT LINK: '" << redL << "' -> URL: " << page.url << std::endl;
if(convertLink(page, redL, &accountManager, settings) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": convert Link failed." << std::endl;
return 78;

}
}
if(settings->debugMode)
@ -866,7 +894,7 @@ int ProgramManager::infoModus(Settings *settings)
}

//Führe Function aus, die überprüft ob die serie existiert
auto retV = pageManager.checkName(settings->pages, settings->name);
auto retV = pageManager.checkName(settings->pages, settings->name, settings->useFirstPage);
if(retV.status == retV.FAILED)
return 145;
else if(retV.status == retV.NOTHING_FOUND) {
@ -1145,7 +1173,7 @@ int ProgramManager::infoModus(Settings *settings)
int ProgramManager::newsModus(Settings *settings)
{
size_t pos = 0;
PAGE page("", "");
PAGE page;
std::string html = pageManager.getServerRequest("https://" + page.url +"/neue-episoden").html;
if(html == "-1") {
if(settings->debugMode)
@ -1464,6 +1492,10 @@ int ProgramManager::searchModus_update(Settings *settings)
{
std::string list;
std::string line;
if(settings->pages.size() < 1) {
std::cout << " => Error Keine Internet Seiten vorhanden." << std::endl;
return 1290;
}

for ( const auto &page : settings->pages ) {
std::cout << " -> Updating '" << page.name_id << "'..." << std::endl;
@ -1708,7 +1740,9 @@ int ProgramManager::convertLink(PAGE page, std::string redirectLink, AccountMana
}

for (int i = 1; i <= 3; ++i) {
std::string newUrl = pageManager.getUrlAfterRedirect("https://" + page.url + redirectLink);
auto rEply = pageManager.getUrlAfterRedirect("https://" + page.url + redirectLink, settings->cookieFilePath + "_" + page.name_id);
std::string newUrl = rEply.url;

//wenn function fehl schlug beende das Programm
if (newUrl == "-1") {
if(settings->debugMode)
@ -1727,7 +1761,7 @@ int ProgramManager::convertLink(PAGE page, std::string redirectLink, AccountMana
continue;

//wenn nach der Umwandlung https://seriens tream.sx/ vorhanden ist, die ist wenn der Link Ungültig war:
} else if (newUrl == "https://" + page.url + "/") {
} else if (newUrl == "https://" + page.url + "/" || rEply.html.find("404 - Seite nicht gefunden") != std::string::npos) {
std::cout << " => " << red << replace(folgenID, "E", " E") << ( (folgenID == "") ? "" : ": " ) << "Ungültige Url: 'https://" + page.url << redirectLink << "'"
<< ((settings->colorless) ? "" : "\033[0m") << std::endl;
if(settings->outputFilePaths.size() != 0)