forked from markus/S_New4
v2.8.0: add news function
This commit is contained in:
parent
a60e58b7fa
commit
c11c43484c
@ -60,7 +60,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]);
|
std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews", argv[1]);
|
||||||
if(res.size() != 1) {
|
if(res.size() != 1) {
|
||||||
if(res.size() == 0)
|
if(res.size() == 0)
|
||||||
std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl;
|
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);
|
unterOption_clean(&settings, argc, argv);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
} else if (strncmp(argv[1], "news", strlen(argv[1])) == 0) {
|
||||||
|
argv[1][0] = '\0';
|
||||||
|
return unterOption_news(&settings, argc, argv);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
||||||
return 3;
|
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) {
|
switch(c) {
|
||||||
case 'p':
|
case 'p':
|
||||||
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
|
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) {
|
switch(c) {
|
||||||
case 'p':
|
case 'p':
|
||||||
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
|
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
|
||||||
@ -1058,3 +1062,72 @@ bool createDirIsOk(std::string path)
|
|||||||
} else
|
} else
|
||||||
return dirExists(path);
|
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;
|
||||||
|
}
|
||||||
|
@ -27,7 +27,8 @@ enum Modus {
|
|||||||
DEFAULT_MODUS = 0,
|
DEFAULT_MODUS = 0,
|
||||||
DIRECT_LINK_MODUS = 1,
|
DIRECT_LINK_MODUS = 1,
|
||||||
SEARCH_MODUS = 2,
|
SEARCH_MODUS = 2,
|
||||||
INFO_MODUS = 3
|
INFO_MODUS = 3,
|
||||||
|
NEWS_MODUS = 4
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ struct Settings {
|
|||||||
proxy_ip = "127.0.0.1",
|
proxy_ip = "127.0.0.1",
|
||||||
languages = "GerDub,GerSub,Eng",
|
languages = "GerDub,GerSub,Eng",
|
||||||
genaueHoster = "",
|
genaueHoster = "",
|
||||||
version = "2.7.2",
|
version = "2.8.0",
|
||||||
defaultFileVersion="1.3",
|
defaultFileVersion="1.3",
|
||||||
outputFilePath = "",
|
outputFilePath = "",
|
||||||
default_checkPath = "",
|
default_checkPath = "",
|
||||||
@ -98,6 +99,9 @@ void unterOption_info_help(std::string programName);
|
|||||||
|
|
||||||
void unterOption_clean(Settings * settings, int argc, char **argv);
|
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);
|
int setS5ProxytoSettings(Settings &settings, std::string optarg);
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ int ProgramManager::start(Settings *settings)
|
|||||||
return 174;
|
return 174;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (settings->modus) {
|
switch (settings->modus) {
|
||||||
case Modus::DEFAULT_MODUS:
|
case Modus::DEFAULT_MODUS:
|
||||||
return defaultModus(settings);
|
return defaultModus(settings);
|
||||||
@ -36,6 +37,8 @@ int ProgramManager::start(Settings *settings)
|
|||||||
return searchModus(settings);
|
return searchModus(settings);
|
||||||
case Modus::INFO_MODUS:
|
case Modus::INFO_MODUS:
|
||||||
return infoModus(settings);
|
return infoModus(settings);
|
||||||
|
case Modus::NEWS_MODUS:
|
||||||
|
return newsModus(settings);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -630,6 +633,70 @@ int ProgramManager::infoModus(Settings *settings)
|
|||||||
return 0;
|
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("<div class=\"row\">")) == std::string::npos ) {
|
||||||
|
std::cout << " => Error: Konnte Position von '<div class=\"row\">'' nicht finden" <<std::endl;
|
||||||
|
return 2;
|
||||||
|
} else
|
||||||
|
html.erase(0, pos + 17);
|
||||||
|
if( (pos = html.find("<div class=\"cf\"></div>")) == std::string::npos ) {
|
||||||
|
std::cout << " => Error: Konnte Position von '<div class=\"cf\"></div>' nicht finden" <<std::endl;
|
||||||
|
return 2;
|
||||||
|
} else
|
||||||
|
html.erase(pos + 12);
|
||||||
|
|
||||||
|
html = pageManager.replace(html, "\n", "");
|
||||||
|
html = pageManager.replace(html, "class=\"row\"", "\n");
|
||||||
|
|
||||||
|
std::stringstream strstream(html + "\n");
|
||||||
|
html.clear();
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(strstream, line).good()) {
|
||||||
|
|
||||||
|
size_t pos = line.find("<strong>");
|
||||||
|
size_t pos2 = line.find("</strong>");
|
||||||
|
if(pos == std::string::npos) {
|
||||||
|
std::cout << " => Error: Konnte Position von '<strong>' nicht finden" <<std::endl;
|
||||||
|
return 3;
|
||||||
|
} else if(pos2 == std::string::npos) {
|
||||||
|
std::cout << " => Error: Konnte Position von '</strong>' nicht finden" <<std::endl;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
std::string name = line.substr(pos + 8, pos2 - pos - 8);
|
||||||
|
|
||||||
|
if( (pos = line.find("blue2\">")) == std::string::npos) {
|
||||||
|
std::cout << " => Error: Konnte Position von 'blue2\">' nicht finden" <<std::endl;
|
||||||
|
return 5;
|
||||||
|
} else if( (pos2 = line.find("</span>", pos)) == std::string::npos) {
|
||||||
|
std::cout << " => Error: Konnte Position von '' nicht finden" <<std::endl;
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
std::string id = pageManager.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;
|
||||||
|
return 5;
|
||||||
|
} else if( (pos2 = line.find("</span>", pos)) == std::string::npos) {
|
||||||
|
std::cout << " => Error: Konnte Position von '</span>' nicht finden" <<std::endl;
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
std::string date = line.substr(pos + 7, pos2 - pos - 7);
|
||||||
|
|
||||||
|
std::cout << " > " << ((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)
|
int ProgramManager::searchModus_update(Settings *settings)
|
||||||
{
|
{
|
||||||
Reply reply = pageManager.getServerRequest("https://s.to/serien");
|
Reply reply = pageManager.getServerRequest("https://s.to/serien");
|
||||||
|
@ -46,6 +46,7 @@ private:
|
|||||||
int directLinkModus(Settings * settings);
|
int directLinkModus(Settings * settings);
|
||||||
int searchModus(Settings * settings, std::string *saveTo = nullptr);
|
int searchModus(Settings * settings, std::string *saveTo = nullptr);
|
||||||
int infoModus(Settings * settings);
|
int infoModus(Settings * settings);
|
||||||
|
int newsModus(Settings *settings);
|
||||||
|
|
||||||
PageManager pageManager;
|
PageManager pageManager;
|
||||||
std::vector<ThreadData*> threadList;
|
std::vector<ThreadData*> threadList;
|
||||||
|
Loading…
Reference in New Issue
Block a user