From a4e86c3250170f19b6e476e923a1d095b2a26faf Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 6 Apr 2020 14:31:34 +0200 Subject: [PATCH] v4.0.3: language & hoster : ignore low/upper writing + move replace vivo things in getLinkAfterHosterBasedOperation() Funktion --- ...in (conflicted copy 2020-04-06 133915).cpp | 22 +++++++++ src/pageManager.cpp | 48 +++++++++++++++++-- src/pageManager.h | 3 +- src/parameterManager.h | 2 +- src/programManager.cpp | 14 ++++-- 5 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 src/main (conflicted copy 2020-04-06 133915).cpp diff --git a/src/main (conflicted copy 2020-04-06 133915).cpp b/src/main (conflicted copy 2020-04-06 133915).cpp new file mode 100644 index 0000000..bb5e4dc --- /dev/null +++ b/src/main (conflicted copy 2020-04-06 133915).cpp @@ -0,0 +1,22 @@ +#include "programManager.h" + +int main(int argc, char *argv[]) +{ + + std::cout << "test: ,.12-.*'§ und: " << PageManager::upper_string("abced<<,.12-.*'§") << std::endl; + + return 0; + + ProgramManager mainProgram; + Settings settings; + int res = manageParameter(settings, argc, argv); + if(res == -1) + return 0; + else if(res != 0) { + if(settings.debugMode) + std::cout << " => Error: Das Auswerten der Parameter ist fehlgeschlagen!" << std::endl; + return res; + } else { + return mainProgram.start(&settings); + } +} diff --git a/src/pageManager.cpp b/src/pageManager.cpp index 1b09128..0613a4a 100644 --- a/src/pageManager.cpp +++ b/src/pageManager.cpp @@ -471,11 +471,11 @@ std::string PageManager::chooseHosterLink(std::string HosterList, std::string Ho if(langId == "") continue; - else if ( langId == "GerDub" ) + else if ( upper_string( langId ) == "GERDUB" ) LangId=1; - else if ( langId == "Eng" ) + else if ( upper_string( langId ) == "ENG" ) LangId=2; - else if ( langId == "GerSub" ) + else if ( upper_string( langId ) == "GERSUB" ) LangId=3; else { std::cout << " => Error: Unbekannte Sprache: " << langId << std::endl; @@ -493,15 +493,25 @@ std::string PageManager::chooseHosterLink(std::string HosterList, std::string Ho continue; } + //Upper all Hoster Name in List: + for (size_t posHoster = LanguageSortedHoster.find("hoster=\""); posHoster != std::string::npos; posHoster = LanguageSortedHoster.find("hoster=\"", posHoster + 8)) { + size_t posNextAnfz = LanguageSortedHoster.find("\"", posHoster + 8); + if(posNextAnfz == std::string::npos) { + std::cout << " => Error: Konnte \" in chooseHosterLink() nicht finden." << std::endl; + break; + } else + LanguageSortedHoster.replace(posHoster + 8, posNextAnfz - posHoster - 8, upper_string(LanguageSortedHoster.substr(posHoster + 8, posNextAnfz - posHoster - 8)) ); + } + //Für jeden Angegebenen Hoster: while (getline(SListHoster, hoster).good()) { //Wenn es den hoster bei dieser prache nicht gibt, wähle nächsten - if(LanguageSortedHoster.find("hoster=\"" + hoster + "\"") == std::string::npos) { + if(LanguageSortedHoster.find( "hoster=\"" + upper_string(hoster) + "\"" ) == std::string::npos) { if(withWarnMsg) std::cout << "Warnung: Hoster " << hoster << " gibt es bei der sprache" << langId << " nicht " << std::endl; continue; } - Line = grep(LanguageSortedHoster + "\n", ("hoster=\"" + hoster + "\"" ) ); + Line = grep(LanguageSortedHoster + "\n", ("hoster=\"" + upper_string(hoster) + "\"" ) ); pos = Line.find("href=\""); if(pos == std::string::npos) { std::cout << " => Error: Konnte 'href=\"' in chooseHosterLink() nicht finden." << std::endl; @@ -526,3 +536,31 @@ std::string PageManager::chooseHosterLink(std::string HosterList, std::string Ho } return ""; } + +std::string PageManager::getLinkAfterHosterBasedOperation(std::string url) +{ + size_t pos1 = 0, pos2 = 0; + if(debugMode) + std::cout << "Convert url: " << url << " ->"<< std::endl; + + if((pos1 = url.find("://")) == std::string::npos) { + std::cout << " => Error: Konnte '://' in getLinkAfterHosterBasedOperation() nicht finden." << std::endl; + return ""; + } else if((pos2 = url.find(".", pos1 + 3)) == std::string::npos) { + std::cout << " => Error: Konnte '.' nach '://' in getLinkAfterHosterBasedOperation() nicht finden." << std::endl; + return ""; + } + + std::string hoster = url.substr(pos1 + 3, pos2 - pos1 - 3); + if(hoster == "vivo") { + url = replace(url, "/embed/", "/"); + url = replace(url, "http://", "https://"); + + } else if (hoster == "...") { + + } + + if(debugMode) + std::cout << " -> zu... " << url << std::endl; + return url; +} diff --git a/src/pageManager.h b/src/pageManager.h index 83870c8..9b6af42 100644 --- a/src/pageManager.h +++ b/src/pageManager.h @@ -38,10 +38,11 @@ public: std::string checkName(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); 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); + static std::string upper_string(const std::string& str); size_t getDate(); std::string getExePath(); diff --git a/src/parameterManager.h b/src/parameterManager.h index cb7cd7d..8c93666 100644 --- a/src/parameterManager.h +++ b/src/parameterManager.h @@ -91,7 +91,7 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng,", genaueHoster = "", - version = "4.0.2", + version = "4.0.3", defaultFileVersion="1.8", default_checkPath = "", default_Searchmuster = "S%Staffel%E%Folge%"; diff --git a/src/programManager.cpp b/src/programManager.cpp index 4d00d51..cbfdccb 100644 --- a/src/programManager.cpp +++ b/src/programManager.cpp @@ -130,8 +130,11 @@ void * threadFunction(void * data) { // get NO-Redirect Link after getUrlAfterRedirect Function } else { - // für Vivo... - newUrl = replace(newUrl, "/embed/", "/"); + if( (newUrl = myThreadData->pageManager->getLinkAfterHosterBasedOperation(newUrl)) == "") { + if(myThreadData->settings->debugMode) + std::cout << " => Error in getLinkAfterHosterBasedOperation() -> exit threadFunction()" << std::endl; + return myThreadData->setState(22); + } myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + clearColor; if(myThreadData->settings->outputFilePaths.size() != 0) { @@ -1540,8 +1543,11 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou return 0; //sonst war die umwandlung erfolgreich } else { - // für Vivo... - newUrl = replace(newUrl, "/embed/", "/"); + if( (newUrl = pageManager.getLinkAfterHosterBasedOperation(newUrl)) == "") { + if(settings->debugMode) + std::cout << " => Error in getLinkAfterHosterBasedOperation() -> exit convertLink()" << std::endl; + return 118; + } std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << green << newUrl << ((settings->colorless) ? "" : "\033[0m") << std::endl; if(settings->outputFilePaths.size() != 0)