commits vergessen (: => add function search + subdir src bei datein + datei serienliste

This commit is contained in:
Markus 2019-08-03 18:23:12 +02:00
parent 844d3e37c6
commit 8d59195a7e
21 changed files with 1633 additions and 125 deletions

BIN
g++/S_New4 Executable file

Binary file not shown.

136
g++/accountManager.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "accountManager.h"

AccountManager::AccountManager(std::string pathToFile, std::string pathToAccountNumberFile)
: pathToAccountNumberFile(pathToAccountNumberFile)
{
std::ifstream ifs(pathToFile);
if(!ifs.is_open()) {
if(writeDefault(pathToFile) != 0)
exit(12);
ifs.open(pathToFile);
if(!ifs.is_open()) {
std::cout << "Konnte Account File nicht öffnen" << std::endl;
exit(13);
}
}


std::string line;
while (std::getline(ifs, line)) {
if(line.length() > 0 && line[0] == '#')
continue;
Account account;
size_t Delimeter = line.find("/");

if(Delimeter == std::string::npos) {
account.Email = line;
account.Password = line;
} else {
account.Email = std::string(line).erase(Delimeter, line.length() - Delimeter);
account.Password = line.erase(0, Delimeter + 1);
}
if(account.Email == "" || account.Password == "")
continue;
else
accounts.push_back(account);
}

ifs.close();

}

Account AccountManager::getNextAccount()
{
if(accounts.size() == 0) {
std::cout << "Keine Accounts vorhanden." << std::endl;
exit(36);
}
size_t accountNumber = getLastAccountNumber();
accountNumber++;

if( accountNumber >= accounts.size() )
accountNumber=0;
if(setLastAccountNumber(accountNumber) != 0)
exit(45);

return accounts.at(accountNumber);
}

int AccountManager::writeDefault(std::string path)
{
std::ofstream ofs(path);
if(!ofs.is_open()) {
perror((std::string("Konnte Account Datei nicht öffnen: ") + path).c_str());
return -1;
}
std::cout << "Erstelle Datei mit Accounts unter: " << path << "..." <<std::endl;
ofs << "# <- Am Anfang der Zeile deaktiviert diese." << std::endl;
ofs << "#Email/Passwort - Falls diese gleich sind, geht auch nur Email oder Passwort" << std::endl;
ofs << "EntzueckendPackenderSkorpion@oida.icu" << std::endl;
ofs << "ExzellentIdealerSchakal@muell.icu" << std::endl;
ofs << "BrillantVitalerSalamander@spam.care" << std::endl;
ofs << "BezauberndRiesigerSchakal@oida.icu" << std::endl;
ofs << "DynamischWarmerBaer@magspam.net" << std::endl;
ofs << "EmotionalLeidenschaftlicherBaer@oida.icu" << std::endl;
ofs << "BewundernswertWarmerSchwan@oida.icu" << std::endl;
ofs << "HuebschUnfassbarerAal@papierkorb.me" << std::endl;
ofs << "FroehlichWundervollerBiber@muellmail.com" << std::endl;
ofs << "BefreiendWilderDelfin@spam.care" << std::endl;
ofs << "FreundlichStilvollerTiger@oida.icu" << std::endl;
ofs << "EchtKoeniglicherStorch@existiert.net" << std::endl;
ofs << "ErhellendSeltenerSeeloewe@ultra.fyi" << std::endl;
ofs << "BefluegeltPrallerSchwan@spam.care" << std::endl;
ofs << "FreundlichZuverlaessigerSchwan@spam.care" << std::endl;
ofs << "HervorragendWundervollerReiher@oida.icu" << std::endl;
ofs << "AnspruchsvollStilvollerUhu@magspam.net" << std::endl;

ofs.close();
return 0;
}

size_t AccountManager::getLastAccountNumber()
{
std::ifstream fStream;
fStream.open(pathToAccountNumberFile);
if(!fStream.is_open()) {
std::ofstream ofs;
ofs.open(pathToAccountNumberFile);
ofs << "0" << std::endl;
ofs.close();
fStream.open(pathToAccountNumberFile);
if(!fStream.is_open()) {
perror("Konnte Account Number Datei nicht erstellen");
exit(34);
}
}

std::string content( (std::istreambuf_iterator<char>(fStream) ), (std::istreambuf_iterator<char>() ) );
return static_cast<size_t>( atoi(content.c_str()) );
}

int AccountManager::setLastAccountNumber(size_t number)
{
std::ofstream ofs;
ofs.open(pathToAccountNumberFile, std::ios::trunc);
if(!ofs.is_open()) {
std::cout << "Account Number Datei ist nicht geöffnet." << std::endl;
return 110;
}
//fStream.clear();
ofs << number << std::endl;
return 0;
}

bool AccountManager::isDirExist(const std::string& path)
{
struct stat info;
if (stat(path.c_str(), &info) != 0) {
return false;
}
return (info.st_mode & S_IFDIR) != 0;
}

bool AccountManager::createDir(std::string path, std::string atLinux)
{
return system(std::string("mkdir " + atLinux + "'" + path +"'").c_str()); // -p if is linux
}

32
g++/accountManager.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef ACCOUNTMANAGER_H
#define ACCOUNTMANAGER_H

#include <iostream>
#include <vector>
#include <sys/stat.h>
#include <fstream>

struct Account {
std::string Email, Password;
};


class AccountManager
{
public:
AccountManager(std::string pathToFile, std::string pathToAccountNumberFile);
Account getNextAccount();

int writeDefault(std::string path);
size_t getLastAccountNumber();
int setLastAccountNumber(size_t number);

bool isDirExist(const std::string& path);
bool createDir(std::string path, std::string atLinux = "-p ");

private:
std::vector<Account> accounts;
std::string pathToAccountNumberFile;
};

#endif // ACCOUNTMANAGER_H

BIN
g++/accountManager.h.gch Normal file

Binary file not shown.

10
g++/main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "parameterManager.h"
#include "programManager.h"


int main(int argc, char *argv[])
{
ProgramManager mainProgram;
Settings settings = manageParameter(argc, argv);
return mainProgram.start(settings);
}

344
g++/pageManager.cpp Normal file
View File

@ -0,0 +1,344 @@
#include "pageManager.h"

PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath)
: sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath)
{

}

PageManager::~PageManager()
{
remove(cookieFilePath.c_str());
}

void PageManager::setProxy(std::string ip, std::string port)
{
this->sock5Proxy = "socks5://" + ip + ":" + port;
}

void PageManager::setCookieFilePath(std::string path)
{
this->cookieFilePath = path;
}

void PageManager::setDebugMode(bool status)
{
this->debugMode = status;
}

size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
//Function für CURL
static_cast<std::string*>(userp)->append(static_cast<char*>(contents),size * nmemb);
return size * nmemb;
}

Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::string data, bool generateCookieFile)
{
CURL *curl;
CURLcode res;
std::string readBuffer;
char *url;
std::string returnUrl;

std::cout << "Lade: '" << Url << "'...";
std::cout.flush();

curl = curl_easy_init();
if(!curl) {
perror("\33[2K\rError: Curl easy init failed");
return Reply("-1");
}

//Settings
curl_easy_setopt(curl, CURLOPT_URL, Url.c_str()); //Url für Curl
curl_easy_setopt(curl, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); //follows redirection
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); // Funktion zum Speichern des outputs in einem string
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); //Legt die Variable readbuffer fest
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0");
if(useCookies)
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookieFilePath.c_str());
if(data != "")
curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data.c_str());
if(generateCookieFile)
curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookieFilePath.c_str());

int maxTimeout = 10;
for (int timeout = 1; timeout <= maxTimeout; ++timeout) {
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
std::cout << "\33[2K\r";
std::cout.flush();

if(res != CURLE_OK) {
if(timeout == maxTimeout) {
perror((std::string("Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str());
return Reply("-1");
} else {
std::cout << "\33[2K\r" << "Warning: Versuch " << timeout << " von " << maxTimeout << ": curl_easy_perform() failed: " << curl_easy_strerror(res);
std::cout.flush();
sleep(1);
}
} else {
break;
}

}

//Get Url
res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
if( res != CURLE_OK || !url ) {
perror((std::string("Error: curl_easy_getinfo failed: ") + curl_easy_strerror(res)).c_str());
return Reply("-1");
} else
returnUrl=url;


/* always cleanup */ /* Mach den Griff zu, schreib die Kekse! */
curl_easy_cleanup(curl);

return Reply(readBuffer, returnUrl);
}

int PageManager::login(Account account)
{
if(debugMode)
std::cout << "Melde mit neuem Account an: Email: " << account.Email << " Passowort: " << account.Password << std::endl;

std::string html = getServerRequest("https://s.to/login", false, std::string("email=" + account.Email + "&password=" + account.Password), true ).html;
if(html == "" )
return 0;
else if (html.find("Das Feld Email muss eine gültige E-Mail-Adresse enthalten.") != std::string::npos)
std::cout << "Error: Login failed: Das Feld Email muss eine gültige E-Mail-Adresse enthalten." << std::endl
<< " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl;
else if (html.find("Das Passwort ist nicht korrekt") != std::string::npos)
std::cout << "Error: Login failed: Das Passwort ist nicht korrekt." << std::endl
<< " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl;
else if (html.find("Ein Account mit dieser E-Mail Adresse wurde nicht gefunden.") != std::string::npos)
std::cout << "Error: Login failed: Ein Account mit dieser E-Mail Adresse wurde nicht gefunden." << std::endl
<< " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl;
else if(html == "-1")
return -1;
else
std::cout << "Error: Login failed: Keine Weiterleitung bei Login." << std::endl
<< " Email: '" << account.Email << "' Passwort: '" << account.Password << "'" << std::endl;
return -1;
}

std::string PageManager::getUrlAfterRedirect(std::string Url)
{
return getServerRequest(Url, true).url;
}

std::string PageManager::checkName(std::string Name)
{
std::string name = replace(Name, " ", "-");
std::cout << "Name: " << name << std::endl;

std::string html = getServerRequest("https://s.to/serie/stream/" + name).html;
if(html.find("Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert.") != std::string::npos) {
std::cout << "Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: " << Name << std::endl;
return "-1";
} else if (html.find("404 - Seite nicht gefunden") != std::string::npos) {
std::cout << "Ungültiger Name: " << Name << std::endl;
return "-1";
} else if (html == "-1") {
return "-1";
}
else {
return name;
}
}

std::string PageManager::getLinks(std::string HTML)
{
size_t pos = HTML.find("<ul class=\"row\">");
if(pos == std::string::npos) {
std::cout << "Konnte Position von \"" << "<ul class=\"row\">" << " nicht finden" <<std::endl;
return "";
}

HTML.erase(0,pos);

pos = HTML.find("<script async=");
if(pos == std::string::npos) {
std::cout << "Konnte Position von \"" << "<script async=" << "\" nicht finden" <<std::endl;
return "";
}

HTML.erase(pos,HTML.length() - pos);
HTML = replace(HTML, "\n", ""); //HTML.replace("\n","").replace("</span>", "\n");
HTML = replace(HTML, "</span>", "\n");
HTML = grep(HTML,"href=\"/redirect/");

std::istringstream iStrStream( HTML + "\n" );
std::string line, ReturnValue;
size_t pos2;

while (getline(iStrStream, line).good()) {
if(line == "")
break;
pos=line.find("data-lang-key=");
if(pos == std::string::npos) {
std::cout << "Error: Konnte Position von \"data-lang-key=\" nicht finden." << std::endl;
continue;
}
//entferne alles bis pos
line.erase(0,pos);

pos=line.find("data-link-id=");
if(pos == std::string::npos) {
std::cout << "Error: Konnte Position von \"data-link-id=\" nicht finden." << std::endl;
continue;
}
pos2=line.find("href=\"");
if(pos2 == std::string::npos) {
std::cout << "Error: Konnte Position von 'href=\"' nicht finden." << std::endl;
continue;
}
//Entferne alles von pos bis pos2
line.erase(pos,pos2-pos);

pos=line.find("target=");
if(pos == std::string::npos) {
std::cout << "Error: Konnte Position von \"target=\" nicht finden." << std::endl;
continue;
}
pos2=line.find("title=");
if(pos2 == std::string::npos) {
std::cout << "Error: Konnte Position von \"title=\" nicht finden." << std::endl;
continue;
}
//entferne alles von pos bis pos2
line.erase(pos,pos2-pos);

pos=line.find("><");
if(pos == std::string::npos) {
std::cout << "Error: Konnte Position von \"><\" nicht finden." << std::endl;
continue;
}
//entferne alles von pos bis zum ende
line.erase(pos,line.length()-pos);

line = replace(line, "title=\"Hoster ", "hoster=\"");

ReturnValue+=line+"\n";
}

if(ReturnValue.size() > 0)
return ReturnValue.erase( ReturnValue.size()-1 , 1);
else
return "";

}

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 + strlen(substr1.c_str())) )
str.replace(index, strlen(substr1.c_str()), substr2);
return str;
}

int PageManager::counterContains(std::string text, std::string substring_with_prozent_i_for_number, int starte_mit_dieser_Zahl)
{
int i = starte_mit_dieser_Zahl;
for (; text.find( replace(substring_with_prozent_i_for_number, "%i", std::to_string(i)) ) != std::string::npos; i++);
return i-1;
}

std::string PageManager::grep(std::string text, std::string substring)
{
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)
returnValue += line + "\n";
if(returnValue.length() >= 1)
return returnValue.erase(returnValue.length()-1,1);
else
return "";

}

int PageManager::writeToFile(std::string path, std::string text)
{
if(path == "")
return 0;
std::ofstream of;
of.open(path, std::ios::out | std::ios::app);
if(!of.is_open()) {
perror("Konnte output Datei nicht öffnen");
return -1;
}
of << text << std::endl;
of.close();
return 0;
}

std::string PageManager::chooseHosterLink(std::string HosterList, std::string Hoster_with_Highst_Priority_at_First, std::string languages_with_highst_priority_at_first)
{
std::istringstream SListLang ( replace( languages_with_highst_priority_at_first, ",", "\n") + "\n" );
std::istringstream SListHoster( replace( Hoster_with_Highst_Priority_at_First, ",", "\n") + "\n" );

int LangId = 0;
size_t pos = 0;
std::string LanguageSortedHoster, Line, langId, hoster;
//QTextStream stream();

//Für jede Sprache:
while (getline(SListLang, langId).good()) {

if ( langId == "GerDub" )
LangId=1;
else if ( langId == "Eng" )
LangId=2;
else if ( langId == "GerSub" )
LangId=3;
else {
std::cout << "Unbekannte Sprache: " << langId << std::endl;
continue;
}

//Liste aller Links mit der Sprache des durchgangs der schleife
LanguageSortedHoster = grep(HosterList, ( "data-lang-key=\"" + std::to_string(LangId) + "\"" ) );
//std::cout << "Alle Folgen mi der Sprache " << langId << ":\n'" << LanguageSortedHoster << "'" << std::endl;

//Wenn keine Links zu der Sprache gefunden worden sind
if(LanguageSortedHoster == "")
continue;

//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) {
//std::cout << "Hoster " << hoster << " gibt es bei der sprache" << langId << " nicht " << std::endl;
continue;
}
Line = grep(LanguageSortedHoster, ("hoster=\"" + hoster + "\"" ) );
pos = Line.find("href=\"");
if(pos == std::string::npos) {
std::cout << "Error: Konnte 'href=\"' nicht finden." << std::endl;
continue;
}
Line.erase(0, pos + static_cast<int>(strlen("href=\"")));

pos = Line.find("\"");
if(pos == std::string::npos) {
std::cout << "Error: Konnte '\"' nicht finden." << std::endl;
continue;
}

return Line.erase(pos, Line.length()-pos);
}

}
return "";
}




50
g++/pageManager.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef MANAGEPAGE_H
#define MANAGEPAGE_H

#include <iostream>
// if complied for windows; everything is in */projectfolder/curl/
#include <curl/curl.h>
#include <string.h>
#include <sstream>
#include <unistd.h>

#include "accountManager.h"

struct Reply {
Reply() {}
Reply(std::string value_both) : html(value_both), url(value_both) {}
Reply(std::string html, std::string url) : html(html), url(url) {}

std::string html, url;
};


class PageManager
{
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 setCookieFilePath(std::string path);
void setDebugMode(bool status);

Reply getServerRequest(std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false);
int login(Account account);
std::string getUrlAfterRedirect(std::string Url);
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);

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);
int writeToFile(std::string path, std::string text);

const std::string UrlPraefix = "https://s.to/serie/stream/";
private:
std::string sock5Proxy, cookieFilePath;
bool debugMode = false;
};

#endif // MANAGEPAGE_H

BIN
g++/pageManager.h.gch Normal file

Binary file not shown.

384
g++/parameterManager.cpp Normal file
View File

@ -0,0 +1,384 @@
#include "parameterManager.h"

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

std::string argv0 = argv[0];

argv0.erase(argv0.find_last_of("/\\") + 1 , argv0.length() - ( argv0.find_last_of("/\\") + 1) );

settings.cookieFilePath = argv0 + "S_New4_cookies";
settings.accountFilePath = argv0 + "Accounts";
settings.accountNumberPath = argv0 + "Account_Number";

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;
}
if(compare("--help\ndefault\nurl\n--version", argv[1]) != 1) {
std::cout << " => Unbekannte Unteroption: '" << argv[1] << "': Mehrere oder keine Option gefunden." << 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;
}

if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
unterOption_help(&settings, argv[0]);
return settings;

} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
unterOption_default(&settings, argc, argv);
return settings;

} else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
unterOption_url(&settings, argc, argv);
return settings;

} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
std::cout << "Version: " << settings.version << std::endl;
settings.modus = Modus::EXIT;
return settings;
} else {
std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
settings.modus = Modus::EXIT;
return settings;
}
}

void unterOption_help(Settings *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;
}


void 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[] = {
{"name", required_argument, nullptr, 'n'},
{"ip-addresse", required_argument, nullptr, 'i'},
{"port", required_argument, nullptr, 'p'},
{"genauer-hoster", required_argument, nullptr, 'g'},
{"languages", required_argument, nullptr, 'l'},
{"output-file", required_argument, nullptr, 'o'},

{"start-episode", required_argument, nullptr, 'e'},
{"stop-episode", required_argument, nullptr, 'E'},
{"start-season", required_argument, nullptr, 's'},
{"stop-season", required_argument, nullptr, 'S'},


{"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, "n:i:p:g:l:o:e:E:s:S:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'n':
if(optarg)
settings->name = optarg;
if(settings->modus)
std::cout << "Name: " << settings->name << std::endl;
break;
case 'i':
if(optarg)
settings->proxy_ip = optarg;
if(settings->modus)
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) {
std::cout << "Invalid Port: " << optarg << std::endl;
settings->modus = Modus::EXIT;
return;
}
if(settings->modus)
std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
break;
case 'g':
if(optarg)
settings->genaueHoster =+ optarg + std::string(",");
if(settings->modus)
std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl;
break;
case 'l':
if(optarg)
settings->languages =+ optarg + std::string(",");
if(settings->modus)
std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl;
break;
case 'o':
if(optarg)
settings->outputFilePath = optarg;
if(settings->modus)
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
break;


case 'e':
if(!optarg)
break;
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;
} else if (settings->startEpisode == 0) {
std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl;
settings->modus = Modus::EXIT;
return;
} else if (settings->startEpisode < 0) {
std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl;
settings->modus = Modus::EXIT;
return;
}
if(settings->debugMode)
std::cout << "StartEpisode: " << settings->startEpisode << std::endl;
break;
case 'E':
if(!optarg)
break;
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;
} else if (settings->debugMode)
std::cout << "StopEpisode: " << settings->stopEpisode << std::endl;
break;
case 's':
if(!optarg)
break;
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;
} else if (settings->startSeason == 0) {
std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl;
settings->modus = Modus::EXIT;
return;
} 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)
std::cout << "StartStaffel: " << settings->startSeason << std::endl;
break;
case 'S':
if(!optarg)
break;
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;
} else if(settings->debugMode)
std::cout << "StopSeason: " << settings->stopSeason << std::endl;
break;


case 'c':
settings->colorless = true;
if(settings->modus)
std::cout << "Farblos: true" << std::endl;
break;
case 'd':
settings->debugMode = true;
if(settings->modus)
std::cout << "Debug Modus: true" << std::endl;
break;
case 'h':
unterOption_default_help(settings, argv[0]);
return;
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;
}
}
}

void unterOption_default_help(Settings *settings, char * argv0)
{
std::cout << "Usage: " << getProgramName(argv0) << " default [ Parameter & {-n [Name]} ]..." << std::endl
<< "Parameter:" << std::endl << std::endl
<< " > Muss-Parameter:" << std::endl
<< "\t-n [Name], --name [Name]" << std::endl
<< "\t -> Namen der Serie, deren Links du willst." << std::endl
<< std::endl
<< " > Auswahloptionen:" << std::endl
<< "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl
<< "\t -> Die Namen der Hoster, deren Links du willst. Der wichtigste zuerst." << std::endl
<< "\t-l [GerDub/GerSub/Eng,...], --languages [GerDub/GerSub/Eng,...]" << std::endl
<< "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl
<< std::endl
<< " > Proxy-Optionen:" << std::endl
<< "\t-i [ProxyIPAddresse], --ip-addresse [ProxyIPAddresse]" << std::endl
<< "\t -> Ip Addresse eines Socks5-Proxys angeben. Default: 127.0.0.1" << std::endl
<< "\t-p [ProxyPort], --port [ProxyPort]" << std::endl
<< "\t -> Port eines Socks5-Proxy angeben. Default: 9050" << std::endl
<< std::endl
<< " > Outputoptionen:" << std::endl
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl
<< "\t -> Schreibe Links nach Redirect in diese Datei." << std::endl
<< "\t-c, --colorless" << std::endl
<< "\t -> Keine Farben beim Output verwenden. Default: false" << std::endl
<< "\t-d, --debug-mode" << std::endl
<< "\t -> Debug Nachrichten an. Default: false" << std::endl
<< std::endl
<< " > Durchlaufoptionen:" << std::endl
<< "\t-e [Folge], --start-episode [Folge]" << std::endl
<< "\t -> Das Programm startet mit dieser Folge." << std::endl
<< "\t Default: 1" << std::endl
<< "\t-E [Folge], --stop-episode [Folge]" << std::endl
<< "\t -> - Wenn -S nicht verwendet wird, stoppt das Programm sobald die Folge erreicht wurde." << std::endl
<< "\t - Wenn -S verwendet wird, stoppt es 1. wenn die Folge UND die Staffel erreicht wurden," << std::endl
<< "\t 2. wenn die die Staffel von -S fertig ist. Zum deaktivieren Folge <= 0 verwenden." << std::endl
<< "\t Default: 0" << std::endl
<< "\t-s [Staffel], --start-season [Staffel]" << std::endl
<< "\t -> Das Programm startet mit dieser Staffel." << std::endl
<< "\t Default: 1" << std::endl
<< "\t-S [Staffel], --stop-season [Staffel]" << std::endl
<< "\t -> Das Programm stopt mit dieser Staffel. Beachte Verwendung mit -E." << std::endl
<< "\t Zum deaktivieren Staffel <= 0 verwenden. Default: 0" << std::endl
<< std::endl
<< " > Help-Optionen" << std::endl
<< "\t-h, --help" << std::endl;
settings->modus = Modus::EXIT;
}


void 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[] = {
{"url", required_argument, nullptr, 'u'},
{"ip-addresse", required_argument, nullptr, 'i'},
{"port", required_argument, nullptr, 'p'},
{"output-file", required_argument, nullptr, 'o'},

{"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, "u:i:p:o:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'u':
if(optarg)
settings->name = optarg;
if(settings->modus)
std::cout << "Urls: " << settings->name << std::endl;
break;

case 'i':
if(optarg)
settings->proxy_ip = optarg;
if(settings->modus)
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) {
std::cout << "Invalid Port: " << optarg << std::endl;
settings->modus = Modus::EXIT;
return;
}
if(settings->modus)
std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
break;
case 'o':
if(optarg)
settings->outputFilePath = optarg;
if(settings->modus)
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
break;
case 'c':
settings->colorless = true;
if(settings->modus)
std::cout << "Farblos: true" << std::endl;
break;
case 'd':
settings->debugMode = true;
if(settings->modus)
std::cout << "Debug Modus: true" << std::endl;
break;
case 'h':
unterOption_url_help(settings, argv[0]);
return;
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;
}
}
}

void unterOption_url_help(Settings *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;
}


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");
std::string line;
int allFounds = 0;
while (getline(iStrStream, line).good())
if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) {
allFounds++;
//std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl;
}
return allFounds;
}

55
g++/parameterManager.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef PARAMETERMANAGER_H
#define PARAMETERMANAGER_H

#include <iostream>
#include <getopt.h>
#include <string.h>
#include <sstream>

enum Modus {
EXIT = -1,
DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1
};


struct Settings {
Settings() {}
Settings(std::string name) : name(name) {}

std::string name,
accountFilePath = "/tmp/a",
accountNumberPath= "/tmp/b",
cookieFilePath = "/tmp/S_New4_cookies",
proxy_ip = "127.0.0.1",
proxy_port = "9050",
languages = "GerDub,GerSub,Eng",
genaueHoster,
version = "1.0.1",
outputFilePath;
Modus modus = Modus::DEFAULT_MODUS;
bool colorless = false,
debugMode = false;
int startEpisode = 1,
stopEpisode = 0,
startSeason = 1,
stopSeason = 0;


};

Settings manageParameter(int argc, char ** argv);
std::string getProgramName(char * argv0);
int compare(std::string All_Options_with_komma_between, std::string input);


void unterOption_help(Settings * settings, char *argv0);

void 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);
void unterOption_url_help(Settings * settings, char *argv0);


#endif // PARAMETERMANAGER_H

BIN
g++/parameterManager.h.gch Normal file

Binary file not shown.

197
g++/programManager.cpp Normal file
View File

@ -0,0 +1,197 @@
#include "programManager.h"

ProgramManager::ProgramManager()
{

}

ProgramManager::~ProgramManager()
{

}

int ProgramManager::start(Settings setting)
{
switch (setting.modus) {
case Modus::DEFAULT_MODUS:
return defaultModus(&setting);
case Modus::DIRECT_LINK_MODUS:
return directLinkModus(&setting);
default:
return -1;
}
}

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;
return 27;
}

std::string nameInUrl =pageManager.checkName(settings->name);
if(nameInUrl == "-1")
return 25;
else if (pageManager.login(accountManager.getNextAccount()) != 0)
return 29;
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);

//Find out number of all seasons
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
return 32;
int maxStaffel = pageManager.counterContains(tmp_reply.html, "/staffel-%i");

if(settings->debugMode)
std::cout << "Die Serie " << settings->name << " hat " << maxStaffel << " Staffeln." << std::endl;
//For every season
for (int staffel = settings->startSeason; staffel <= maxStaffel; ++staffel) {

//Find out number of all episodes
tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel));
if(tmp_reply.html == "-1")
return 40;
int maxFolge = pageManager.counterContains(tmp_reply.html, "/episode-%i");

if(settings->debugMode)
std::cout << "Die Staffel " << staffel << " hat " << maxFolge << " Folgen." << std::endl;
//for every episode
for (int folge = settings->startEpisode; folge <= maxFolge; ++folge) {

tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge));
if(tmp_reply.html == "-1")
return 47;
std::string allLinks = pageManager.getLinks(tmp_reply.html);
std::string Link = pageManager.chooseHosterLink(allLinks, settings->genaueHoster, settings->languages);

if(settings->debugMode)
std::cout << allLinks << std::endl << " -> Link: '" << ( (Link == "") ? "" : "https://s.to") << Link << "'" << std::endl;
if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0)
return 51;

if(folge == settings->stopEpisode && settings->stopSeason < 1) // stoppe wenn stopfolge gleich der folge ist und stopstaffel nicht gesetzt wurde.
return 0;
else if ( folge == settings->stopEpisode && staffel == settings->stopSeason) // stoppe wenn stopfolge = folge && stopstaffel == staffel
return 0;
}
//Setzte Startepisode zurück für nächste Staffel
settings->startEpisode = 1;

if(staffel == settings->stopSeason) {
if(settings->debugMode)
std::cout << "Stoppe, weil Staffel: " << staffel << " == StopStaffel " << settings->stopSeason << std::endl;
break;
}
}

return 0;
}

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;
return 76;
}

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

if(pageManager.login(accountManager.getNextAccount()) != 0)
return 71;

while (getline(iStrStream, line).good()) {
if(line.find("https://s.to/redirect/") == std::string::npos) {
std::cout << "Invalid Redirect Link: '" << line << "'" << std::endl;
continue;
}
else if(convertLink(pageManager.replace(line, "https://s.to", ""), &accountManager, settings) != 0)
return 78;
}

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");

if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) {
if(allLinks == "") {
std::cout << " => " << red << "KEINEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl;
if(pageManager.writeToFile(settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
return 130;
}
else {
std::cout << " => " << orange << "Keinen PASSENDEN Hoster für die Folge " << folgenID << " gefunden." << "\033[0m" << std::endl
<< "Alle Links:" << std::endl
<< allLinks << std::endl;
if(pageManager.writeToFile(settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
return 138;
}
return 0;
}

for (int i = 1; i <= 3; ++i) {
std::string newUrl = pageManager.getUrlAfterRedirect("https://s.to" + redirectLink);
if (newUrl == "-1") {
return 102;
} else if(newUrl.find("/s.to/redirect/") != std::string::npos ) {
if(settings->debugMode)
std::cout << "Redirect Link nach umwandlung --> Neuer Account" << std::endl;
if(pageManager.login(accountManager->getNextAccount()) != 0)
return -1;
continue;
}
else {
std::cout << " => " << folgenID << green << newUrl << "\033[0m" << std::endl;
if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath,folgenID + newUrl) != 0)
return 108;
return 0;
}
}
std::cout << " => " << folgenID << red << "https://s.to" << redirectLink << "\033[0m" << std::endl;
if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath, folgenID + redirectLink) != 0)
return 114;
return 0;
}


























27
g++/programManager.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef MANAGEPROGRAM_H
#define MANAGEPROGRAM_H

#include "parameterManager.h"
#include "pageManager.h"
#include "accountManager.h"
#include <unistd.h>

class ProgramManager
{
public:
ProgramManager();
~ProgramManager();
int start(Settings setting);

private:
int defaultModus(Settings * settings);
int directLinkModus(Settings * settings);

PageManager pageManager;


int convertLink(std::string redirectLink, AccountManager *accountManager, Settings * settings, int Staffel = -1, int Folge = -1, std::string allLinks = "NOT_EMPTY");

};

#endif // MANAGEPROGRAM_H

BIN
g++/programManager.h.gch Normal file

Binary file not shown.

View File

@ -5,6 +5,10 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ProgramManager mainProgram; 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); return mainProgram.start(settings);
} }

View File

@ -11,9 +11,9 @@ PageManager::~PageManager()
remove(cookieFilePath.c_str()); 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) void PageManager::setCookieFilePath(std::string path)
@ -250,12 +250,12 @@ int PageManager::counterContains(std::string text, std::string substring_with_pr
return i-1; 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::istringstream iStrStream(text + "\n");
std::string line, returnValue; std::string line, returnValue;
while( std::getline(iStrStream, line).good() ) //auto start_of_line_position = begin( line ); //auto end_of_line_position = end( line ); 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"; returnValue += line + "\n";
if(returnValue.length() >= 1) if(returnValue.length() >= 1)
return returnValue.erase(returnValue.length()-1,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) int PageManager::writeToFile(std::string path, std::string text)
{ {
if(path == "") if(path == "")

View File

@ -8,6 +8,8 @@
#include <sstream> #include <sstream>
#include <unistd.h> #include <unistd.h>


#include <algorithm>

#include "accountManager.h" #include "accountManager.h"


struct Reply { 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(std::string sock5Proxy = "socks5://127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies");
~PageManager(); ~PageManager();


void setProxy(std::string ip, std::string port); void setProxy(std::string ip, int port);
void setCookieFilePath(std::string path); void setCookieFilePath(std::string path);
void setDebugMode(bool status); void setDebugMode(bool status);


@ -38,12 +40,15 @@ public:


std::string replace(std::string str, std::string substr1, std::string substr2); 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); 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); int writeToFile(std::string path, std::string text);


const std::string UrlPraefix = "https://s.to/serie/stream/"; const std::string UrlPraefix = "https://s.to/serie/stream/";
std::string sock5Proxy;
private: private:
std::string sock5Proxy, cookieFilePath; std::string cookieFilePath;
bool debugMode = false; bool debugMode = false;
}; };



View File

@ -1,75 +1,90 @@
#include "parameterManager.h" #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) { if(argc < 2) {
std::cout << " => Keine Unteroption angegeben." << std::endl; std::cout << " => Keine Unteroption angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl;
settings.modus = Modus::EXIT; return 1;
return settings;
} }
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 << "Aufruf: " << getProgramName(argv[0]) << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName(argv[0]) << " --help“ liefert weitere Informationen." << std::endl;
settings.modus = Modus::EXIT; return 2;
return settings;
} }


if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
unterOption_help(&settings, argv[0]); return unterOption_help(&settings, argv[0]);
return settings;


} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) { } else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
unterOption_default(&settings, argc, argv); return unterOption_default(&settings, argc, argv);
return settings;


} else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) { } else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) {
argv[1][0] = '\0'; argv[1][0] = '\0';
unterOption_url(&settings, argc, argv); return unterOption_url(&settings, argc, argv);
return settings;


} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) { } else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
std::cout << "Version: " << settings.version << std::endl; std::cout << "Version: " << settings.version << std::endl;
settings.modus = Modus::EXIT; return -1;
return settings;
} 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 { } 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;
settings.modus = Modus::EXIT; return 3;
return settings;
} }
} }


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 << "Aufruf: " << getProgramName(argv0) << " [Unteroption] [PARAMETER]" << std::endl << std::endl;
std::cout << "Unteroptionen:" << std::endl std::cout << "Unteroptionen:" << std::endl
<< "\t„--help“\tListe aller Unteroptionen" << std::endl << "\t„--help“\tListe aller Unteroptionen" << std::endl
<< "\t„--version“\tVersion des Programmes" << std::endl << "\t„--version“\tVersion des Programmes" << std::endl
<< "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl
<< "\t„default“\tModus um Links von Serien zu bekommen." << std::endl; << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl
settings->modus = Modus::EXIT; << "\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; settings->modus = Modus::DEFAULT_MODUS;
if(settings->modus)
std::cout << "Modus: DEFAULT_MODUS" << std::endl;


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
@ -99,42 +114,40 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
case 'n': case 'n':
if(optarg) if(optarg)
settings->name = optarg; settings->name = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Name: " << settings->name << std::endl; std::cout << "Name: " << settings->name << std::endl;
break; break;
case 'i': case 'i':
if(optarg) if(optarg)
settings->proxy_ip = optarg; settings->proxy_ip = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl; std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl;
break; break;
case 'p': case 'p':
if(optarg) if(optarg)
settings->proxy_port = std::to_string( atoi( optarg ) ); settings->proxy_port = atoi( optarg ) ;
if(settings->proxy_port != optarg) { if(std::to_string(settings->proxy_port) != optarg) {
std::cout << "Invalid Port: " << optarg << std::endl; std::cout << "Invalid Port: " << optarg << std::endl;
settings->modus = Modus::EXIT; return 10;
return; } else if(settings->debugMode)
}
if(settings->modus)
std::cout << "Proxy Port: " << settings->proxy_port << std::endl; std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
break; break;
case 'g': case 'g':
if(optarg) if(optarg)
settings->genaueHoster =+ optarg + std::string(","); settings->genaueHoster =+ optarg + std::string(",");
if(settings->modus) if(settings->debugMode)
std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl; std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl;
break; break;
case 'l': case 'l':
if(optarg) if(optarg)
settings->languages =+ optarg + std::string(","); settings->languages =+ optarg + std::string(",");
if(settings->modus) if(settings->debugMode)
std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl; std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl;
break; break;
case 'o': case 'o':
if(optarg) if(optarg)
settings->outputFilePath = optarg; settings->outputFilePath = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
break; break;


@ -145,16 +158,13 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
settings->startEpisode = atoi(optarg); settings->startEpisode = atoi(optarg);
if (std::to_string(settings->startEpisode) != optarg) { if (std::to_string(settings->startEpisode) != optarg) {
std::cout << "Error: -e [Folge]: '" << optarg << "' ist keine Zahl." << std::endl; std::cout << "Error: -e [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
settings->modus = Modus::EXIT; return 11;
return;
} else if (settings->startEpisode == 0) { } else if (settings->startEpisode == 0) {
std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl; std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl;
settings->modus = Modus::EXIT; return 12;
return;
} else if (settings->startEpisode < 0) { } else if (settings->startEpisode < 0) {
std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl; std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl;
settings->modus = Modus::EXIT; return 13;
return;
} }
if(settings->debugMode) if(settings->debugMode)
std::cout << "StartEpisode: " << settings->startEpisode << std::endl; std::cout << "StartEpisode: " << settings->startEpisode << std::endl;
@ -165,8 +175,7 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
settings->stopEpisode = atoi(optarg); settings->stopEpisode = atoi(optarg);
if (std::to_string(settings->stopEpisode) != optarg) { if (std::to_string(settings->stopEpisode) != optarg) {
std::cout << "Error: -E [Folge]: '" << optarg << "' ist keine Zahl." << std::endl; std::cout << "Error: -E [Folge]: '" << optarg << "' ist keine Zahl." << std::endl;
settings->modus = Modus::EXIT; return 14;
return;
} else if (settings->debugMode) } else if (settings->debugMode)
std::cout << "StopEpisode: " << settings->stopEpisode << std::endl; std::cout << "StopEpisode: " << settings->stopEpisode << std::endl;
break; break;
@ -176,18 +185,14 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
settings->startSeason = atoi(optarg); settings->startSeason = atoi(optarg);
if (std::to_string(settings->startSeason) != optarg) { if (std::to_string(settings->startSeason) != optarg) {
std::cout << "Error: -s [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl; std::cout << "Error: -s [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
settings->modus = Modus::EXIT; return 15;
return;
} else if (settings->startSeason == 0) { } else if (settings->startSeason == 0) {
std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl; std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl;
settings->modus = Modus::EXIT; return 16;
return;
} else if (settings->startSeason < 0) { } else if (settings->startSeason < 0) {
std::cout << "Error: -s [Staffel]: StartStaffel " << settings->startSeason << " ist kleiner 0." << std::endl; std::cout << "Error: -s [Staffel]: StartStaffel " << settings->startSeason << " ist kleiner 0." << std::endl;
settings->modus = Modus::EXIT; return 17;
return; } else if(settings->debugMode)
}
if(settings->debugMode)
std::cout << "StartStaffel: " << settings->startSeason << std::endl; std::cout << "StartStaffel: " << settings->startSeason << std::endl;
break; break;
case 'S': case 'S':
@ -196,36 +201,36 @@ void unterOption_default(Settings *settings, int argc, char ** argv)
settings->stopSeason = atoi(optarg); settings->stopSeason = atoi(optarg);
if (std::to_string(settings->stopSeason) != optarg) { if (std::to_string(settings->stopSeason) != optarg) {
std::cout << "Error: -S [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl; std::cout << "Error: -S [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl;
settings->modus = Modus::EXIT; return 18;
return;
} else if(settings->debugMode) } else if(settings->debugMode)
std::cout << "StopSeason: " << settings->stopSeason << std::endl; std::cout << "StopSeason: " << settings->stopSeason << std::endl;
break; break;



case 'c': case 'c':
settings->colorless = true; settings->colorless = true;
if(settings->modus) if(settings->debugMode)
std::cout << "Farblos: true" << std::endl; std::cout << "Farblos: true" << std::endl;
break; break;
case 'd': case 'd':
settings->debugMode = true; settings->debugMode = true;
if(settings->modus) if(settings->debugMode)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_default_help(settings, argv[0]); unterOption_default_help(settings, argv[0]);
return; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName(argv[0]) << " default [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName(argv[0]) << " default --help“ liefert weitere Informationen." << std::endl;
settings->modus = Modus::EXIT; return -1;
return;
} }
} }
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 std::cout << "Usage: " << getProgramName(argv0) << " default [ Parameter & {-n [Name]} ]..." << std::endl
<< "Parameter:" << std::endl << std::endl << "Parameter:" << std::endl << std::endl
@ -236,7 +241,7 @@ void unterOption_default_help(Settings *settings, char * argv0)
<< " > Auswahloptionen:" << std::endl << " > Auswahloptionen:" << std::endl
<< "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl << "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl
<< "\t -> Die Namen der Hoster, deren Links du willst. Der wichtigste zuerst." << std::endl << "\t -> Die Namen der Hoster, deren Links du willst. Der wichtigste zuerst." << std::endl
<< "\t-l [GerSub/GerDub/Eng,...], --languages [GerSub/GerDub/Eng,...]" << std::endl << "\t-l [GerDub/GerSub/Eng,...], --languages [GerDub/GerSub/Eng,...]" << std::endl
<< "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl << "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl
<< std::endl << std::endl
<< " > Proxy-Optionen:" << std::endl << " > Proxy-Optionen:" << std::endl
@ -271,15 +276,13 @@ void unterOption_default_help(Settings *settings, char * argv0)
<< std::endl << std::endl
<< " > Help-Optionen" << std::endl << " > Help-Optionen" << std::endl
<< "\t-h, --help" << 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; settings->modus = Modus::DIRECT_LINK_MODUS;
if(settings->modus)
std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl;


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
@ -301,68 +304,73 @@ void unterOption_url(Settings *settings, int argc, char **argv)
case 'u': case 'u':
if(optarg) if(optarg)
settings->name = optarg; settings->name = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Urls: " << settings->name << std::endl; std::cout << "Urls: " << settings->name << std::endl;
break; break;


case 'i': case 'i':
if(optarg) if(optarg)
settings->proxy_ip = optarg; settings->proxy_ip = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl; std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl;
break; break;
case 'p': case 'p':
if(optarg) if(optarg)
settings->proxy_port = std::to_string( atoi( optarg ) ); settings->proxy_port = atoi( optarg );
if(settings->proxy_port != optarg) { if(std::to_string(settings->proxy_port) != optarg) {
std::cout << "Invalid Port: " << optarg << std::endl; std::cout << "Invalid Port: " << optarg << std::endl;
settings->modus = Modus::EXIT; return 20;
return;
} }
if(settings->modus) if(settings->debugMode)
std::cout << "Proxy Port: " << settings->proxy_port << std::endl; std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
break; break;
case 'o': case 'o':
if(optarg) if(optarg)
settings->outputFilePath = optarg; settings->outputFilePath = optarg;
if(settings->modus) if(settings->debugMode)
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
break; break;
case 'c': case 'c':
settings->colorless = true; settings->colorless = true;
if(settings->modus) if(settings->debugMode)
std::cout << "Farblos: true" << std::endl; std::cout << "Farblos: true" << std::endl;
break; break;
case 'd': case 'd':
settings->debugMode = true; settings->debugMode = true;
if(settings->modus) if(settings->debugMode)
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
case 'h': case 'h':
unterOption_url_help(settings, argv[0]); unterOption_url_help(settings, argv[0]);
return; return -1;
default: default:
std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl; std::cout << "Aufruf: " << getProgramName(argv[0]) << " url [PARAMETER]" << std::endl;
std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl; std::cout << "„" << getProgramName(argv[0]) << " url --help“ liefert weitere Informationen." << std::endl;
settings->modus = Modus::EXIT; return 21;
return;
} }
} }
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 std::cout << "Usage: " << getProgramName(argv0) << " url [ Parameter & {-u [Url]} ]..." << std::endl
<< "Parameter" << std::endl << "Parameter:" << std::endl
<< "\t-u [Url1,Url2,...], \t--url [Url1,Url2,...]" << std::endl << "\t-u [Url1,Url2,...], --url [Url1,Url2,...]" << std::endl
<< "\t-i [ProxyIPAddresse], \t--ip-addresse [ProxyIPAddresse] Default: 127.0.0.1" << std::endl << "\t -> Die zu umwandelnden redirect-Links." << std::endl
<< "\t-p [ProxyPort], \t--port [ProxyPort]\t\t Default: 9050" << std::endl << "\t-i [ProxyIPAddresse], --ip-addresse [ProxyIPAddresse]" << std::endl
<< "\t-o [Pfad], \t\t--output-file [Pfad]" << std::endl << "\t -> Default: 127.0.0.1." << std::endl
<< "\t-c, \t\t\t--colorless\t\t\t Default: false" << std::endl << "\t-p [ProxyPort], --port [ProxyPort]" << std::endl
<< "\t-d, \t\t\t--debug-mode\t\t\t Default: false" << std::endl << "\t -> Default: 9050." << std::endl
<< "\t -> Debug Nachrichten an." << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl
<< "\t-h, \t\t\t--help" << std::endl; << "\t-c, --colorless" << std::endl
settings->modus = Modus::EXIT; << "\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 ) ); 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) int compare(std::string All_Options_with_komma_between, std::string input)
{ {
std::istringstream iStrStream( All_Options_with_komma_between + "\n"); 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; 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;
}

View File

@ -5,11 +5,13 @@
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include <sys/stat.h>


enum Modus { enum Modus {
EXIT = -1, EXIT = -1,
DEFAULT_MODUS = 0, DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1 DIRECT_LINK_MODUS = 1,
Search_MODUS = 2
}; };




@ -21,35 +23,43 @@ struct Settings {
accountFilePath = "/tmp/a", accountFilePath = "/tmp/a",
accountNumberPath= "/tmp/b", accountNumberPath= "/tmp/b",
cookieFilePath = "/tmp/S_New4_cookies", cookieFilePath = "/tmp/S_New4_cookies",
serienListPath = "/tmp/SerienListe",
proxy_ip = "127.0.0.1", proxy_ip = "127.0.0.1",
proxy_port = "9050",
languages = "GerDub,GerSub,Eng", languages = "GerDub,GerSub,Eng",
genaueHoster, genaueHoster = "",
version = "1.0.1", version = "1.0.1",
outputFilePath; outputFilePath;
Modus modus = Modus::DEFAULT_MODUS; Modus modus = Modus::DEFAULT_MODUS;
bool colorless = false, bool colorless = false,
debugMode = false; debugMode = false,
search_IgnoreUpperLower = true,
search_wantUpdate = false;
int startEpisode = 1, int startEpisode = 1,
stopEpisode = 0, stopEpisode = 0,
startSeason = 1, 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); std::string getProgramName(char * argv0);
int compare(std::string All_Options_with_komma_between, std::string input); 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); int unterOption_default(Settings * settings, int argc, char **argv);

void unterOption_default(Settings * settings, int argc, char **argv);
void unterOption_default_help(Settings * settings, char * argv0); 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); 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 #endif // PARAMETERMANAGER_H

View File

@ -5,13 +5,24 @@ ProgramManager::ProgramManager()


} }


int ProgramManager::start(Settings setting) ProgramManager::~ProgramManager()
{ {
switch (setting.modus) {
}

int ProgramManager::start(Settings settings)
{
pageManager.setProxy(settings.proxy_ip, settings.proxy_port);
pageManager.setCookieFilePath(settings.cookieFilePath);
pageManager.setDebugMode(settings.debugMode);

switch (settings.modus) {
case Modus::DEFAULT_MODUS: case Modus::DEFAULT_MODUS:
return defaultModus(&setting); return defaultModus(&settings);
case Modus::DIRECT_LINK_MODUS: case Modus::DIRECT_LINK_MODUS:
return directLinkModus(&setting); return directLinkModus(&settings);
case Modus::Search_MODUS:
return searchModus(&settings);
default: default:
return -1; return -1;
} }
@ -20,9 +31,6 @@ int ProgramManager::start(Settings setting)
int ProgramManager::defaultModus(Settings *settings) int ProgramManager::defaultModus(Settings *settings)
{ {
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); 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 == "") { if(settings->name == "") {
std::cout << "Kein Name angegeben: Missing Parameter -n [Name]." << std::endl; std::cout << "Kein Name angegeben: Missing Parameter -n [Name]." << std::endl;
@ -30,8 +38,10 @@ int ProgramManager::defaultModus(Settings *settings)
} }


std::string nameInUrl =pageManager.checkName(settings->name); std::string nameInUrl =pageManager.checkName(settings->name);
if(nameInUrl == "-1") if(nameInUrl == "-1") {
searchModus(settings);
return 25; return 25;
}
else if (pageManager.login(accountManager.getNextAccount()) != 0) else if (pageManager.login(accountManager.getNextAccount()) != 0)
return 29; return 29;
pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name); pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name);
@ -90,9 +100,6 @@ int ProgramManager::defaultModus(Settings *settings)
int ProgramManager::directLinkModus(Settings *settings) int ProgramManager::directLinkModus(Settings *settings)
{ {
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath); 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 == "") { if(settings->name == "") {
std::cout << "Kein(e) Link(s) angegeben: Missing Parameter -u [Url]." << std::endl; std::cout << "Kein(e) Link(s) angegeben: Missing Parameter -u [Url]." << std::endl;
@ -117,11 +124,123 @@ int ProgramManager::directLinkModus(Settings *settings)
return 0; 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) 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 ) + ": "); + "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(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) {
if(allLinks == "") { if(allLinks == "") {

View File

@ -10,11 +10,15 @@ class ProgramManager
{ {
public: public:
ProgramManager(); ProgramManager();
~ProgramManager();
int start(Settings setting); int start(Settings setting);


private: private:
int defaultModus(Settings * settings); int defaultModus(Settings * settings);
int directLinkModus(Settings * settings); int directLinkModus(Settings * settings);
int searchModus(Settings * settings);
int searchModus_update(Settings * settings);



PageManager pageManager; PageManager pageManager;