v3.9.2: fix replace funktion a second time... last time was onlyfast solution -> error: instett of string1 -> string2 -.length + => Colors in the LogFilePrintFunktion

This commit is contained in:
Markus 2020-02-23 15:38:31 +01:00
parent 7121158484
commit 3785962af5
6 changed files with 100 additions and 66 deletions

View File

@ -26,7 +26,7 @@ int Logger::logCommandLine(std::string logText)
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 + "\"");
return writetoFile( " -> " + date + ": \"" + logText + "\"");
}

int Logger::logSubLine(std::string line)

View File

@ -334,15 +334,6 @@ std::string PageManager::getLinks(std::string HTML)

}

std::string PageManager::replace(std::string str, std::string substr1, std::string substr2)
{
if(substr1 == "")
return str;
size_t index = 0;
for (index = str.find(substr1, index); index != std::string::npos; index = str.find(substr1, index + substr1.length() +1) )
str.replace(index, substr1.length(), substr2);
return str;
}

int PageManager::counterContains(std::string text, std::string substring_with_prozent_i_for_number, int starte_mit_dieser_Zahl)
{

View File

@ -39,7 +39,6 @@ public:
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 replace(std::string str, std::string substr1, std::string substr2);
int counterContains(std::string text, std::string substring_with_prozent_i_for_number, int starte_mit_dieser_Zahl = 1);
std::string grep(std::string text, std::string substring, bool IgnoreCaseSensetifity = false);
std::string upper_string(const std::string& str);

View File

@ -1468,14 +1468,15 @@ int unterOption_printLogFile(Settings *settings, int argc, char **argv)
const option long_opts[] = {
{"help", no_argument, nullptr, 'h'},
{"print", no_argument, nullptr, 'p'},
{"clear", no_argument, nullptr, 'c'},
{"clear", no_argument, nullptr, 'C'},
{"colorless", no_argument, nullptr, 'c'},
{nullptr, no_argument, nullptr, 0}

};

bool printMode = false, ClearMode = false;

while( ( c = getopt_long (argc, argv, "hpc", long_opts, nullptr) ) != -1 ) {
while( ( c = getopt_long (argc, argv, "hpCc", long_opts, nullptr) ) != -1 ) {
switch(c) {

case 'h':
@ -1483,9 +1484,18 @@ int unterOption_printLogFile(Settings *settings, int argc, char **argv)
return -1;
case 'p':
printMode = true;
if(settings->debugMode)
std::cout << "printMode: true" << std::endl;
break;
case 'C':
ClearMode = true;
if(settings->debugMode)
std::cout << "ClearMode: true" << std::endl;
break;
case 'c':
ClearMode = true;
settings->colorless = true;
if(settings->debugMode)
std::cout << "Farblos: true" << std::endl;
break;
default:
std::cout << "Aufruf: " << settings->programName << " log [OPTION]..." << std::endl;
@ -1495,15 +1505,36 @@ int unterOption_printLogFile(Settings *settings, int argc, char **argv)
}

if(!printMode && !ClearMode) {
std::cout << " => Error: Fehlende Parameter: -p / -c." << std::endl;
std::cout << " => Error: Fehlende Parameter: -p oder -c." << std::endl;
std::cout << "\"" << settings->programName << " log --help\" liefert weitere Informationen." << std::endl;
return 34;
}

// Main-Program:......

if(printMode)
std::string green = ((settings->colorless) ? "" : "\033[92m"),
pink = ((settings->colorless) ? "" : "\033[95m"),
orange =((settings->colorless) ? "" : "\033[33m"),
blue = ((settings->colorless) ? "" : "\033[94m"),
clearColor = ((settings->colorless) ? "" : "\033[0m");

if(printMode && settings->colorless)
std::cout << Logger(settings->logFilePath).getLogText() << std::endl;
else if(printMode) {
std::string text = settings->logFilePath + ":\n" + Logger(settings->logFilePath).getLogText();
//Command Lines
text = replace(text, ": \"", clearColor + ": " + blue + "\"");
text = replace(text, "\n -> ", "\n -> " + pink );

//Good Links
text = replace(text, ": http", clearColor + ": " + green + "http");
text = replace(text, "\nS", "\n" + orange + "S");

//Line/ Text - End
text = replace(text, "\n", "\n" + clearColor);
text.append(clearColor);
std::cout << text << std::endl;
}
if(ClearMode)
if(Logger(settings->logFilePath).clearFile())
return 12;
@ -1515,11 +1546,23 @@ void unterOption_printLogFile(std::string programName)
std::cout << "Aufruf: " << programName << " log [OPTION]..." << std::endl << std::endl;

std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man die Log Datei sehen/bearbeiten." << std::endl << std::endl;
<< " Mit dieser Unterfunktion kann man die Log Datei sehen/leeren." << std::endl << std::endl;

std::cout << "OPTIONEN:" << std::endl
<< " -p, --print" << std::endl
<< " Mit dieser Option wird das LogFile ausgegeben." << std::endl
<< " -c, --clear" << std::endl
<< " Mit dieser Option wird das LogFile geleert." << std::endl;
<< " -C, --clear" << std::endl
<< " Mit dieser Option wird das LogFile geleert." << std::endl
<< " -c, --colorless" << std::endl
<< " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl;
}

std::string replace(std::string str, std::string substr1, std::string substr2)
{
if(substr1 == "")
return str;
size_t index = 0;
for (index = str.find(substr1, index); index != std::string::npos; index = str.find(substr1, index + substr2.length() ) )
str.replace(index, substr1.length(), substr2);
return str;
}

View File

@ -83,7 +83,7 @@ struct Settings {
proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng,",
genaueHoster = "",
version = "3.9.1",
version = "3.9.2",
defaultFileVersion="1.8",
default_checkPath = "",
default_Searchmuster = "S%Staffel%E%Folge%";
@ -109,6 +109,7 @@ struct Settings {
unsigned maxThreads = 0;

};
std::string replace(std::string str, std::string substr1, std::string substr2);

int manageParameter(Settings &settings, int argc, char ** argv);
int loadDefaulOptions(Settings & settings);

View File

@ -82,22 +82,22 @@ void * threadFunction(void * data) {
if(Link == "") {
//Wenn gar keine Links vorhanden sind:
if(allLinks == "") {
myThreadData->returnValue = " => " + red + "KEINEN Hoster für die Folge " + myThreadData->pageManager->replace(folgenID, "E", " E") + " gefunden." + clearColor;
myThreadData->returnValue = " => " + red + "KEINEN Hoster für die Folge " + replace(folgenID, "E", " E") + " gefunden." + clearColor;
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, std::string("KEINEN Hoster für die Folge ")
+ myThreadData->pageManager->replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
+ replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(14);
}
//Wenn nur kein passender Link gefunden wurde:
} else {
myThreadData->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + myThreadData->pageManager->replace(folgenID, "E", " E") + " gefunden." + clearColor + "\n"
myThreadData->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + replace(folgenID, "E", " E") + " gefunden." + clearColor + "\n"
+ "Alle Links:" + "\n"
+ myThreadData->pageManager->replace(
myThreadData->pageManager->replace( myThreadData->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
+ replace(
replace( 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->outputFilePaths,
std::string("Keinen PASSENDEN Hoster für die Folge ") + myThreadData->pageManager->replace(folgenID, "E", " E")
std::string("Keinen PASSENDEN Hoster für die Folge ") + replace(folgenID, "E", " E")
+ std::string(" gefunden.")) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
@ -145,9 +145,9 @@ void * threadFunction(void * data) {
}

//error at 3 time
myThreadData->returnValue = " => " + myThreadData->pageManager->replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + clearColor;
myThreadData->returnValue = " => " + replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + clearColor;
if(myThreadData->settings->outputFilePaths.size() != 0)
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, myThreadData->pageManager->replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + Link) != 0) {
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePaths, replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + Link) != 0) {
if(myThreadData->settings->debugMode)
std::cerr << " => Debug: In Thread: "<< myThreadData->id << ": writeToFile Function failed." << std::endl;
return myThreadData->setState(19);
@ -498,7 +498,7 @@ int ProgramManager::defaultModus(Settings *settings)

//Überprüfe ob, wenn -C vorhanden, die Folge in dem Ordner bereits vorkommt.
if(settings->default_checkPath != "") {
if(dirFiles.find(pageManager.replace( pageManager.replace( settings->default_Searchmuster, "%Staffel%", ((staffel < 10) ? "0" : "") + std::to_string(staffel) ),
if(dirFiles.find(replace( replace( settings->default_Searchmuster, "%Staffel%", ((staffel < 10) ? "0" : "") + std::to_string(staffel) ),
"%Folge%", ((folge < 10) ? "0" : "") + std::to_string(folge) ) ) != std::string::npos) {
if(settings->debugMode)
std::cout << " > Skippe Folge: S" << staffel << "E" << folge << std::endl;
@ -605,7 +605,7 @@ int ProgramManager::directLinkModus(Settings *settings)
return 76;
}

std::istringstream iStrStream( pageManager.replace( settings->name, ",", "\n" ) + "\n" );
std::istringstream iStrStream( replace( settings->name, ",", "\n" ) + "\n" );
std::string line;

//if(pageManager.login(accountManager.getNextAccount()) != 0)
@ -828,8 +828,8 @@ int ProgramManager::infoModus(Settings *settings)
} else
html.erase(pos, std::string::npos);

html = pageManager.replace(html, "\n", "");
html = pageManager.replace(html, "</tr>", "\n");
html = replace(html, "\n", "");
html = replace(html, "</tr>", "\n");

std::stringstream folgenListe(html);
std::string line;
@ -949,18 +949,18 @@ int ProgramManager::infoModus(Settings *settings)
std::cout << " => Error: Konnte '\">' nicht finden." << std::endl;
return 86;
}
std::string description = pageManager.replace( pageManager.replace( tmp_reply.html.substr(pos + 23, pos2 - pos - 23), "\n", "" ), "<br />", "" );
std::string description = replace( replace( tmp_reply.html.substr(pos + 23, pos2 - pos - 23), "\n", "" ), "<br />", "" );

//remove bug text:
description = pageManager.replace(description, "&amp;quot;", "\""); //
description = replace(description, "&amp;quot;", "\""); //

description = pageManager.replace(description, "&amp;", "&"); //
description = pageManager.replace(description, "&lt;", "<"); //
description = pageManager.replace(description, "&gt;", ">"); //
description = replace(description, "&amp;", "&"); //
description = replace(description, "&lt;", "<"); //
description = replace(description, "&gt;", ">"); //

description = pageManager.replace(description, "<br />", " "); //
description = pageManager.replace(description, "&quot;", "\""); //
description = pageManager.replace(description, "&apos;", "'"); //
description = replace(description, "<br />", " "); //
description = replace(description, "&quot;", "\""); //
description = replace(description, "&apos;", "'"); //


//Genres
@ -1042,8 +1042,8 @@ int ProgramManager::newsModus(Settings *settings)
} else
html.erase(pos + 12);

html = pageManager.replace(html, "\n", "");
html = pageManager.replace(html, "class=\"row\"", "\n");
html = replace(html, "\n", "");
html = replace(html, "class=\"row\"", "\n");

std::stringstream strstream(html + "\n");
html.clear();
@ -1068,7 +1068,7 @@ int ProgramManager::newsModus(Settings *settings)
std::cout << " => Error: Konnte Position von '' nicht finden" <<std::endl;
return 6;
}
std::string id = pageManager.replace( line.substr(pos + 7, pos2 - pos - 7), " ", "");
std::string id = replace( line.substr(pos + 7, pos2 - pos - 7), " ", "");

if( (pos = line.find("Right\">")) == std::string::npos) {
std::cout << " => Error: Konnte Position von 'Right\">' nicht finden" <<std::endl;
@ -1106,7 +1106,7 @@ int ProgramManager::updateModus(Settings *settings)
std::cout << " => Error: Das herunterladen der neusten Version ist fehlgeschlagen." << std::endl;
return 1;
} else {
html = pageManager.replace(html, "\r", "");
html = replace(html, "\r", "");
}


@ -1285,7 +1285,7 @@ int ProgramManager::searchModus_update(Settings *settings)
return 22;
}

std::string serienListe = pageManager.replace( pageManager.grep( reply.html, "data-alternative-title" ), "</li>", "\n" );
std::string serienListe = replace( pageManager.grep( reply.html, "data-alternative-title" ), "</li>", "\n" );

if(reply.html.find("\" href=\"") == std::string::npos ||
reply.html.find("<li><a data-alternative-title=\"") == std::string::npos ||
@ -1298,11 +1298,11 @@ int ProgramManager::searchModus_update(Settings *settings)
}

//...\n<li><a data-alternative-title="" href="/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
serienListe = pageManager.replace(serienListe, "<li><a data-alternative-title=\"", "");
serienListe = replace(serienListe, "<li><a data-alternative-title=\"", "");
//...\n" href="/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
serienListe = pageManager.replace(serienListe, "\" href=\"", "|");
serienListe = replace(serienListe, "\" href=\"", "|");
//...\n|/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
serienListe = pageManager.replace(serienListe, "|/serie/stream/", "|/");
serienListe = replace(serienListe, "|/serie/stream/", "|/");

std::stringstream strstream(serienListe);
std::string line;
@ -1314,9 +1314,9 @@ int ProgramManager::searchModus_update(Settings *settings)

line.erase(line.find(" title="), line.find(">") - line.find(" title="));
//...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null</a>\n...
line = pageManager.replace(line, "\">", "|");
line = replace(line, "\">", "|");
//...\n|/serie/stream/2012-das-jahr-null|2012 - Das Jahr Null</a>\n...
line = pageManager.replace(line, "</a>", "");
line = replace(line, "</a>", "");
//...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n...

serienListe += line + "\n";
@ -1325,15 +1325,15 @@ int ProgramManager::searchModus_update(Settings *settings)
serienListe.pop_back();

//Entferne Html Sonderzeichen
serienListe = pageManager.replace(serienListe, "&amp;quot;", "\""); //
serienListe = replace(serienListe, "&amp;quot;", "\""); //

serienListe = pageManager.replace(serienListe, "&amp;", "&"); //
serienListe = pageManager.replace(serienListe, "&lt;", "<"); //
serienListe = pageManager.replace(serienListe, "&gt;", ">"); //
serienListe = replace(serienListe, "&amp;", "&"); //
serienListe = replace(serienListe, "&lt;", "<"); //
serienListe = replace(serienListe, "&gt;", ">"); //

serienListe = pageManager.replace(serienListe, "<br />", " "); //
serienListe = pageManager.replace(serienListe, "&quot;", "\""); //
serienListe = pageManager.replace(serienListe, "&apos;", "'"); //
serienListe = replace(serienListe, "<br />", " "); //
serienListe = replace(serienListe, "&quot;", "\""); //
serienListe = replace(serienListe, "&apos;", "'"); //



@ -1484,18 +1484,18 @@ 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 " << pageManager.replace(folgenID, "E", " E") << " gefunden." << ((settings->colorless) ? "" : "\033[0m") << std::endl;
if(pageManager.writeToFile(settings->outputFilePaths, std::string("KEINEN Hoster für die Folge ") + pageManager.replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
std::cout << " => " << red << "KEINEN Hoster für die Folge " << replace(folgenID, "E", " E") << " gefunden." << ((settings->colorless) ? "" : "\033[0m") << std::endl;
if(pageManager.writeToFile(settings->outputFilePaths, std::string("KEINEN Hoster für die Folge ") + replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 130;
}
} else {
std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << pageManager.replace(folgenID, "E", " E") << " gefunden." << ((settings->colorless) ? "" : "\033[0m") << std::endl
std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << replace(folgenID, "E", " E") << " gefunden." << ((settings->colorless) ? "" : "\033[0m") << std::endl
<< "Alle Links:" << std::endl
<< pageManager.replace( pageManager.replace( pageManager.replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
<< replace( replace( 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->outputFilePaths, std::string("Keinen PASSENDEN Hoster für die Folge ") + pageManager.replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
if(pageManager.writeToFile(settings->outputFilePaths, std::string("Keinen PASSENDEN Hoster für die Folge ") + replace(folgenID, "E", " E") + std::string(" gefunden.")) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 138;
@ -1526,10 +1526,10 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou

//wenn nach der Umwandlung https://s.to/ vorhanden ist, die ist wenn der Link Ungültig war:
} else if (newUrl == "https://s.to/") {
std::cout << " => " << red << pageManager.replace(folgenID, "E", " E") << ( (folgenID == "") ? "" : ": " ) << "Ungültige Url: 'https://s.to" << redirectLink << "'"
std::cout << " => " << red << replace(folgenID, "E", " E") << ( (folgenID == "") ? "" : ": " ) << "Ungültige Url: 'https://s.to" << redirectLink << "'"
<< ((settings->colorless) ? "" : "\033[0m") << std::endl;
if(settings->outputFilePaths.size() != 0)
if(pageManager.writeToFile(settings->outputFilePaths, pageManager.replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + "Ungültige Url: https://s.to" + redirectLink) != 0) {
if(pageManager.writeToFile(settings->outputFilePaths, replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + "Ungültige Url: https://s.to" + redirectLink) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 108;
@ -1549,9 +1549,9 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou
}

//nach 3temn Versuch gib error aus:
std::cout << " => " << pageManager.replace(folgenID, "E", " E") << ( (folgenID == "") ? "" : ": " ) << red << "https://s.to" << redirectLink << ((settings->colorless) ? "" : "\033[0m") << std::endl;
std::cout << " => " << replace(folgenID, "E", " E") << ( (folgenID == "") ? "" : ": " ) << red << "https://s.to" << redirectLink << ((settings->colorless) ? "" : "\033[0m") << std::endl;
if(settings->outputFilePaths.size() != 0) {
if(pageManager.writeToFile(settings->outputFilePaths, pageManager.replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0) {
if(pageManager.writeToFile(settings->outputFilePaths, replace(folgenID, "E", " E") + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0) {
if(settings->debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": writeToFile f() failed." << std::endl;
return 114;