From c11c43484ce1489b9559291810e54f9d8c82507a Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 20 Sep 2019 21:47:02 +0200 Subject: [PATCH] v2.8.0: add news function --- parameterManager.cpp | 79 ++++++++++++++++++++++++++++++++++++++-- parameterManager.h | 8 +++- programManager.cpp | 87 +++++++++++++++++++++++++++++++++++++++----- programManager.h | 1 + 4 files changed, 160 insertions(+), 15 deletions(-) diff --git a/parameterManager.cpp b/parameterManager.cpp index f5a1a3c..d8c0947 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -60,7 +60,7 @@ int manageParameter(Settings &settings, int argc, char **argv) return 1; } - std::vector res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); + std::vector res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews", argv[1]); if(res.size() != 1) { if(res.size() == 0) std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl; @@ -115,6 +115,10 @@ int manageParameter(Settings &settings, int argc, char **argv) unterOption_clean(&settings, argc, argv); return -1; + } else if (strncmp(argv[1], "news", strlen(argv[1])) == 0) { + argv[1][0] = '\0'; + return unterOption_news(&settings, argc, argv); + } else { std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; @@ -706,7 +710,7 @@ int unterOption_search(Settings *settings, int argc, char **argv) }; - while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { + while( ( c = getopt_long (argc, argv, "p:hcdeu", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': if(optarg && setS5ProxytoSettings(*settings, optarg) != 0) @@ -810,7 +814,7 @@ int unterOption_info(Settings *settings, int argc, char **argv) }; - while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { + while( ( c = getopt_long (argc, argv, "p:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': if(optarg && setS5ProxytoSettings(*settings, optarg) != 0) @@ -1058,3 +1062,72 @@ bool createDirIsOk(std::string path) } else return dirExists(path); } + +int unterOption_news(Settings *settings, int argc, char **argv) +{ + settings->modus = Modus::NEWS_MODUS; + + int c = 0; + const option long_opts[] = { + {"socks5-proxy", required_argument, nullptr, 'p'}, + + {"help", no_argument, nullptr, 'h'}, + {"colorless", no_argument, nullptr, 'c'}, + {"debug-mode", no_argument, nullptr, 'd'}, + + {nullptr, no_argument, nullptr, 0} + + }; + + while( ( c = getopt_long (argc, argv, "p:hcd", long_opts, nullptr) ) != -1 ) { + switch(c) { + case 'p': + if(optarg && setS5ProxytoSettings(*settings, optarg) != 0) + return 2; + break; + case 'h': + unterOption_news_help(settings->programName); + return -1; + case 'c': + settings->colorless = true; + if(settings->debugMode) + std::cout << "Farblos: true" << std::endl; + break; + case 'd': + settings->debugMode = true; + if(settings->debugMode) + std::cout << "Debug Modus: true" << std::endl; + break; + default: + std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl; + std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl; + return 21; + } + } + + if(settings->debugMode) + std::cout << "Modus: Search_MODUS" << std::endl; + + return 0; +} + + +void unterOption_news_help(std::string programName) +{ + std::cout << "Aufruf: " << programName << " news [OPTION]..." << std::endl << std::endl; + + std::cout << "Beschreibung:" << std::endl + << " Mit dieser Unterfunktion kann man die neuesten Folgen auf s.to sehen." << std::endl << std::endl; + + std::cout << "OPTIONEN:" << std::endl + << " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl + << " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl + << " Standart: 127.0.0.1:9050" << std::endl << std::endl + << " -c, --colorless" << std::endl + << " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl + << " -d, --debug-mode" << std::endl + << " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl + << " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl + << " -h, --help" << std::endl + << " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl; +} diff --git a/parameterManager.h b/parameterManager.h index 777abed..d14261b 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -27,7 +27,8 @@ enum Modus { DEFAULT_MODUS = 0, DIRECT_LINK_MODUS = 1, SEARCH_MODUS = 2, - INFO_MODUS = 3 + INFO_MODUS = 3, + NEWS_MODUS = 4 }; @@ -46,7 +47,7 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng", genaueHoster = "", - version = "2.7.2", + version = "2.8.0", defaultFileVersion="1.3", outputFilePath = "", default_checkPath = "", @@ -98,6 +99,9 @@ void unterOption_info_help(std::string programName); void unterOption_clean(Settings * settings, int argc, char **argv); +int unterOption_news(Settings * settings, int argc, char **argv); +void unterOption_news_help(std::string programName); + int setS5ProxytoSettings(Settings &settings, std::string optarg); diff --git a/programManager.cpp b/programManager.cpp index 2e1d013..36de585 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -27,17 +27,20 @@ int ProgramManager::start(Settings *settings) return 174; } + switch (settings->modus) { - case Modus::DEFAULT_MODUS: - return defaultModus(settings); - case Modus::DIRECT_LINK_MODUS: - return directLinkModus(settings); - case Modus::SEARCH_MODUS: - return searchModus(settings); - case Modus::INFO_MODUS: - return infoModus(settings); - default: - return -1; + case Modus::DEFAULT_MODUS: + return defaultModus(settings); + case Modus::DIRECT_LINK_MODUS: + return directLinkModus(settings); + case Modus::SEARCH_MODUS: + return searchModus(settings); + case Modus::INFO_MODUS: + return infoModus(settings); + case Modus::NEWS_MODUS: + return newsModus(settings); + default: + return -1; } } @@ -630,6 +633,70 @@ int ProgramManager::infoModus(Settings *settings) return 0; } +int ProgramManager::newsModus(Settings *settings) +{ + size_t pos = 0; + std::string html = pageManager.getServerRequest("https://s.to/neue-episoden").html; + if(html == "-1") + return 1; + + if( (pos = html.find("
")) == std::string::npos ) { + std::cout << " => Error: Konnte Position von '
'' nicht finden" <
")) == std::string::npos ) { + std::cout << " => Error: Konnte Position von '
' nicht finden" <"); + size_t pos2 = line.find(""); + if(pos == std::string::npos) { + std::cout << " => Error: Konnte Position von '' nicht finden" < Error: Konnte Position von '' nicht finden" <")) == std::string::npos) { + std::cout << " => Error: Konnte Position von 'blue2\">' nicht finden" <", pos)) == std::string::npos) { + std::cout << " => Error: Konnte Position von '' nicht finden" <")) == std::string::npos) { + std::cout << " => Error: Konnte Position von 'Right\">' nicht finden" <", pos)) == std::string::npos) { + std::cout << " => Error: Konnte Position von '' nicht finden" < " << ((settings->colorless) ? "" : "\033[97m") << date << ((settings->colorless) ? "" : "\033[0m") << ": " + << ((settings->colorless) ? "" : "\033[96m") << name << ((settings->colorless) ? "" : "\033[0m") << ": " + << ((settings->colorless) ? "" : "\033[92m") << id << ((settings->colorless) ? "" : "\033[0m") << std::endl; + } + + return 0; +} + + int ProgramManager::searchModus_update(Settings *settings) { Reply reply = pageManager.getServerRequest("https://s.to/serien"); diff --git a/programManager.h b/programManager.h index 4ffe071..5bf8aaf 100644 --- a/programManager.h +++ b/programManager.h @@ -46,6 +46,7 @@ private: int directLinkModus(Settings * settings); int searchModus(Settings * settings, std::string *saveTo = nullptr); int infoModus(Settings * settings); + int newsModus(Settings *settings); PageManager pageManager; std::vector threadList;