diff --git a/src/logger.cpp b/src/logger.cpp index a5e9a56..1dbc46e 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -23,7 +23,8 @@ int Logger::logCommandLine(std::string logText) { std::time_t now = std::time(nullptr); struct tm *tm_now = localtime(&now); - std::string date(std::to_string(tm_now->tm_mday) + "." + std::to_string(tm_now->tm_mon +1) + "." + std::string date((tm_now->tm_mday < 10 ? "0" : "") + std::to_string(tm_now->tm_mday) + "." + + (tm_now->tm_mon +1 < 10 ? "0" : "" ) + std::to_string(tm_now->tm_mon +1) + "." + std::to_string(1900 + tm_now->tm_year) + " - " + std::to_string(tm_now->tm_hour) + ":" + std::to_string(tm_now->tm_min)); return writetoFile(date + ": \"" + logText + "\""); } diff --git a/src/pageManager.cpp b/src/pageManager.cpp index 92069f3..3a0ed83 100644 --- a/src/pageManager.cpp +++ b/src/pageManager.cpp @@ -446,18 +446,21 @@ int PageManager::compareVersions(std::string Version1, std::string Version2) } -int PageManager::writeToFile(std::string path, std::string text) +int PageManager::writeToFile(std::vector paths, std::string text) { - if(path == "") + if(paths.size() == 0) return 0; std::ofstream of; - of.open(path, std::ios::out | std::ios::app); - if(!of.is_open()) { - perror(" => Error: Konnte Output Datei nicht öffnen"); - return -1; + for(auto path : paths) { + of.open(path, std::ios::out | std::ios::app); + if(!of.is_open()) { + perror((" => Error: Konnte Output: '" + path + "' Datei nicht öffnen").c_str()); + return -1; + } + of << text << std::endl; + of.close(); } - of << text << std::endl; - of.close(); + return 0; } diff --git a/src/pageManager.h b/src/pageManager.h index 2e77e6b..790c85d 100644 --- a/src/pageManager.h +++ b/src/pageManager.h @@ -48,7 +48,7 @@ public: int compareVersions(std::string Version1, std::string Version2); - int writeToFile(std::string path, std::string text); + int writeToFile(std::vector paths, std::string text); const std::string UrlPraefix = "https://s.to/serie/stream/"; std::string sock5Proxy; diff --git a/src/parameterManager.cpp b/src/parameterManager.cpp index 23fc7f9..1b0aa54 100644 --- a/src/parameterManager.cpp +++ b/src/parameterManager.cpp @@ -185,7 +185,13 @@ int loadDefaulOptions(Settings &settings) ofs << "# -> Einstellung gleicht dem Parameter -o [Pfad], --output-file," << std::endl; ofs << "# falls dieser in der ausgeführeten Unterfunktion vorhanden ist:" << std::endl; - ofs << "#OutputFile=/tmp/a" << std::endl << std::endl; + ofs << "# Hier auch mehrere Pfade Möglich..:" << std::endl; + ofs << "#OutputFile=/tmp/a" << std::endl; + ofs << "#OutputFile=/tmp/b" << std::endl; + ofs << "# -> Log-to-LogFile: Speichere Ausgabe im LogFile - LogFile u.a. beim" << std::endl; + ofs << "# JD2-Renamer Skript nötig. Auch anderer Pfad möglich." << std::endl; + ofs << "OutputFile=" << settings.logFilePath<< std::endl << std::endl; + ofs << "#" << std::endl << "# -> Einstellungen für default Modus:" << std::endl << "#" << std::endl << std::endl; @@ -319,9 +325,9 @@ int loadDefaulOptions(Settings &settings) std::cout << " > Defaults: search-AchteAufGroßUndKleinschreibung: " << settings.search_IgnoreUpperLower << std::endl; } else if (what == "OutputFile") { - settings.outputFilePath = data; + settings.outputFilePaths.push_back(data); if(settings.debugMode) - std::cout << " > Defaults: OutputFile: " << settings.outputFilePath << std::endl; + std::cout << " > Defaults: OutputFile: " << settings.outputFilePaths.back() << std::endl; } else if (what == "search_UpdateWarnungNachTagen") { if(!isNumber(data)) { @@ -333,11 +339,8 @@ int loadDefaulOptions(Settings &settings) if(settings.debugMode) std::cout << " > Defaults: search_UpdateWarnungNachTagen: " << settings.updateWarningDays << std::endl; - } else if (what == "") { - - } else if (what == "") { - - } else if (what == "") { + } else if (what == "test") { + //test } else { std::cout << " => Warnung: Unbekannte Default-Option: '" << what << "'." << std::endl; @@ -437,9 +440,9 @@ int unterOption_default(Settings *settings, int argc, char ** argv) break; case 'o': if(optarg) - settings->outputFilePath = optarg; + settings->outputFilePaths.push_back(optarg); if(settings->debugMode) - std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; + std::cout << "Pfad zu Output-Datei: " << settings->outputFilePaths.back() << std::endl; break; case 'e': @@ -703,9 +706,9 @@ int unterOption_url(Settings *settings, int argc, char **argv) break; case 'o': if(optarg) - settings->outputFilePath = optarg; + settings->outputFilePaths.push_back(optarg); if(settings->debugMode) - std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; + std::cout << "Pfad zu Output-Datei: " << settings->outputFilePaths.back() << std::endl; break; case 'c': settings->colorless = true; @@ -920,9 +923,9 @@ int unterOption_info(Settings *settings, int argc, char **argv) break; case 'o': if(optarg) - settings->outputFilePath = optarg; + settings->outputFilePaths.push_back(optarg); if(settings->debugMode) - std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; + std::cout << "Pfad zu Output-Datei: " << settings->outputFilePaths.back() << std::endl; break; case 'h': unterOption_info_help(settings->programName); @@ -1497,6 +1500,8 @@ int unterOption_printLogFile(Settings *settings, int argc, char **argv) return 34; } + // Main-Program:...... + if(printMode) std::cout << Logger(settings->logFilePath).getLogText() << std::endl; if(ClearMode) diff --git a/src/parameterManager.h b/src/parameterManager.h index dbc4d07..6f871b1 100644 --- a/src/parameterManager.h +++ b/src/parameterManager.h @@ -84,12 +84,13 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng,", genaueHoster = "", - version = "3.8.0", - defaultFileVersion="1.7", - outputFilePath = "", + version = "3.9.0", + defaultFileVersion="1.8", default_checkPath = "", default_Searchmuster = "S%Staffel%E%Folge%"; + std::vector outputFilePaths; + Modus modus = Modus::EXIT; bool colorless = false, debugMode = false, diff --git a/src/programManager.cpp b/src/programManager.cpp index 495df45..fc566b9 100644 --- a/src/programManager.cpp +++ b/src/programManager.cpp @@ -83,7 +83,7 @@ void * threadFunction(void * data) { //Wenn gar keine Links vorhanden sind: if(allLinks == "") { myThreadData->returnValue = " => " + red + "KEINEN Hoster für die Folge " + folgenID + " gefunden." + clearColor; - if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { + if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { if(myThreadData->settings->debugMode) std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl; return myThreadData->setState(14); @@ -95,7 +95,7 @@ void * threadFunction(void * data) { + myThreadData->pageManager->replace( myThreadData->pageManager->replace( myThreadData->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ), "data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\""); - if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, + if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { if(myThreadData->settings->debugMode) std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl; @@ -129,8 +129,8 @@ void * threadFunction(void * data) { // get NO-Redirect Link after getUrlAfterRedirect Function } else { myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + clearColor; - if(myThreadData->settings->outputFilePath != "") { - if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) { + if(myThreadData->settings->outputFilePaths.size() != 0) { + if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) { if(myThreadData->settings->debugMode) std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl; return myThreadData->setState(18); @@ -143,8 +143,8 @@ void * threadFunction(void * data) { } myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + clearColor; - if(myThreadData->settings->outputFilePath != "") - if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0) { + if(myThreadData->settings->outputFilePaths.size() != 0) + if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0) { if(myThreadData->settings->debugMode) std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl; return myThreadData->setState(19); @@ -413,8 +413,8 @@ int ProgramManager::defaultModus(Settings *settings) } //Write Name to File if -o is set und kein TXT-FILE angegeben wird - if(settings->outputFilePath != "" && !fileExists( settings->default_checkPath )) - if(pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name) != 0) { + if(settings->outputFilePaths.size() != 0 && !fileExists( settings->default_checkPath )) + if(pageManager.writeToFile(settings->outputFilePaths, "Name: " + settings->name) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile Function fails when write Name." << std::endl; return 31; @@ -759,7 +759,7 @@ int ProgramManager::infoModus(Settings *settings) } //write Name to file - if(pageManager.writeToFile(settings->outputFilePath, "\n\nSerie: " + settings->name + " (" + nameInUrl + ")") != 0) + if(pageManager.writeToFile(settings->outputFilePaths, "\n\nSerie: " + settings->name + " (" + nameInUrl + ")") != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; @@ -803,7 +803,7 @@ int ProgramManager::infoModus(Settings *settings) std::cout << std::endl << green << "Die Staffel " << staffel << " hat " << folgen << " Folge" << ((folgen > 1) ? "n" : "") << "." << white << std::endl << std::endl; - if(pageManager.writeToFile(settings->outputFilePath, "\nDie Staffel " + std::to_string(staffel) + if(pageManager.writeToFile(settings->outputFilePaths, "\nDie Staffel " + std::to_string(staffel) + " hat " + std::to_string(folgen) + " Folge" + ((folgen > 1) ? "n" : "") + ".\n") != 0) { if(settings->debugMode) @@ -848,7 +848,7 @@ int ProgramManager::infoModus(Settings *settings) << " ( " << blue << "S" << ( (staffel < 10) ? "0" : "" ) << staffel << "E" << ( ( atoi( line.substr(0, pos).c_str() ) < 10) ? "0" : "" ) << line.substr(0, pos) << lila << " ):" << white <outputFilePath, "Ep. " + std::string( (gesammtFolge < 100) ? ( (gesammtFolge < 10) ? "00" : "0" ) : "" ) + if(pageManager.writeToFile(settings->outputFilePaths, "Ep. " + std::string( (gesammtFolge < 100) ? ( (gesammtFolge < 10) ? "00" : "0" ) : "" ) + std::to_string(gesammtFolge) + " ( S" + ( (staffel < 10) ? "0" : "" ) + std::to_string(staffel) + "E" + ( ( atoi( line.substr(0, pos).c_str() ) < 10) ? "0" : "" ) + line.substr(0, pos) + " ):" ) != 0) { if(settings->debugMode) @@ -868,7 +868,7 @@ int ProgramManager::infoModus(Settings *settings) titel = line.substr(0, pos); if(titel != "") { std::cout << lila << " > Titel 1: " << Lightyellow << titel << white << std::endl; - if(pageManager.writeToFile(settings->outputFilePath, " > Titel 1: " + titel) != 0) { + if(pageManager.writeToFile(settings->outputFilePaths, " > Titel 1: " + titel) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 110; @@ -887,7 +887,7 @@ int ProgramManager::infoModus(Settings *settings) titel = line.substr(0, pos); if(titel != "") { std::cout << lila << " > Titel 2: " << Darkyellow << titel << white << std::endl; - if(pageManager.writeToFile(settings->outputFilePath, " > Titel 2: " + titel) != 0) { + if(pageManager.writeToFile(settings->outputFilePaths, " > Titel 2: " + titel) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 120; @@ -1004,7 +1004,7 @@ int ProgramManager::infoModus(Settings *settings) for( const auto &e : genres) all_genres += e + " "; - if(pageManager.writeToFile(settings->outputFilePath, "\nProduktion von " + startStopDates[0] + " bis " + startStopDates[1] + "\n" + if(pageManager.writeToFile(settings->outputFilePaths, "\nProduktion von " + startStopDates[0] + " bis " + startStopDates[1] + "\n" "FSK: " + fsk + "\n" + "Cover Bild: " + coverLink + "\n" + "Genre(s): " + all_genres + "\n" "\nBeschreibung: " + description + "\n") != 0) { @@ -1462,7 +1462,8 @@ int ProgramManager::listDir(std::string &list,std::string path, int maxDepth, bo listDir(list, (path + dp->d_name + ((path.find("/") == std::string::npos) ? "\\" : "/") ), maxDepth, debugMode); } else { list.append( std::string(dp->d_name) + "\n" ); - std::cout << " > " << dp->d_name << std::endl; + if(debugMode) + std::cout << " > " << dp->d_name << std::endl; } } closedir(dirp); @@ -1481,7 +1482,7 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) { if(allLinks == "") { std::cout << " => " << red << "KEINEN Hoster für die Folge " << folgenID << " gefunden." << ((settings->colorless) ? "" : "\033[0m") << std::endl; - if(pageManager.writeToFile(settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { + if(pageManager.writeToFile(settings->outputFilePaths, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 130; @@ -1491,7 +1492,7 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou << "Alle Links:" << std::endl << pageManager.replace( pageManager.replace( pageManager.replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ), "data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\"") << std::endl; - if(pageManager.writeToFile(settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { + if(pageManager.writeToFile(settings->outputFilePaths, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 138; @@ -1524,8 +1525,8 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou } else if (newUrl == "https://s.to/") { std::cout << " => " << red << folgenID << ( (folgenID == "") ? "" : ": " ) << "Ungültige Url: 'https://s.to" << redirectLink << "'" << ((settings->colorless) ? "" : "\033[0m") << std::endl; - if(settings->outputFilePath != "") - if(pageManager.writeToFile(settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + "Ungültige Url: https://s.to" + redirectLink) != 0) { + if(settings->outputFilePaths.size() != 0) + if(pageManager.writeToFile(settings->outputFilePaths, folgenID + ( (folgenID == "") ? "" : ": " ) + "Ungültige Url: https://s.to" + redirectLink) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 108; @@ -1534,8 +1535,8 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou //sonst war die umwandlung erfolgreich } else { std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << green << newUrl << ((settings->colorless) ? "" : "\033[0m") << std::endl; - if(settings->outputFilePath != "") - if(pageManager.writeToFile(settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) { + if(settings->outputFilePaths.size() != 0) + if(pageManager.writeToFile(settings->outputFilePaths,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 108; @@ -1546,8 +1547,8 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou //nach 3temn Versuch gib error aus: std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << red << "https://s.to" << redirectLink << ((settings->colorless) ? "" : "\033[0m") << std::endl; - if(settings->outputFilePath != "") { - if(pageManager.writeToFile(settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0) { + if(settings->outputFilePaths.size() != 0) { + if(pageManager.writeToFile(settings->outputFilePaths, folgenID + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0) { if(settings->debugMode) std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl; return 114;