diff --git a/src/pageManager.cpp b/src/pageManager.cpp index 214afb6..4cdcff0 100644 --- a/src/pageManager.cpp +++ b/src/pageManager.cpp @@ -290,24 +290,45 @@ std::string PageManager::getUrlAfterRedirect(std::string Url) return getServerRequest(Url, true, "", false, true).url; } -std::string PageManager::checkName(std::string Name) +std::string PageManager::checkName(std::vector pages, std::string Name) { + int count = 0; std::string name = replace(Name, " ", "-"); + std::string pagesonExist; - std::string html = getServerRequest("https://serienstream.sx/serie/stream/" + name).html; - if(html.find("Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert.") != std::string::npos) { - std::cout << "\33[2K\r => Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: '" << Name << "'" << std::endl; - return "-1"; - } else if (html.find("404 - Seite nicht gefunden") != std::string::npos) { - std::cout << "\33[2K\r => Ungültiger Name: '" << Name << "'" << std::endl; - return "-1"; - } else if (html == "-1" || html == "") { - return "-2"; + //für jede Seite + for ( const auto &page : pages ) { + + std::string html = getServerRequest("https://" + page.url +"/serie/stream/" + 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 "-1"; + + } else if (html == "-1" || html == "") { + return "-2"; + + } + else { + count ++; + pagesonExist += page.url + " "; + } } - else { + + // + if( count == 1 ) { std::cout << "\33[2K\r > Name: " << name << std::endl; return name; + } else if ( count > 1) { + std::cout << "\33[2K\r => Die Serie existiert auf mehreren Seiten " << pagesonExist << ": '" << name << "'" << std::endl; + return "-1"; + } else { + std::cout << "\33[2K\r => Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: '" << Name << "'" << std::endl; + return "-1"; } + } std::string PageManager::getLinks(std::string HTML) diff --git a/src/pageManager.h b/src/pageManager.h index b8777b0..d6e82b8 100644 --- a/src/pageManager.h +++ b/src/pageManager.h @@ -37,7 +37,7 @@ public: int login(Account account); std::string getUrlAfterRedirect(std::string Url); - std::string checkName(std::string Name); + std::string checkName(std::vector pages, std::string Name); 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); diff --git a/src/parameterManager.h b/src/parameterManager.h index af1cb4c..d3aed54 100644 --- a/src/parameterManager.h +++ b/src/parameterManager.h @@ -30,6 +30,10 @@ #define VERSION "4.3.7" +//default, anime, normal, +//suche: für jede katego. eine +//zu beginn, erst eiunmal serie suchen + enum Modus { EXIT = -1, @@ -44,9 +48,38 @@ enum Modus { }; +struct PAGE { + PAGE( std::string url, std::string nameID ) + : name_id(nameID), url(url) {} + + std::string name_id, + url; + std::string urlAlphabetSerienList, + UrlDir; + + + std::string accountFileName = "", + accountNumberFileName= "", + cookieFileName = "", + serienListName = ""; +}; + struct Settings { - Settings() {} - Settings(std::string name) : name(name) {} + 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"; // Wenn das Betriebsystem x86 ist: @@ -81,11 +114,13 @@ struct Settings { #endif #endif + std::vector pages; std::string name, - accountFilePath = "", - accountNumberPath= "", - cookieFilePath = "", - serienListPath = "", + accountFilePath = "", + accountNumberPath= "", + cookieFilePath = "", + serienListPath = "", + lastUpdateDateFilePath = "", configDir="", cacheDir="", @@ -102,6 +137,7 @@ struct Settings { std::vector outputFilePaths; + Modus modus = Modus::EXIT; bool colorless = false, debugMode = false, diff --git a/src/programManager.cpp b/src/programManager.cpp index b78b76d..e34a8d2 100644 --- a/src/programManager.cpp +++ b/src/programManager.cpp @@ -288,7 +288,7 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana } //Überprüfe ob es die serie gibt wenn ja speicher ihn in newname und beende Function - newName = pageManager.checkName(finds); +//<>/newName = pageManager.checkName(finds); if(newName == "-2") return 23; else if( newName == "-1" ) { @@ -391,8 +391,10 @@ int ProgramManager::defaultModus(Settings *settings) if(dirFiles.length() > 0) //Entferne von der liste das \n am ende dirFiles.pop_back(); + + //Führe Function aus, die überprüft ob die serie existiert - std::string nameInUrl =pageManager.checkName(settings->name); + std::string nameInUrl =pageManager.checkName(settings->pages, settings->name); if(nameInUrl == "-2") return 67; else if(nameInUrl == "-1") { @@ -684,6 +686,14 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no return 0; } + //Check for last Update.. (glaub hier nocghmal die funktion, um datei zu erstellen, auch wenn ausgabe deaktiviert is, kann aber auch sein dass der teil ghier weg gehört) + if(checkLastUpdate(settings) != 0) { + if(settings->debugMode) + std::cerr << ">>> Debug In " << __FUNCTION__ << ": checkLastUpdate function failed." << std::endl; + return -1; + } + + std::ifstream ifs(settings->serienListPath); if(!ifs.is_open()) { std::cout << " => Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl; @@ -702,15 +712,9 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no } } - //Check for last Update.. - if(checkLastUpdate(settings) != 0) { - if(settings->debugMode) - std::cerr << ">>> Debug In " << __FUNCTION__ << ": checkLastUpdate function failed." << std::endl; - return -1; - } //Save file in string: - std::string serienListe((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + std::string serienListe = std::string((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); //Suche alle Möglichkeiten std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower); @@ -749,11 +753,35 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no std::stringstream strstream(finds); std::string line; std::cout << " => Für '" << settings->name << "' wurde(n) folgende Serie(n) gefunden: " << std::endl; + + std::string lastPageUrl; while (getline(strstream, line)) { - std::cout << " > " << line.substr(line.find_last_of('|') + 1, std::string::npos ) - << "\t[" << line.substr(line.find("|/") + 2, line.find("|", line.find("|/") + 2) - line.find("|/") - 2) << "]" - << ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl; - } + + //splitting + ///Nadia The Secret, Fushigi no Nadia|/nadia-zauberstein|Nadia und Zauberstein|seriento + // into Vector + + std::vector parts; + std::istringstream f(line + "|"); + std::string p; + while (getline(f, p, '|').good()) + parts.push_back(p); + if(parts.size() != 4) { + std::cout << " => Error: Invalid SerienListeEintrag: '" << line << "'" << parts.size() << std::endl; + continue; + } + + if( lastPageUrl != parts.at(3) ) { + std::cout << ((settings->colorless) ? "" : "\033[93m") << "Auf '" << parts.at(3) << "'..." << ((settings->colorless) ? "" : "\033[0m") << std::endl; + lastPageUrl = parts.at(3); + } + + std::cout << " > " << parts.at(2) << "\t[" << parts.at(1).erase(0, 1) << "]" + << ( (line[0] == '|') ? "" : "\t( " + parts.at(0) + " )" ) << std::endl; + + ///That Time I Got Reincarnated as a Slime|/tensei-shitara-slime-datta-ken|Tensei Shitara Slime Datta Ken|ANIME + } /// > Tensei Shitara Slime Datta Ken [tensei-shitara-slime-datta-ken] ( That Time I Got Reincarnated as a Slime ) + if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": success." << std::endl; return 0; @@ -769,7 +797,7 @@ int ProgramManager::infoModus(Settings *settings) } //Führe Function aus, die überprüft ob die serie existiert - std::string nameInUrl = pageManager.checkName(settings->name); + std::string nameInUrl;//<>/ = pageManager.checkName(settings->name); if(nameInUrl == "-2") return 145; else if(nameInUrl == "-1") { @@ -1361,82 +1389,91 @@ int ProgramManager::cleanUpSettingsAndCache(Settings *settings) int ProgramManager::searchModus_update(Settings *settings) { - Reply reply = pageManager.getServerRequest("https://serienstream.sx/serien-alphabet"); - if(reply.html == "-1") { - if(settings->debugMode) - std::cerr << ">>> Debug In " << __FUNCTION__ << ": getServerRequest function failed." << std::endl; - return 21; - } - else if(reply.html.find("") == std::string::npos ) { - std::cout << " => Error: Konnte in searchModus_update() nicht finden." << std::endl; - return 22; - } - - std::string serienListe = replace( pageManager.grep( reply.html, "data-alternative-title" ), "", "\n" ); - - std::string tests[] = {"\" href=\"", "
  • ", }; - for ( auto t : tests ) { - if(reply.html.find( t ) == std::string::npos) { - if(settings->debugMode) - std::cerr << ">>> Debug In " << __FUNCTION__ << ": hatml doesnt contain:'" << t << "' after preparing." << std::endl; - return 51; - } - } - - - - //...\n
  • 2012 - Das Jahr Null\n... - serienListe = replace(serienListe, "
  • 2012 - Das Jahr Null\n... - serienListe = replace(serienListe, "\" href=\"", "|"); - //...\n|/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null\n... - serienListe = replace(serienListe, "|/serie/stream/", "|/"); - - std::stringstream strstream(serienListe); + std::string list; std::string line; - serienListe.clear(); - while (getline(strstream, line)) { - if(line.find(" title=\"") == std::string::npos) - continue; + for ( const auto &page : settings->pages ) { + std::cout << " -> Updating '" << page.name_id << "'..." << std::endl; - line.erase(line.find(" title="), line.find(">") - line.find(" title=")); - //...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null\n... - line = replace(line, "\">", "|"); - //...\n|/serie/stream/2012-das-jahr-null|2012 - Das Jahr Null\n... - line = replace(line, "", ""); - //...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n... + Reply reply = pageManager.getServerRequest("https://" + page.url + page.urlAlphabetSerienList); + + + if(reply.html == "-1") { + if(settings->debugMode) + std::cerr << ">>> Debug In " << __FUNCTION__ << ": getServerRequest function failed." << std::endl; + return 21; + } + else if(reply.html.find("") == std::string::npos ) { + std::cout << " => Error: Konnte in searchModus_update() nicht finden." << std::endl; + return 22; + } + + std::string serienListe = replace( pageManager.grep( reply.html, "data-alternative-title" ), "
  • ", "\n" ); + + std::string tests[] = {"\" href=\"", "
  • ", }; + for ( auto t : tests ) { + if(reply.html.find( t ) == std::string::npos) { + if(settings->debugMode) + std::cerr << ">>> Debug In " << __FUNCTION__ << ": hatml doesnt contain:'" << t << "' after preparing." << std::endl; + return 51; + } + } + + //...\n
  • 2012 - Das Jahr Null\n... + serienListe = replace(serienListe, "
  • 2012 - Das Jahr Null\n... + serienListe = replace(serienListe, "\" href=\"", "|"); + //...\n|/serie /stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null\n... + serienListe = replace(serienListe, "|" + page.UrlDir, "|/"); + + std::stringstream strstream(serienListe); + serienListe.clear(); + + while (getline(strstream, line)) { + if(line.find(" title=\"") == std::string::npos) + continue; + + line.erase(line.find(" title="), line.find(">") - line.find(" title=")); + //...\n|/serie/ stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null\n... + line = replace(line, "\">", "|"); + //...\n|/serie/ stream/2012-das-jahr-null|2012 - Das Jahr Null\n... + line = replace(line, "", ""); + //...\n|/serie/ stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n... + + ///Nadia The Secret, Fushigi no Nadia|/nadia-zauberstein|Nadia und Zauberstein|seriento + serienListe += line + "|" + page.url + "\n"; + } + if(serienListe.length() > 0) + serienListe.pop_back(); + + //Entferne Html Sonderzeichen + serienListe = replace(serienListe, "&quot;", "\""); // + + serienListe = replace(serienListe, "&", "&"); // + serienListe = replace(serienListe, "<", "<"); // + serienListe = replace(serienListe, ">", ">"); // + + serienListe = replace(serienListe, "
    ", " "); // + serienListe = replace(serienListe, """, "\""); // + serienListe = replace(serienListe, "'", "'"); // + + list += serienListe; - serienListe += line + "\n"; } - if(serienListe.length() > 0) - serienListe.pop_back(); - - //Entferne Html Sonderzeichen - serienListe = replace(serienListe, "&quot;", "\""); // - - serienListe = replace(serienListe, "&", "&"); // - serienListe = replace(serienListe, "<", "<"); // - serienListe = replace(serienListe, ">", ">"); // - - serienListe = replace(serienListe, "
    ", " "); // - serienListe = replace(serienListe, """, "\""); // - serienListe = replace(serienListe, "'", "'"); // - - //Anzahl der Serien/Zeilen vorher: ssize_t countBef = 0; - std::ifstream myFileBef(settings->serienListPath); + std::ifstream myFileBef(settings->serienListPath ); std::string alteListe; if(myFileBef.is_open()) { - for(countBef = 0; std::getline(myFileBef,line); ++countBef) { + for(countBef = 0; std::getline(myFileBef, line); ++countBef) { //Speicher alteListe für verglkeich nach Update alteListe.append(line + "\n"); //Vergeliche neue und alte list => entfernte Serien - if(line != "" && serienListe.find(line) == std::string::npos) { - std::cout << ((settings->colorless) ? "" : "\033[91m") << "Entfernt: '" << line.substr(line.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m") + if(line != "" && list.find(line) == std::string::npos) { + std::string tmp = std::string(line).erase(line.find_last_of('|')); + std::cout << ((settings->colorless) ? "" : "\033[91m") << "Entfernt: '" << tmp.substr(tmp.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m") << std::endl; } } @@ -1444,24 +1481,25 @@ int ProgramManager::searchModus_update(Settings *settings) } //Schreibe die Liste in das TextFile - std::ofstream ofs(settings->serienListPath, std::ios::trunc); + std::ofstream ofs(settings->serienListPath , std::ios::trunc); if(!ofs.is_open()) { perror("Konnte SerienListe-Datei nicht öffnen"); return 111; } else { //Schreibe Liste in das TextFile - ofs << serienListe << std::endl; + ofs << list << std::endl; ofs.close(); } //Anzahl der Zeile nachher ssize_t countAf = 0; - std::ifstream myFileAf(settings->serienListPath); + std::ifstream myFileAf(settings->serienListPath ); if(myFileAf.is_open()) { for(countAf = 0; std::getline(myFileAf,line); ++countAf) { //Vergeliche neu mit Alt => gib neue Serien aus if(line != "" && alteListe.find(line) == std::string::npos) { - std::cout << ((settings->colorless) ? "" : "\033[92m") << "Neu: '" << line.substr(line.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m") + std::string tmp = std::string(line).erase(line.find_last_of('|')); + std::cout << ((settings->colorless) ? "" : "\033[92m") << "Neu: '" << tmp.substr(tmp.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m") << std::endl; } } @@ -1473,7 +1511,11 @@ int ProgramManager::searchModus_update(Settings *settings) std::cout << ((settings->colorless) ? "" : "\033[93m") << "Serienunterschied: " << ( ((countAf - countBef) > 0) ? "+" : "") << countAf - countBef << " Serien." << "\033[0m" << std::endl; - //Speicher Dateim des Updates... + + + + + //Speicher Datum des Updates... ofs.open(settings->lastUpdateDateFilePath, std::ios::trunc); if(!ofs.is_open()) { perror("Konnte UpdateDate-Datei nicht öffnen"); @@ -1484,7 +1526,6 @@ int ProgramManager::searchModus_update(Settings *settings) ofs.close(); } - return 0; }