From 0162441d2690bcbffd381bff370a8792db7adf14 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Mar 2021 10:42:50 +0100 Subject: [PATCH] make default modus stabil --- src/accountManager.cpp | 208 +++++++++++++++++++++------------------ src/accountManager.h | 9 +- src/pageManager.cpp | 12 +-- src/pageManager.h | 7 +- src/parameterManager.cpp | 22 +++++ src/parameterManager.h | 19 ++-- src/programManager.cpp | 41 +++++--- src/programManager.h | 1 + 8 files changed, 191 insertions(+), 128 deletions(-) diff --git a/src/accountManager.cpp b/src/accountManager.cpp index 3d36858..8380472 100644 --- a/src/accountManager.cpp +++ b/src/accountManager.cpp @@ -1,13 +1,14 @@ #include "accountManager.h" -AccountManager::AccountManager(std::string pathToFile, std::string pathToAccountNumberFile) - : pathToAccountNumberFile(pathToAccountNumberFile) +AccountManager::AccountManager(std::string pathToFil, std::string pathToAccountNumberFile, PAGE page) + : pathToAccountNumberFile(pathToAccountNumberFile + "_" + page.name_id), pageInUse(page) { - std::ifstream ifs(pathToFile); + std::string pathToAccountsFile = pathToFil + "_" + page.name_id; + std::ifstream ifs(pathToAccountsFile); if(!ifs.is_open()) { - if(writeDefault(pathToFile) != 0) + if(writeDefault(pathToAccountsFile) != 0) exit(12); - ifs.open(pathToFile); + ifs.open(pathToAccountsFile); if(!ifs.is_open()) { std::cout << " => Error: Konnte Account File nicht öffnen" << std::endl; exit(13); @@ -66,98 +67,113 @@ int AccountManager::writeDefault(std::string path) std::cout << " => Erstelle Datei mit Accounts unter: " << path << "..." < WARNUNG: Keine standart Accounts für die Url '" << pageInUse.url << "' vorhanden." < #include + + +#include "parameterManager.h" + + + struct Account { std::string Email, Password; @@ -14,13 +20,14 @@ struct Account { class AccountManager { public: - AccountManager(std::string pathToFile, std::string pathToAccountNumberFile); + AccountManager(std::string pathToFile, std::string pathToAccountNumberFile, PAGE page); Account getNextAccount(); size_t getLastAccountNumber(); private: std::vector accounts; std::string pathToAccountNumberFile; + PAGE pageInUse; int setLastAccountNumber(size_t number); int writeDefault(std::string path); diff --git a/src/pageManager.cpp b/src/pageManager.cpp index 11bd34f..8a5a87c 100644 --- a/src/pageManager.cpp +++ b/src/pageManager.cpp @@ -64,8 +64,8 @@ void PageManager::get_terminal_size(int& width) { #if defined(_WIN32) CONSOLE_SCREEN_BUFFER_INFO csbi; if( GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) == 0 ) { - if ( debugMode ) - std::cout << " => WARNING: GetConsoleScreenBufferInfo failed => Use 9999 as max Msg-Length" << std::endl; + //if ( debugMode ) + //std::cout << " => WARNING: GetConsoleScreenBufferInfo failed => Use 9999 as max Msg-Length" << std::endl; return; } @@ -300,13 +300,13 @@ checkNameRply PageManager::checkName(std::vector pages, std::string Name) //für jede Seite for ( const auto &p : pages ) { - std::string html = getServerRequest("https://" + p.url +"/serie/stream/" + name).html; + std::string html = getServerRequest("https://" + p.url + p.UrlDir + name).html; if(html.find("Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert.") != std::string::npos) { continue; } 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::NEEDHELP); + return checkNameRply("", PAGE("", ""), checkNameRply::NOTHING_FOUND); } else if (html == "-1" || html == "") { return checkNameRply("", PAGE("", ""), checkNameRply::FAILED); @@ -325,10 +325,10 @@ checkNameRply PageManager::checkName(std::vector pages, std::string Name) 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::NEEDHELP);; + 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::NEEDHELP);; + return checkNameRply("", PAGE("", ""), checkNameRply::NOTHING_FOUND);; } } diff --git a/src/pageManager.h b/src/pageManager.h index 0024e13..c07956b 100644 --- a/src/pageManager.h +++ b/src/pageManager.h @@ -1,10 +1,15 @@ #ifndef MANAGEPAGE_H #define MANAGEPAGE_H + #include "accountManager.h" #include "curl/curl.h" #include "parameterManager.h" // for isNumber +#ifdef _WIN32 +#include +#endif + #include #include // sleep #include @@ -22,7 +27,7 @@ struct Reply { struct checkNameRply { std::string name; PAGE pageInUse; - enum STATUS { SUCCESS, FAILED, NEEDHELP } status; + enum STATUS { SUCCESS, FAILED, NOTHING_FOUND, MULTIPLE_OPTIONS_FOUND } status; checkNameRply(const std::string &name, const PAGE &p, const checkNameRply::STATUS &s ) : name(name), pageInUse(p), status(s) {} diff --git a/src/parameterManager.cpp b/src/parameterManager.cpp index 73fc06a..85eda02 100644 --- a/src/parameterManager.cpp +++ b/src/parameterManager.cpp @@ -1007,6 +1007,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv) return; } + //Um altes zeug zu löschen unsigned count = 0; if(fileExists(settings->cookieFilePath)) { if(remove(settings->cookieFilePath.c_str()) != 0) { @@ -1024,6 +1025,27 @@ void unterOption_clean(Settings * settings, int argc, char **argv) ++count; } } + //UM sachen nach multipage update zu löschen + for ( const auto &p : settings->pages ) { + if(fileExists(settings->cookieFilePath + "_" + p.name_id)) { + if(remove((settings->cookieFilePath + "_" + p.name_id).c_str()) != 0) { + perror(( " => Error: Das löschen von " + settings->cookieFilePath + "_" + p.name_id + " ist fehlgeschlagen: ").c_str()); + return; + } else + ++count; + } + + for (unsigned i = 0; i < UINT_MAX && fileExists(settings->cookieFilePath + "_" + p.name_id + std::to_string(i)); ++i) { + if(remove( (settings->cookieFilePath + "_" + p.name_id + std::to_string(i)).c_str() ) != 0) { + perror((" => Error: Das löschen von " + settings->cookieFilePath + "_" + p.name_id + std::to_string(i) + " ist fehlgeschlagen: ").c_str()); + return; + } else { + ++count; + } + } + } + + if(count == 0) std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl; diff --git a/src/parameterManager.h b/src/parameterManager.h index d3aed54..1feed48 100644 --- a/src/parameterManager.h +++ b/src/parameterManager.h @@ -7,6 +7,7 @@ #endif #endif + #include #include #include // strlen @@ -19,11 +20,9 @@ #include // readlink() #include -#include "logger.h" -#ifdef _WIN32 -#include -#endif + +#include "logger.h" #define UpdaterCloudUrlWithPath "https://cloud.obermui.de/s/tXz7SWdaPJ7TacZ/download?path=%2F&files=" #define SecondUpdaterCloudUrlWithPath "https://snew4.obermui.de/download?path=%2F&files=" @@ -56,12 +55,6 @@ struct PAGE { url; std::string urlAlphabetSerienList, UrlDir; - - - std::string accountFileName = "", - accountNumberFileName= "", - cookieFileName = "", - serienListName = ""; }; struct Settings { @@ -115,6 +108,10 @@ struct Settings { #endif std::vector pages; + enum MULTIPAGEFOUND_HANDLE { STOP, USE_PAGE_PRIORITY_HIGHEST, MANUEL_HANDLE } mpfH = MANUEL_HANDLE; + std::string pagePriority; + + std::string name, accountFilePath = "", accountNumberPath= "", @@ -131,7 +128,7 @@ struct Settings { languages = "GerDub,GerSub,Eng,", genaueHoster = "", version = VERSION, - defaultFileVersion="1.8", + defaultFileVersion="2.0", default_checkPath = "", default_Searchmuster = "S%Staffel%E%Folge%"; diff --git a/src/programManager.cpp b/src/programManager.cpp index 077c649..40ba81e 100644 --- a/src/programManager.cpp +++ b/src/programManager.cpp @@ -311,8 +311,6 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana } } - std::cout << "NAME: " << finds << std::endl; - //suche Seite aus sucheregbnis in settings... bool found = false; @@ -338,7 +336,7 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana auto ret = pageManager.checkName( pages /*settings->pages dann glaub ich immer fehler, wenn serie auf 2 seiten excistiert*/, finds); if(ret.status == ret.FAILED) return 23; - else if( ret.status == ret.NEEDHELP ) { + else if( ret.status == ret.NOTHING_FOUND ) { std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl; if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": Extracted Name from searchModus is invalid." << std::endl; @@ -394,7 +392,6 @@ int ProgramManager::checkLastUpdate(Settings *settings, ssize_t *days = nullptr) int ProgramManager::defaultModus(Settings *settings) { - AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); //Wenn kein Name mit -n Angegeben wurde: if(settings->name == "") { @@ -447,7 +444,7 @@ int ProgramManager::defaultModus(Settings *settings) if(retVal.status == retVal.FAILED) return 67; - else if(retVal.status == retVal.NEEDHELP) { + else if(retVal.status == retVal.NOTHING_FOUND) { //Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch && Wenn nur 1ne dacnn frag ob es diese ist. int res = 0; if( ( res = sucheNach_1_Serien(settings, pageManager, retVal) ) != 0) { @@ -455,10 +452,28 @@ 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); /* Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor @@ -470,16 +485,16 @@ int ProgramManager::defaultModus(Settings *settings) if(settings->maxThreads > 0) { for (unsigned i = 0; i < settings->maxThreads; ++i) { - if(dirExists(settings->cookieFilePath + std::to_string( i ))) { + if(dirExists(settings->cookieFilePath + "_" + page.name_id + std::to_string( i ))) { std::cout << " => Error: Kann Cokkie-File nicht erstellen: Es existiert bereits ein Ordner mit diesem Namen: \n '" - << settings->cookieFilePath + std::to_string( i ) << "'." << std::endl; + << settings->cookieFilePath + "_" + page.name_id + std::to_string( i ) << "'." << std::endl; return 174; } - PageManager * pm = new PageManager(settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i )); + PageManager * pm = new PageManager(settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + "_" + page.name_id + std::to_string( i )); pm->setDebugMode(settings->debugMode); //pm->setProxy(settings->proxy_ip, settings->proxy_port); - //pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i )); + //pm->setCookieFile Path(settings->cookieFile Path + std::to_string( i )); ThreadData * newThreadData = new ThreadData(i, 0, nameInUrl, -1, settings, &accountManager, pm, page); threadList.push_back(newThreadData); @@ -669,7 +684,7 @@ int ProgramManager::defaultModus(Settings *settings) int ProgramManager::directLinkModus(Settings *settings) { - AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); + AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath, PAGE("", "")); if(settings->name == "") { std::cout << " => Kein(e) Link(s) angegeben." << std::endl; @@ -854,13 +869,13 @@ int ProgramManager::infoModus(Settings *settings) auto retV = pageManager.checkName(settings->pages, settings->name); if(retV.status == retV.FAILED) return 145; - else if(retV.status == retV.NEEDHELP) { + else if(retV.status == retV.NOTHING_FOUND) { //Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch. int res = 0; if( ( res = sucheNach_1_Serien(settings, pageManager, retV) ) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": sucheNach_1_Serien function failed." << std::endl; - return (res = -10101) ? 0 : 28; + return (res == -10101) ? 0 : 28; } } std::string nameInUrl = retV.name; diff --git a/src/programManager.h b/src/programManager.h index 64f4072..5034393 100644 --- a/src/programManager.h +++ b/src/programManager.h @@ -1,6 +1,7 @@ #ifndef MANAGEPROGRAM_H #define MANAGEPROGRAM_H + #include "pageManager.h" #include "parameterManager.h" #include "accountManager.h"