forked from markus/S_New4
version 2.0.0
This commit is contained in:
parent
7a1bec866b
commit
3891dd5a1d
BIN
g++/S_New4
BIN
g++/S_New4
Binary file not shown.
Binary file not shown.
@ -5,6 +5,10 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ProgramManager mainProgram;
|
||||
Settings settings = manageParameter(argc, argv);
|
||||
Settings settings;
|
||||
int res = manageParameter(settings, argc, argv);
|
||||
if(res != 0)
|
||||
return (res == -1) ? 0 : res;
|
||||
|
||||
return mainProgram.start(settings);
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ PageManager::~PageManager()
|
||||
remove(cookieFilePath.c_str());
|
||||
}
|
||||
|
||||
void PageManager::setProxy(std::string ip, std::string port)
|
||||
void PageManager::setProxy(std::string ip, int port)
|
||||
{
|
||||
this->sock5Proxy = "socks5://" + ip + ":" + port;
|
||||
this->sock5Proxy = "socks5://" + ip + ":" + std::to_string(port);
|
||||
}
|
||||
|
||||
void PageManager::setCookieFilePath(std::string path)
|
||||
@ -250,12 +250,12 @@ int PageManager::counterContains(std::string text, std::string substring_with_pr
|
||||
return i-1;
|
||||
}
|
||||
|
||||
std::string PageManager::grep(std::string text, std::string substring)
|
||||
std::string PageManager::grep(std::string text, std::string substring, bool IgnoreCaseSensetifity)
|
||||
{
|
||||
std::istringstream iStrStream(text + "\n");
|
||||
std::string line, returnValue;
|
||||
while( std::getline(iStrStream, line).good() ) //auto start_of_line_position = begin( line ); //auto end_of_line_position = end( line );
|
||||
if(line.find(substring) != std::string::npos)
|
||||
if(line.find(substring) != std::string::npos || ( IgnoreCaseSensetifity && upper_string(line).find(upper_string(substring)) != std::string::npos) )
|
||||
returnValue += line + "\n";
|
||||
if(returnValue.length() >= 1)
|
||||
return returnValue.erase(returnValue.length()-1,1);
|
||||
@ -264,6 +264,13 @@ std::string PageManager::grep(std::string text, std::string substring)
|
||||
|
||||
}
|
||||
|
||||
std::string PageManager::upper_string(const std::string &str)
|
||||
{
|
||||
std::string upper;
|
||||
transform(str.begin(), str.end(), std::back_inserter(upper), toupper);
|
||||
return upper;
|
||||
}
|
||||
|
||||
int PageManager::writeToFile(std::string path, std::string text)
|
||||
{
|
||||
if(path == "")
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "accountManager.h"
|
||||
|
||||
struct Reply {
|
||||
@ -25,7 +27,7 @@ public:
|
||||
PageManager(std::string sock5Proxy = "socks5://127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies");
|
||||
~PageManager();
|
||||
|
||||
void setProxy(std::string ip, std::string port);
|
||||
void setProxy(std::string ip, int port);
|
||||
void setCookieFilePath(std::string path);
|
||||
void setDebugMode(bool status);
|
||||
|
||||
@ -38,12 +40,15 @@ public:
|
||||
|
||||
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);
|
||||
std::string grep(std::string text, std::string substring, bool IgnoreCaseSensetifity = false);
|
||||
std::string upper_string(const std::string& str);
|
||||
|
||||
int writeToFile(std::string path, std::string text);
|
||||
|
||||
const std::string UrlPraefix = "https://s.to/serie/stream/";
|
||||
std::string sock5Proxy;
|
||||
private:
|
||||
std::string sock5Proxy, cookieFilePath;
|
||||
std::string cookieFilePath;
|
||||
bool debugMode = false;
|
||||
};
|
||||
|
||||
|
Binary file not shown.
@ -1,75 +1,90 @@
|
||||
#include "parameterManager.h"
|
||||
|
||||
Settings manageParameter(int argc, char **argv)
|
||||
void setPaths(Settings &settings, std::string executablePathTo)
|
||||
{
|
||||
Settings settings;
|
||||
//Path settings
|
||||
executablePathTo.erase(executablePathTo.find_last_of("/\\") + 1 , executablePathTo.length() - ( executablePathTo.find_last_of("/\\") + 1) );
|
||||
|
||||
std::string argv0 = argv[0];
|
||||
if(!dirExists(executablePathTo + "src/"))
|
||||
system(std::string("mkdir \"" + executablePathTo + "src/\"").c_str());
|
||||
if(dirExists(executablePathTo + "src/"))
|
||||
executablePathTo+="src/";
|
||||
|
||||
argv0.erase(argv0.find_last_of("/\\") + 1 , argv0.length() - ( argv0.find_last_of("/\\") + 1) );
|
||||
settings.cookieFilePath = executablePathTo + "S_New4_cookies";
|
||||
settings.accountFilePath = executablePathTo + "Accounts";
|
||||
settings.accountNumberPath = executablePathTo + "Account_Number";
|
||||
settings.serienListPath = executablePathTo + "SerienListe";
|
||||
|
||||
settings.cookieFilePath = argv0 + "S_New4_cookies";
|
||||
settings.accountFilePath = argv0 + "Accounts";
|
||||
settings.accountNumberPath = argv0 + "Account_Number";
|
||||
}
|
||||
|
||||
|
||||
int manageParameter(Settings &settings, int argc, char **argv)
|
||||
{
|
||||
//Path settings
|
||||
setPaths(settings, argv[0]);
|
||||
|
||||
if(argc < 2) {
|
||||
std::cout << " => Keine Unteroption angegeben." << std::endl;
|
||||
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl;
|
||||
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl;
|
||||
settings.modus = Modus::EXIT;
|
||||
return settings;
|
||||
return 1;
|
||||
}
|
||||
if(compare("--help\ndefault\nurl\n--version", argv[1]) != 1) {
|
||||
std::cout << " => Unbekannte Unteroption: '" << argv[1] << "': Mehrere oder keine Option gefunden." << std::endl;
|
||||
|
||||
int res = compare("--help\ndefault\nurl\n--version\nsearch", argv[1]);
|
||||
if(res != 1) {
|
||||
std::cout << " => Unbekannte Unteroption: '" << argv[1] << "': Mehrere oder keine Option gefunden: " << res << " Möglichkeiten." << std::endl;
|
||||
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl;
|
||||
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl;
|
||||
settings.modus = Modus::EXIT;
|
||||
return settings;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
|
||||
argv[1][0] = '\0';
|
||||
unterOption_help(&settings, argv[0]);
|
||||
return settings;
|
||||
return unterOption_help(&settings, argv[0]);
|
||||
|
||||
} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
|
||||
argv[1][0] = '\0';
|
||||
unterOption_default(&settings, argc, argv);
|
||||
return settings;
|
||||
return unterOption_default(&settings, argc, argv);
|
||||
|
||||
} else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) {
|
||||
argv[1][0] = '\0';
|
||||
unterOption_url(&settings, argc, argv);
|
||||
return settings;
|
||||
return unterOption_url(&settings, argc, argv);
|
||||
|
||||
} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
|
||||
std::cout << "Version: " << settings.version << std::endl;
|
||||
settings.modus = Modus::EXIT;
|
||||
return settings;
|
||||
return -1;
|
||||
|
||||
} else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) {
|
||||
argv[1][0] = '\0';
|
||||
return unterOption_search(&settings, argc, argv);
|
||||
|
||||
} else if (false) {
|
||||
|
||||
//return 0;
|
||||
|
||||
} else {
|
||||
std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
||||
settings.modus = Modus::EXIT;
|
||||
return settings;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
void unterOption_help(Settings *settings, char * argv0)
|
||||
int unterOption_help(Settings *, char * argv0)
|
||||
{
|
||||
std::cout << "Aufruf: " << getProgramName(argv0) << " [Unteroption] [PARAMETER]" << std::endl << std::endl;
|
||||
std::cout << "Unteroptionen:" << std::endl
|
||||
<< "\t„--help“\tListe aller Unteroptionen" << std::endl
|
||||
<< "\t„--version“\tVersion des Programmes" << std::endl
|
||||
<< "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl
|
||||
<< "\t„default“\tModus um Links von Serien zu bekommen." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
<< "\t„default“\tModus um Links von Serien zu bekommen." << std::endl
|
||||
<< "\t„search“\tModus um Serien zu suchen." << std::endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
int unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
{
|
||||
settings->modus = Modus::DEFAULT_MODUS;
|
||||
if(settings->modus)
|
||||
std::cout << "Modus: DEFAULT_MODUS" << std::endl;
|
||||
|
||||
int c = 0;
|
||||
const option long_opts[] = {
|
||||
@ -99,42 +114,40 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
case 'n':
|
||||
if(optarg)
|
||||
settings->name = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Name: " << settings->name << std::endl;
|
||||
break;
|
||||
case 'i':
|
||||
if(optarg)
|
||||
settings->proxy_ip = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl;
|
||||
break;
|
||||
case 'p':
|
||||
if(optarg)
|
||||
settings->proxy_port = std::to_string( atoi( optarg ) );
|
||||
if(settings->proxy_port != optarg) {
|
||||
settings->proxy_port = atoi( optarg ) ;
|
||||
if(std::to_string(settings->proxy_port) != optarg) {
|
||||
std::cout << "Invalid Port: " << optarg << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
}
|
||||
if(settings->modus)
|
||||
return 10;
|
||||
} else if(settings->debugMode)
|
||||
std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
|
||||
break;
|
||||
case 'g':
|
||||
if(optarg)
|
||||
settings->genaueHoster =+ optarg + std::string(",");
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl;
|
||||
break;
|
||||
case 'l':
|
||||
if(optarg)
|
||||
settings->languages =+ optarg + std::string(",");
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl;
|
||||
break;
|
||||
case 'o':
|
||||
if(optarg)
|
||||
settings->outputFilePath = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
|
||||
break;
|
||||
|
||||
@ -145,16 +158,13 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
settings->startEpisode = atoi(optarg);
|
||||
if (std::to_string(settings->startEpisode) != optarg) {
|
||||
std::cout << "Error: -e [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 11;
|
||||
} else if (settings->startEpisode == 0) {
|
||||
std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 12;
|
||||
} else if (settings->startEpisode < 0) {
|
||||
std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 13;
|
||||
}
|
||||
if(settings->debugMode)
|
||||
std::cout << "StartEpisode: " << settings->startEpisode << std::endl;
|
||||
@ -165,8 +175,7 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
settings->stopEpisode = atoi(optarg);
|
||||
if (std::to_string(settings->stopEpisode) != optarg) {
|
||||
std::cout << "Error: -E [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 14;
|
||||
} else if (settings->debugMode)
|
||||
std::cout << "StopEpisode: " << settings->stopEpisode << std::endl;
|
||||
break;
|
||||
@ -176,18 +185,14 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
settings->startSeason = atoi(optarg);
|
||||
if (std::to_string(settings->startSeason) != optarg) {
|
||||
std::cout << "Error: -s [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 15;
|
||||
} else if (settings->startSeason == 0) {
|
||||
std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 16;
|
||||
} else if (settings->startSeason < 0) {
|
||||
std::cout << "Error: -s [Staffel]: StartStaffel " << settings->startSeason << " ist kleiner 0." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
}
|
||||
if(settings->debugMode)
|
||||
return 17;
|
||||
} else if(settings->debugMode)
|
||||
std::cout << "StartStaffel: " << settings->startSeason << std::endl;
|
||||
break;
|
||||
case 'S':
|
||||
@ -196,36 +201,36 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
|
||||
settings->stopSeason = atoi(optarg);
|
||||
if (std::to_string(settings->stopSeason) != optarg) {
|
||||
std::cout << "Error: -S [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 18;
|
||||
} else if(settings->debugMode)
|
||||
std::cout << "StopSeason: " << settings->stopSeason << std::endl;
|
||||
break;
|
||||
|
||||
|
||||
case 'c':
|
||||
settings->colorless = true;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Farblos: true" << std::endl;
|
||||
break;
|
||||
case 'd':
|
||||
settings->debugMode = true;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Debug Modus: true" << std::endl;
|
||||
break;
|
||||
case 'h':
|
||||
unterOption_default_help(settings, argv[0]);
|
||||
return;
|
||||
return -1;
|
||||
default:
|
||||
std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl;
|
||||
std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(settings->debugMode)
|
||||
std::cout << "Modus: DEFAULT_MODUS" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unterOption_default_help(Settings *settings, char * argv0)
|
||||
void unterOption_default_help(Settings *, char * argv0)
|
||||
{
|
||||
std::cout << "Usage: " << getProgramName(argv0) << " default [ Parameter & {-n [Name]} ]..." << std::endl
|
||||
<< "Parameter:" << std::endl << std::endl
|
||||
@ -271,15 +276,13 @@ void unterOption_default_help(Settings *settings, char * argv0)
|
||||
<< std::endl
|
||||
<< " > Help-Optionen" << std::endl
|
||||
<< "\t-h, --help" << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void unterOption_url(Settings *settings, int argc, char **argv)
|
||||
int unterOption_url(Settings *settings, int argc, char **argv)
|
||||
{
|
||||
settings->modus = Modus::DIRECT_LINK_MODUS;
|
||||
if(settings->modus)
|
||||
std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl;
|
||||
|
||||
int c = 0;
|
||||
const option long_opts[] = {
|
||||
@ -301,68 +304,73 @@ void unterOption_url(Settings *settings, int argc, char **argv)
|
||||
case 'u':
|
||||
if(optarg)
|
||||
settings->name = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Urls: " << settings->name << std::endl;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
if(optarg)
|
||||
settings->proxy_ip = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl;
|
||||
break;
|
||||
case 'p':
|
||||
if(optarg)
|
||||
settings->proxy_port = std::to_string( atoi( optarg ) );
|
||||
if(settings->proxy_port != optarg) {
|
||||
settings->proxy_port = atoi( optarg );
|
||||
if(std::to_string(settings->proxy_port) != optarg) {
|
||||
std::cout << "Invalid Port: " << optarg << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 20;
|
||||
}
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
|
||||
break;
|
||||
case 'o':
|
||||
if(optarg)
|
||||
settings->outputFilePath = optarg;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
|
||||
break;
|
||||
case 'c':
|
||||
settings->colorless = true;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Farblos: true" << std::endl;
|
||||
break;
|
||||
case 'd':
|
||||
settings->debugMode = true;
|
||||
if(settings->modus)
|
||||
if(settings->debugMode)
|
||||
std::cout << "Debug Modus: true" << std::endl;
|
||||
break;
|
||||
case 'h':
|
||||
unterOption_url_help(settings, argv[0]);
|
||||
return;
|
||||
return -1;
|
||||
default:
|
||||
std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl;
|
||||
std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
return;
|
||||
return 21;
|
||||
}
|
||||
}
|
||||
if(settings->debugMode)
|
||||
std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unterOption_url_help(Settings *settings, char * argv0)
|
||||
void unterOption_url_help(Settings *, char * argv0)
|
||||
{
|
||||
std::cout << "Usage: " << getProgramName(argv0) << " url [ Parameter & {-u [Url]} ]..." << std::endl
|
||||
<< "Parameter" << std::endl
|
||||
<< "\t-u [Url1,Url2,...], \t--url [Url1,Url2,...]" << std::endl
|
||||
<< "\t-i [ProxyIPAddresse], \t--ip-addresse [ProxyIPAddresse] Default: 127.0.0.1" << std::endl
|
||||
<< "\t-p [ProxyPort], \t--port [ProxyPort]\t\t Default: 9050" << std::endl
|
||||
<< "\t-o [Pfad], \t\t--output-file [Pfad]" << std::endl
|
||||
<< "\t-c, \t\t\t--colorless\t\t\t Default: false" << std::endl
|
||||
<< "\t-d, \t\t\t--debug-mode\t\t\t Default: false" << std::endl
|
||||
<< "\t -> Debug Nachrichten an." << std::endl
|
||||
<< "\t-h, \t\t\t--help" << std::endl;
|
||||
settings->modus = Modus::EXIT;
|
||||
<< "Parameter:" << std::endl
|
||||
<< "\t-u [Url1,Url2,...], --url [Url1,Url2,...]" << std::endl
|
||||
<< "\t -> Die zu umwandelnden redirect-Links." << std::endl
|
||||
<< "\t-i [ProxyIPAddresse], --ip-addresse [ProxyIPAddresse]" << std::endl
|
||||
<< "\t -> Default: 127.0.0.1." << std::endl
|
||||
<< "\t-p [ProxyPort], --port [ProxyPort]" << std::endl
|
||||
<< "\t -> Default: 9050." << std::endl
|
||||
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl
|
||||
<< "\t-c, --colorless" << std::endl
|
||||
<< "\t -> Default: false ." << std::endl
|
||||
<< "\t-d, --debug-mode" << std::endl
|
||||
<< "\t -> Debug Nachrichten an. Default: false" << std::endl
|
||||
<< "\t-h, --help" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -370,6 +378,7 @@ std::string getProgramName(char *argv0)
|
||||
{
|
||||
return std::string(argv0).erase(0, ( (std::string(argv0).find_last_of("/\\") != std::string::npos ) ? std::string(argv0).find_last_of("/\\") +1 : 0 ) );
|
||||
}
|
||||
|
||||
int compare(std::string All_Options_with_komma_between, std::string input)
|
||||
{
|
||||
std::istringstream iStrStream( All_Options_with_komma_between + "\n");
|
||||
@ -382,3 +391,118 @@ int compare(std::string All_Options_with_komma_between, std::string input)
|
||||
}
|
||||
return allFounds;
|
||||
}
|
||||
|
||||
int unterOption_search(Settings *settings, int argc, char **argv)
|
||||
{
|
||||
settings->modus = Modus::Search_MODUS;
|
||||
|
||||
int c = 0;
|
||||
const option long_opts[] = {
|
||||
{"name", required_argument, nullptr, 'n'},
|
||||
{"socks5-proxy", required_argument, nullptr, 'p'},
|
||||
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{"colorless", no_argument, nullptr, 'c'},
|
||||
{"debug-mode", no_argument, nullptr, 'd'},
|
||||
{"debug-mode", no_argument, nullptr, 'd'},
|
||||
{"exactly-writing", no_argument, nullptr, 'e'},
|
||||
{"update", no_argument, nullptr, 'u'},
|
||||
|
||||
{nullptr, no_argument, nullptr, 0}
|
||||
|
||||
};
|
||||
std::string optarg2;
|
||||
while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
|
||||
switch(c) {
|
||||
case 'n':
|
||||
if(optarg)
|
||||
settings->name = optarg;
|
||||
if(settings->debugMode)
|
||||
std::cout << "Name: " << settings->name << std::endl;
|
||||
break;
|
||||
case 'p': {
|
||||
optarg2 = optarg;
|
||||
if(!optarg || optarg2 == "")
|
||||
break;
|
||||
else if(optarg2.find(":") == std::string::npos) {
|
||||
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
|
||||
return 31;
|
||||
}
|
||||
std::string ip = optarg2.substr(0, optarg2.find(":"));
|
||||
std::string portStr = optarg2.substr(optarg2.find(":") + 1, optarg2.length() - optarg2.find(":"));
|
||||
int port = atoi(portStr.c_str());
|
||||
if(std::to_string(port) != portStr || port <= 0) {
|
||||
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
|
||||
return 32;
|
||||
} else if (ip == "") {
|
||||
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
|
||||
return 34;
|
||||
} else if(settings->debugMode) {
|
||||
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
|
||||
}
|
||||
settings->proxy_ip = ip;
|
||||
settings->proxy_port = port;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
unterOption_search_help(settings, argv[0]);
|
||||
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;
|
||||
case 'e':
|
||||
settings->search_IgnoreUpperLower = false;
|
||||
if(settings->debugMode)
|
||||
std::cout << "Achte auf Groß und Kleinschreibung: true" << std::endl;
|
||||
break;
|
||||
case 'u':
|
||||
settings->search_wantUpdate = true;
|
||||
if(settings->debugMode)
|
||||
std::cout << "Update die Liste: true" << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << "Aufruf: " << getProgramName(argv[0]) << " search [PARAMETER]" << std::endl;
|
||||
std::cout << "„" << getProgramName(argv[0]) << " search --help“ liefert weitere Informationen." << std::endl;
|
||||
return 21;
|
||||
}
|
||||
}
|
||||
if(settings->debugMode)
|
||||
std::cout << "Modus: Search_MODUS" << std::endl;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void unterOption_search_help(Settings *, char *argv0)
|
||||
{
|
||||
std::cout << "Usage: " << getProgramName(argv0) << " search [ Parameter & {-n [Name] / -u} ]..." << std::endl
|
||||
<< "Parameter:" << std::endl
|
||||
<< "\t-n [Name], --name [Name]" << std::endl
|
||||
<< "\t -> (Teil)Namen der gesuchten Serie." << std::endl
|
||||
<< "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl
|
||||
<< "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl
|
||||
<< "\t-c, --colorless" << std::endl
|
||||
<< "\t -> Gib keine Farbigen Infos aus. Default: false" << std::endl
|
||||
<< "\t-d, --debug-mode" << std::endl
|
||||
<< "\t -> Debug Nachrichten an. Default: false" << std::endl
|
||||
<< "\t-e, --exactly-writing" << std::endl
|
||||
<< "\t -> Achte auf Groß und kleinschreibung bei der Suche. Default: false" << std::endl
|
||||
<< "\t-u, --update" << std::endl
|
||||
<< "\t -> Update die Serienliste. Default: false" << std::endl
|
||||
<< "\t-h, --help" << std::endl
|
||||
<< "\t -> Gibt dieses Helpmenü aus." << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool dirExists(std::string dir)
|
||||
{
|
||||
struct stat sb;
|
||||
return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false;
|
||||
}
|
||||
|
@ -5,11 +5,13 @@
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
enum Modus {
|
||||
EXIT = -1,
|
||||
DEFAULT_MODUS = 0,
|
||||
DIRECT_LINK_MODUS = 1
|
||||
DIRECT_LINK_MODUS = 1,
|
||||
Search_MODUS = 2
|
||||
};
|
||||
|
||||
|
||||
@ -21,35 +23,43 @@ struct Settings {
|
||||
accountFilePath = "/tmp/a",
|
||||
accountNumberPath= "/tmp/b",
|
||||
cookieFilePath = "/tmp/S_New4_cookies",
|
||||
serienListPath = "/tmp/SerienListe",
|
||||
proxy_ip = "127.0.0.1",
|
||||
proxy_port = "9050",
|
||||
languages = "GerDub,GerSub,Eng",
|
||||
genaueHoster,
|
||||
genaueHoster = "",
|
||||
version = "1.0.1",
|
||||
outputFilePath;
|
||||
Modus modus = Modus::DEFAULT_MODUS;
|
||||
bool colorless = false,
|
||||
debugMode = false;
|
||||
debugMode = false,
|
||||
search_IgnoreUpperLower = true,
|
||||
search_wantUpdate = false;
|
||||
int startEpisode = 1,
|
||||
stopEpisode = 0,
|
||||
startSeason = 1,
|
||||
stopSeason = 0;
|
||||
stopSeason = 0,
|
||||
proxy_port = 9050;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Settings manageParameter(int argc, char ** argv);
|
||||
int manageParameter(Settings &settings, int argc, char ** argv);
|
||||
std::string getProgramName(char * argv0);
|
||||
int compare(std::string All_Options_with_komma_between, std::string input);
|
||||
void setPaths(Settings &settings, std::string executablePathTo);
|
||||
bool dirExists(std::string dir);
|
||||
|
||||
int unterOption_help(Settings * settings, char *argv0);
|
||||
|
||||
void unterOption_help(Settings * settings, char *argv0);
|
||||
|
||||
void unterOption_default(Settings * settings, int argc, char **argv);
|
||||
int unterOption_default(Settings * settings, int argc, char **argv);
|
||||
void unterOption_default_help(Settings * settings, char * argv0);
|
||||
|
||||
void unterOption_url(Settings * settings, int argc, char **argv);
|
||||
int unterOption_url(Settings * settings, int argc, char **argv);
|
||||
void unterOption_url_help(Settings * settings, char *argv0);
|
||||
|
||||
int unterOption_search(Settings * settings, int argc, char **argv);
|
||||
void unterOption_search_help(Settings * settings, char *argv0);
|
||||
|
||||
|
||||
|
||||
#endif // PARAMETERMANAGER_H
|
||||
|
Binary file not shown.
@ -10,13 +10,19 @@ ProgramManager::~ProgramManager()
|
||||
|
||||
}
|
||||
|
||||
int ProgramManager::start(Settings setting)
|
||||
int ProgramManager::start(Settings settings)
|
||||
{
|
||||
switch (setting.modus) {
|
||||
pageManager.setProxy(settings.proxy_ip, settings.proxy_port);
|
||||
pageManager.setCookieFilePath(settings.cookieFilePath);
|
||||
pageManager.setDebugMode(settings.debugMode);
|
||||
|
||||
switch (settings.modus) {
|
||||
case Modus::DEFAULT_MODUS:
|
||||
return defaultModus(&setting);
|
||||
return defaultModus(&settings);
|
||||
case Modus::DIRECT_LINK_MODUS:
|
||||
return directLinkModus(&setting);
|
||||
return directLinkModus(&settings);
|
||||
case Modus::Search_MODUS:
|
||||
return searchModus(&settings);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -25,9 +31,6 @@ int ProgramManager::start(Settings setting)
|
||||
int ProgramManager::defaultModus(Settings *settings)
|
||||
{
|
||||
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
||||
pageManager.setProxy(settings->proxy_ip, settings->proxy_port);
|
||||
pageManager.setCookieFilePath(settings->cookieFilePath);
|
||||
pageManager.setDebugMode(settings->debugMode);
|
||||
|
||||
if(settings->name == "") {
|
||||
std::cout << "Kein Name angegeben: Missing Parameter -n [Name]." << std::endl;
|
||||
@ -35,8 +38,10 @@ int ProgramManager::defaultModus(Settings *settings)
|
||||
}
|
||||
|
||||
std::string nameInUrl =pageManager.checkName(settings->name);
|
||||
if(nameInUrl == "-1")
|
||||
if(nameInUrl == "-1") {
|
||||
searchModus(settings);
|
||||
return 25;
|
||||
}
|
||||
else if (pageManager.login(accountManager.getNextAccount()) != 0)
|
||||
return 29;
|
||||
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);
|
||||
@ -95,9 +100,6 @@ int ProgramManager::defaultModus(Settings *settings)
|
||||
int ProgramManager::directLinkModus(Settings *settings)
|
||||
{
|
||||
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
|
||||
pageManager.setCookieFilePath(settings->cookieFilePath);
|
||||
pageManager.setProxy(settings->proxy_ip, settings->proxy_port);
|
||||
pageManager.setDebugMode(settings->debugMode);
|
||||
|
||||
if(settings->name == "") {
|
||||
std::cout << "Kein(e) Link(s) angegeben: Missing Parameter -u [Url]." << std::endl;
|
||||
@ -122,11 +124,123 @@ int ProgramManager::directLinkModus(Settings *settings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProgramManager::convertLink(std::string redirectLink, AccountManager * accountManager, Settings * settings, int Staffel, int Folge, std::string allLinks)
|
||||
int ProgramManager::searchModus(Settings *settings)
|
||||
{
|
||||
|
||||
if(settings->search_wantUpdate) {
|
||||
int res = searchModus_update(settings) ;
|
||||
if( res == 0)
|
||||
std::cout << "Erfolgreich geupdatet: Die Serienliste ist nun auf dem neusten Stand." << std::endl;
|
||||
else
|
||||
std::cout << "Das updaten der Serienliste ist fehlgeschlagen." << std::endl;
|
||||
return res;
|
||||
|
||||
} else if(settings->name == "") {
|
||||
std::cout << "Kein Name angegeben: Missing Parameter -n [Name]." << std::endl;
|
||||
return 27;
|
||||
}
|
||||
|
||||
std::ifstream ifs(settings->serienListPath);
|
||||
if(!ifs.is_open()) {
|
||||
std::cout << "Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl;
|
||||
if(searchModus_update(settings) != 0)
|
||||
return 354;
|
||||
else {
|
||||
ifs.open(settings->serienListPath);
|
||||
if(!ifs.is_open()) {
|
||||
perror("Couldn't open SerienList file after update again.");
|
||||
return 434;
|
||||
}
|
||||
std::cout << "Erfolgreich gedownloadet." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//Save file in string:
|
||||
std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
|
||||
std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower);
|
||||
serienListe.clear();
|
||||
|
||||
if(!settings->colorless) {
|
||||
for (size_t pos = pageManager.upper_string( finds ).find( pageManager.upper_string( settings->name ), 0);
|
||||
pos != std::string::npos;
|
||||
pos = pageManager.upper_string( finds ).find( pageManager.upper_string( settings->name ), pos + settings->name.length() + strlen("\033[37m\033[0m")))
|
||||
finds.insert(pos, ( (finds.find(settings->name, pos) == pos) ? "\033[32m" : "\033[36m" ) ).insert(pos + settings->name.length() + strlen("\033[37m"), "\033[0m");
|
||||
}
|
||||
|
||||
|
||||
std::stringstream strstream(finds);
|
||||
std::string line;
|
||||
std::cout << "Für '" << settings->name << "' wurde(n) folgende Serie(n) gefunden: " << std::endl;
|
||||
while (getline(strstream, line)) {
|
||||
std::cout << " > " << line.substr(line.find("|", line.find("/")) + 1, line.length() - line.find("|", line.find("/")) -1 )
|
||||
<< "\t[" << line.substr(line.find("/") + 1, line.find("|", line.find("/")) - line.find("/") - 1) << "]"
|
||||
<< ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProgramManager::searchModus_update(Settings *settings)
|
||||
{
|
||||
Reply reply = pageManager.getServerRequest("https://s.to/serien");
|
||||
if(reply.html == "-1")
|
||||
return 21;
|
||||
|
||||
std::string serienListe = pageManager.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 ||
|
||||
reply.html.find("/serie/stream/") == std::string::npos ||
|
||||
reply.html.find("</a>") == std::string::npos)
|
||||
return 51;
|
||||
|
||||
//...\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=\"", "");
|
||||
//...\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=\"", "|");
|
||||
//...\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/", "|/");
|
||||
|
||||
//Performanze:
|
||||
serienListe = pageManager.grep(serienListe, settings->name, true);
|
||||
|
||||
std::stringstream strstream(serienListe);
|
||||
std::string line;
|
||||
serienListe.clear();
|
||||
|
||||
while (getline(strstream, line)) {
|
||||
if(line.find(" title=\"") == std::string::npos)
|
||||
continue;
|
||||
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, "\">", "|");
|
||||
//...\n|/serie/stream/2012-das-jahr-null|2012 - Das Jahr Null</a>\n...
|
||||
line = pageManager.replace(line, "</a>", "");
|
||||
//...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n...
|
||||
|
||||
serienListe += line + "\n";
|
||||
} serienListe.pop_back();
|
||||
|
||||
std::ofstream ofs(settings->serienListPath, std::ios::trunc);
|
||||
if(!ofs.is_open()) {
|
||||
perror("Konnte SerienListe-Datei nicht öffnen");
|
||||
return 111;
|
||||
}
|
||||
ofs << serienListe << std::endl;
|
||||
ofs.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProgramManager::convertLink(std::string redirectLink, AccountManager * accountManager,
|
||||
Settings * settings, int Staffel, int Folge, std::string allLinks)
|
||||
{
|
||||
std::string folgenID = std::string((Staffel == -1 || Folge == -1 ) ? "" : "S" + std::string( (Staffel < 10) ? "0" : "" ) + std::to_string(Staffel)
|
||||
+ "E" + std::string( (Folge < 10) ? "0" : "" ) + std::to_string( Folge ) + ": ");
|
||||
std::string green = ((settings->colorless) ? "" : "\033[32m"), red = ((settings->colorless) ? "" : "\033[31m"), orange =((settings->colorless) ? "" : "\033[33m"), blue = ((settings->colorless) ? "" : "\033[34m");
|
||||
std::string green = ((settings->colorless) ? "" : "\033[32m"),
|
||||
red = ((settings->colorless) ? "" : "\033[31m"),
|
||||
orange =((settings->colorless) ? "" : "\033[33m"),
|
||||
blue = ((settings->colorless) ? "" : "\033[34m");
|
||||
|
||||
if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) {
|
||||
if(allLinks == "") {
|
||||
|
@ -16,6 +16,9 @@ public:
|
||||
private:
|
||||
int defaultModus(Settings * settings);
|
||||
int directLinkModus(Settings * settings);
|
||||
int searchModus(Settings * settings);
|
||||
int searchModus_update(Settings * settings);
|
||||
|
||||
|
||||
PageManager pageManager;
|
||||
|
||||
|
Binary file not shown.
@ -27,7 +27,7 @@ struct Settings {
|
||||
proxy_ip = "127.0.0.1",
|
||||
languages = "GerDub,GerSub,Eng",
|
||||
genaueHoster = "",
|
||||
version = "1.0.1",
|
||||
version = "2.0.0",
|
||||
outputFilePath;
|
||||
Modus modus = Modus::DEFAULT_MODUS;
|
||||
bool colorless = false,
|
||||
|
Loading…
Reference in New Issue
Block a user