mv source files to src folder

This commit is contained in:
Markus
2019-11-04 14:56:32 +01:00
parent c8ad9fd891
commit 7ec961a457
11 changed files with 2 additions and 2 deletions

40
src/S_New4.pro Normal file
View File

@ -0,0 +1,40 @@
QT -= gui
#Linux:
unix: LIBS += -lcurl
#Windows
win32: LIBS += -L$${_PRO_FILE_PWD_}\curl -lcurl
CONFIG += c++14 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
pageManager.cpp \
parameterManager.cpp \
programManager.cpp \
accountManager.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
pageManager.h \
parameterManager.h \
programManager.h \
accountManager.h

197
src/accountManager.cpp Normal file
View File

@ -0,0 +1,197 @@
#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 << " => Error: 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 << " => Error: 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(" => Error: 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 << "HumorvollWundervollerDelfin@spam.care/HumorvollWundervollerDelfin@spam.care" << std::endl;
ofs << "ExzellentPackenderHirsch@muell.icu/ExzellentPackenderHirsch@muell.icu" << std::endl;
ofs << "GrandiosLeuchtenderPanda@papierkorb.me" << std::endl;
ofs << "AttraktivPositiverSteinbock@magspam.net" << std::endl;
ofs << "FreundlichKostbarerSteinbock@spam.care" << std::endl;
ofs << "FabelhaftSelbstsichererUhu@spam.care" << std::endl;
ofs << "HumorvollSinnlicherRabe@muell.icu" << std::endl;
ofs << "AnspruchsvollTraumhafterPavian@ultra.fyi" << std::endl;
ofs << "FaszinierendRiskanterLuchs@magspam.net" << std::endl;
ofs << "BeruehmtMystischerPanda@ultra.fyi" << std::endl;
ofs << "CharmantRasanterLoewe@existiert.net" << std::endl;
ofs << "BedeutendLuesternerAal@existiert.net" << std::endl;
ofs << "ElegantSelbstsichererAdler@ultra.fyi" << std::endl;
ofs << "FaszinierendKoeniglicherBaer@spam.care" << std::endl;
ofs << "CharmantKostbarerLoewe@magspam.net" << std::endl;
ofs << "BedeutendPrallerSkorpion@muellemail.com" << std::endl;
ofs << "FreundlichPerfekterRochen@muellmail.com" << std::endl;
ofs << "AusgelassenKostbarerBasilisk@magspam.net" << std::endl;
ofs << "FabelhaftLebhafterSchakal@ultra.fyi" << std::endl;
ofs << "ExzellentSchoenerSteinbock@existiert.net" << std::endl;
ofs << "ErhellendLustvollerAdler@muell.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 << "BefluegeltPrallerSchwan@spam.care" << std::endl;
ofs << "ErhellendSeltenerSeeloewe@ultra.fyi" << std::endl;
ofs << "FreundlichZuverlaessigerSchwan@spam.care" << std::endl;
ofs << "HervorragendWundervollerReiher@oida.icu" << std::endl;
ofs << "AnspruchsvollStilvollerUhu@magspam.net" << std::endl;
ofs << "AnmutigTraumhafterHai@muellemail.com" << std::endl;
ofs << "AtemberaubendIdealerTapir@ultra.fyi" << std::endl;
ofs << "GeheimLeuchtenderLuchs@muellemail.com" << std::endl;
ofs << "DuftendKlarerTapir@muellmail.com" << std::endl;
ofs << "GeheimUnwiderstehlicherRabe@muell.icu" << std::endl;
ofs << "ExtravagantSpektakulaererAdler@spam.care" << std::endl;
ofs << "BildlichWarmerLoewe@oida.icu" << std::endl;
ofs << "AktivKlarerHai@spam.care" << std::endl;
ofs << "AktivKostbarerElch@oida.icu" << std::endl;
ofs << "Strust1991@jourrapide.com" << std::endl;
ofs << "Natchoughe1928@dayrep.com" << std::endl;
ofs << "zweirot@einrot.com" << std::endl;
ofs << "AktivMagischerFrosch@existiert.net" << std::endl;
ofs << "ErhellendPerfekterDachs@existiert.net" << std::endl;
ofs << "ojfvwj.fgf@existiert.net" << std::endl;
ofs << "lusiouae@wegwerfemail.de" << std::endl;
ofs << "fraiwrou@wegwerfemail.de" << std::endl;
ofs << "driotean@wegwerfemail.de" << std::endl;
ofs << "tiaprour@wegwerfemail.de" << std::endl;
ofs << "FeurigWarmerPapagei@existiert.net" << std::endl;
ofs << "FrischStilvollerPavian@magspam.net" << std::endl;
ofs << "FeurigZaghafterLoewe@muellmail.com" << std::endl;
ofs << "GigantischKoeniglicherSchwan@magspam.net" << std::endl;
ofs << "FreizuegigPersoenlicherLemming@spam.care" << std::endl;
ofs << "BelebtIntelligenterHusky@papierkorb.me" << std::endl;
ofs << "FreundlichMaximalerSpecht@muellmail.com" << std::endl;
ofs << "FreundlichStarkerHirsch@ultra.fyi" << std::endl;
ofs << "ErstklassigRasanterElch@oida.icu" << std::endl;
ofs << "FreundlichStarkerPavian@ultra.fyi" << std::endl;
ofs << "EinfuehlsamRiskanterPapagei@oida.icu" << std::endl;
ofs << "FantastischPositiverHirsch@existiert.net" << std::endl;
ofs << "GeborgenIndividuellerOtter@muell.icu" << std::endl;
ofs << "HervorragendSensibelerWal@oida.icu" << std::endl;
ofs << "HerrlichIndividuellerPelikan@spam.care" << std::endl;
ofs << "HerrlichLeuchtenderTapir@muellmail.com" << std::endl;
ofs << "ErstaunlichIntensiverEsel@magspam.net" << std::endl;
ofs << "ExtravagantPraechtigerWal@muellemail.com" << std::endl;
ofs << "GravierendWundervollerFalke@spam.care" << std::endl;
ofs << "EntzueckendLebhafterFlamingo@magspam.net" << std::endl;
ofs << "GeheimSprachloserStorch@existiert.net" << std::endl;
ofs << "GravierendVitalerOtter@spam.care" << std::endl;
ofs << "GrenzenlosInteressanterElch@oida.icu" << std::endl;
ofs << "HellPackenderGoldfisch@muellemail.com" << std::endl;
ofs << "AbenteuerlichSelbstloserFalke@muell.icu" << std::endl;
ofs << "EmotionalZaghafterPapagei@magspam.net" << std::endl;
ofs << "HellLiebenswerterElefant@muellemail.com" << std::endl;
ofs << "BildlichImponierenderEsel@muellemail.com" << std::endl;
ofs << "ErstaunlichSprachloserPapagei@ultra.fyi" << std::endl;
ofs << "BerauschendLebendigerDelfin@ultra.fyi" << std::endl;
ofs << "GravierendIntensiverHase@oida.icu" << std::endl;
ofs << "BerauschendUnglaublicherGorilla@oida.icu" << std::endl;
ofs << "GenuesslichPraechtigerDachs@spam.care" << 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(" => Error: 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 << " => Error: Account Number Datei ist nicht geöffnet." << std::endl;
return 110;
}
//fStream.clear();
ofs << number << std::endl;
return 0;
}

28
src/accountManager.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef ACCOUNTMANAGER_H
#define ACCOUNTMANAGER_H
#include <iostream>
#include <vector>
#include <fstream>
struct Account {
std::string Email, Password;
};
class AccountManager
{
public:
AccountManager(std::string pathToFile, std::string pathToAccountNumberFile);
Account getNextAccount();
size_t getLastAccountNumber();
private:
std::vector<Account> accounts;
std::string pathToAccountNumberFile;
int setLastAccountNumber(size_t number);
int writeDefault(std::string path);
};
#endif // ACCOUNTMANAGER_H

17
src/main.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "programManager.h"
int main(int argc, char *argv[])
{
ProgramManager mainProgram;
Settings settings;
int res = manageParameter(settings, argc, argv);
if(res == -1)
return 0;
else if(res != 0) {
if(settings.debugMode)
std::cout << " => Error: Das Auswerten der Parameter ist fehlgeschlagen!" << std::endl;
return res;
} else {
return mainProgram.start(&settings);
}
}

523
src/pageManager.cpp Normal file
View File

@ -0,0 +1,523 @@
#include "pageManager.h"
PageManager::PageManager(std::string sock5ProxyOnlyAddress, std::string cookieFilePath)
: sock5Proxy("socks5://" + sock5ProxyOnlyAddress), cookieFilePath(cookieFilePath)
{
curl_global_init(CURL_GLOBAL_ALL);
}
PageManager::~PageManager()
{
curl_global_cleanup();
}
void PageManager::setProxy(std::string ip, int port)
{
if(!port) {
if(debugMode)
std::cout << " => INFO: Es wird kein Proxy verwendet." << std::endl;
this->sock5Proxy = "";
} else {
this->sock5Proxy = "socks5://" + ip + ":" + std::to_string(port);
if(debugMode)
std::cout << "Proxy: " << ip << ":" << port << std::endl;
}
}
void PageManager::setCookieFilePath(std::string path)
{
this->cookieFilePath = path;
}
void PageManager::setDebugMode(bool status)
{
this->debugMode = status;
}
//Save reply to string
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;
}
//Write data to file
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
size_t written = fwrite(ptr, size, nmemb, reinterpret_cast<FILE *>(stream));
return written;
}
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;
//info ausgabe
std::cout << ( "\33[2K\rLade: '" + Url + "'..." + ((debugMode) ? "\n" : "" )) << std::flush;
curl = curl_easy_init();
if(!curl) {
perror("\33[2K\r => Error: Curl easy init failed");
return Reply("-1");
}
//Settings
if(sock5Proxy != "")
curl_easy_setopt(curl, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl
else if(debugMode)
std::cout << "\33[2K\r => INFO: Es wird kein Proxy verwendet." << std::endl;
//curl_easy_setopt(curl, CURLOPT_FAILONERROR, true); // html errors to errorcode res
//curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false); // Progressausgabe aktivieren
curl_easy_setopt(curl, CURLOPT_URL, Url.c_str()); //Url 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::flush;
if(res != CURLE_OK) {
if(timeout == maxTimeout) {
perror((std::string("\33[2K\r => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str());
return Reply("-1");
} else {
std::cout << std::string( "\33[2K\r => Warning: Versuch " + std::to_string(timeout) + " von " + std::to_string(maxTimeout) + ": curl_easy_perform() failed: " + curl_easy_strerror(res) )<< std::flush;
sleep(1);
}
} else {
break;
}
}
//Get Url
res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
if( res != CURLE_OK || !url ) {
perror((std::string("\33[2K\r => 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::downLoadToFile(std::string filePath, std::string url)
{
CURL *curl_handle;
FILE *pagefile;
CURLcode res;
/* open the file */
pagefile = fopen(filePath.c_str(), "wb"); // w == write; b == binäre
if(!pagefile) {
perror("Open File filed");
return 1;
}
//Info ausgabe
std::cout << ( "\33[2K\rDownloade: '" + url + "'..." + ((debugMode) ? "\n" : "" )) << std::flush;
/* init the curl session */
curl_handle = curl_easy_init();
if(!curl_handle) {
perror("\33[2K\r => Error: Curl easy init failed");
return 2;
}
/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
/* Switch on full protocol/debug output while testing */
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, false);
/* disable progress meter, set to 0L to enable and disable debug output */
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, false);
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
//Sock5Proxy für Curl
if(sock5Proxy != "")
curl_easy_setopt(curl_handle, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl
else if(debugMode)
std::cout << "\33[2K\r => INFO: Es wird kein Proxy verwendet." << std::endl;
//User Agent
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0");
/* write the page body to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
//Error 404, for example => not found
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, true);
int maxTimeOut = 5;
bool failed = false;
for (int timeout = 1; timeout <= maxTimeOut; ++timeout) {
/* get it! */
if( (res = curl_easy_perform(curl_handle)) != CURLE_OK ) {
//Wenns fehlschlägt error ( + wiederversuchen )
if(timeout == maxTimeOut) {
perror((std::string("\33[2K\r => Error: curl_easy_perform() failed: ") + curl_easy_strerror(res)).c_str());
failed = true;
} else {
std::cout << std::string( "\33[2K\r => Warning: Versuch " + std::to_string(timeout) + " von " + std::to_string(maxTimeOut) + ": curl_easy_perform() failed: " + curl_easy_strerror(res) )<< std::flush;
sleep(1);
}
} else {
//Sonst ( wenns functioniert) schleife verlassen
break;
}
}
/* close the header file */
if(fclose(pagefile) != 0) {
perror(" => Error: fclose failed");
return 4;
}
/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
return (failed) ? 10 : 0;
}
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::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 << "\33[2K\r => Error: 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 << "\33[2K\r => Error: Ungültiger Name: '" << Name << "'" << std::endl;
return "-1";
} else if (html == "-1" || html == "") {
return "-2";
}
else {
std::cout << "\33[2K\r > Name: " << name << std::endl;
return name;
}
}
std::string PageManager::getLinks(std::string HTML)
{
size_t pos = HTML.find("<ul class=\"row\">");
if(pos == std::string::npos) {
std::cout << " => Error: 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 << " => Error: 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.length() > 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 + substr1.length()) )
str.replace(index, substr1.length(), 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, 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 || ( 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);
else
return "";
}
std::string PageManager::upper_string(const std::string &str)
{
std::string upper;
transform(str.begin(), str.end(), std::back_inserter(upper), toupper);
return upper;
}
size_t PageManager::getDate()
{
std::time_t now = std::time(nullptr);
struct tm *tm_now = localtime(&now);
return static_cast<size_t>( static_cast<double>(1900 + tm_now->tm_year) * 365.24220 +
static_cast<double>(tm_now->tm_mon +1) * 30.43685 + tm_now->tm_mday);
}
std::string PageManager::getExePath()
{
#ifdef __linux__
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len == -1) {
perror("Readlink proc self exe failed");
return "";
} else {
buff[len] = '\0';
return std::string(buff);
}
#endif
#ifdef _WIN32
wchar_t buffer[MAX_PATH + 1];
GetModuleFileName( nullptr, buffer, MAX_PATH );
std::wstring wstr(buffer);
return std::string(wstr.begin(), wstr.end());
#endif
}
int PageManager::compareVersions(std::string Version1, std::string Version2)
{
std::string StringList[2] = { ( Version1 + "." ), ( Version2 + "." ) };
int Versions[2][3];
size_t pos;
//Für beide Versionen:
for (int n = 0; n < 2; ++n) {
//Für 3 Punkte:
for (int i = 0; i < 3; ++i) {
//Wenn kein Punkt gefunden werden konnte => Error:
if( (pos = StringList[n].find(".")) == std::string::npos) {
std::cout << " => Error: Ungültige ProgrammVersion: '" << ( (n == 0) ? Version1 : Version2 ) << "'" << std::endl;
return -1;
//wenn punkt gefunden werden konnte
} else {
//Wenn der Teilstring keine Zahl ist error:
if( !isNumber(StringList[n].substr(0, pos)) ) {
std::cout << " => Error: Ungültige ProgrammVersion: (Keine Zahl): '" << ( (n == 0) ? Version1 : Version2 ) << "'" << std::endl;
return -1;
} else {
//Sonst speicher Zahl in array und entferne den anfang des strings
Versions[n][i] = atoi(StringList[n].substr(0, pos).c_str());
StringList[n].erase(0, pos + 1);
}
}
}
}
for (int i = 0; i < 3; ++i) {
if(Versions[0][i] > Versions[1][i]) {
return 2;
} else if(Versions[0][i] < Versions[1][i]) {
return 1;
}
}
return 0;
}
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(" => Error: 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 == "")
continue;
else if ( langId == "GerDub" )
LangId=1;
else if ( langId == "Eng" )
LangId=2;
else if ( langId == "GerSub" )
LangId=3;
else {
std::cout << " => Error: 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=\"' in chooseHosterLink() nicht finden." << std::endl;
continue;
}
Line.erase(0, pos + 6/*static_cast<int>(strlen("href=\""))*/);
pos = Line.find("\"");
if(pos == std::string::npos) {
std::cout << " => Error: Konnte '\"' in chooseHosterLink() nicht finden." << std::endl;
continue;
}
return Line.erase(pos, Line.length()-pos);
}
}
return "";
}

60
src/pageManager.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef MANAGEPAGE_H
#define MANAGEPAGE_H
#include "accountManager.h"
#include "curl/curl.h"
#include "parameterManager.h" // for isNumber
#include <sstream>
#include <unistd.h> // sleep
#include <algorithm>
#include <ctime> // std::time, localtime ...
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 sock5ProxyOnlyAddress = "127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies");
~PageManager();
void setProxy(std::string ip, int 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 downLoadToFile(std::string filePath, std::string url);
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, bool IgnoreCaseSensetifity = false);
std::string upper_string(const std::string& str);
size_t getDate();
std::string getExePath();
int compareVersions(std::string Version1, std::string Version2);
int writeToFile(std::string path, std::string text);
const std::string UrlPraefix = "https://s.to/serie/stream/";
std::string sock5Proxy;
private:
std::string cookieFilePath;
bool debugMode = false;
};
#endif // MANAGEPAGE_H

1416
src/parameterManager.cpp Normal file

File diff suppressed because it is too large Load Diff

150
src/parameterManager.h Normal file
View File

@ -0,0 +1,150 @@
#ifndef PARAMETERMANAGER_H
#define PARAMETERMANAGER_H
#ifndef __linux__
#ifndef _WIN32
#error "Error Invalid System: Only for Linux and Windows systems!"
#endif
#endif
#include <iostream>
#include <getopt.h>
#include <string.h> // strlen
#include <sstream>
#include <sys/stat.h>
#include <fstream>
#include <vector>
#include <limits.h> // PATH_MAX
#include <unistd.h> // readlink()
#include <dirent.h>
#ifdef _WIN32
#include <windows.h>
#endif
enum Modus {
EXIT = -1,
DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1,
SEARCH_MODUS = 2,
INFO_MODUS = 3,
NEWS_MODUS = 4,
UPDATE_MODUS = 5,
REMOVE_SETTINGS_AND_CACHE_MODUS = 6
};
struct Settings {
Settings() {}
Settings(std::string name) : name(name) {}
const std::string programName = "S_New4";
#ifdef __linux
const std::string VersionFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=Version-LINx86.txt";
const std::string ProgrammFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=S_New4-LINx86";
#endif
#ifdef _WIN32
const std::string VersionFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=Version-WINx86.txt";
const std::string ProgrammFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=S_New4-WINx86.exe";
#endif
std::string name,
accountFilePath = "",
accountNumberPath= "",
cookieFilePath = "",
serienListPath = "",
lastUpdateDateFilePath = "",
configDir="",
cacheDir="",
defaultsFilePath = "",
proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng,",
genaueHoster = "",
version = "3.6.1",
defaultFileVersion="1.6",
outputFilePath = "",
default_checkPath = "",
default_Searchmuster = "S%Staffel%E%Folge%";
Modus modus = Modus::EXIT;
bool colorless = false,
debugMode = false,
search_IgnoreUpperLower = true,
search_wantUpdate = false,
askForEveryDir = true,
skipEpisodenNameOutput = false;
int startEpisode = 1,
stopEpisode = 0,
startSeason = 1,
stopSeason = 0,
proxy_port = 9050,
default_maxDirs = 20,
updateWarningDays = 10;
char pathSymbol = '/';
unsigned maxThreads = 0;
};
int manageParameter(Settings &settings, int argc, char ** argv);
int loadDefaulOptions(Settings & settings);
std::vector<std::string> compare(std::string All_Options_with_komma_between, std::string input);
bool isNumber(std::string number);
int setPaths(Settings &settings);
bool fileExists (const std::string& name);
bool dirExists(std::string dir);
bool nothingExists(std::string path);
bool createDirIsOk(std::string path);
bool makePathIsOk(std::string path);
bool removeDirIsOk(std::string path, Settings *settings);
int unterOption_help(Settings &settings);
void unterOption_printVersion(Settings &settings);
int unterOption_default(Settings * settings, int argc, char **argv);
void unterOption_default_help(std::string programName);
int unterOption_url(Settings * settings, int argc, char **argv);
void unterOption_url_help(std::string programName);
int unterOption_search(Settings * settings, int argc, char **argv);
void unterOption_search_help(std::string programName);
int unterOption_info(Settings * settings, int argc, char **argv);
void unterOption_info_help(std::string programName);
void unterOption_clean(Settings * settings, int argc, char **argv);
int unterOption_news(Settings * settings, int argc, char **argv);
void unterOption_news_help(std::string programName);
int unterOption_update(Settings * settings, int argc, char **argv);
void unterOption_update_help(std::string programName);
int unterOption_RemoveSettings_or_CacheDir(Settings * settings, int argc, char **argv);
void unterOption_RemoveSettings_or_CacheDire_help(std::string programName);
int setS5ProxytoSettings(Settings &settings, std::string optarg);
#endif // PARAMETERMANAGER_H

1481
src/programManager.cpp Normal file

File diff suppressed because it is too large Load Diff

66
src/programManager.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef MANAGEPROGRAM_H
#define MANAGEPROGRAM_H
#include "pageManager.h"
#include "parameterManager.h"
#include "accountManager.h"
#include <sys/types.h>
#include <pthread.h>
struct ThreadData
{
ThreadData(unsigned id, pthread_t init, std::string nameinUrl,int exitStateInit, Settings * settings, AccountManager * accountMg, PageManager * pM)
: id(id), thread(init), nameInUrl(nameinUrl), exitState(exitStateInit), settings(settings), accountManager(accountMg), pageManager(pM) {}
unsigned id;
pthread_t thread;
std::string nameInUrl, returnValue;
int staffel, folge, exitState;
Settings * settings;
AccountManager * accountManager;
PageManager * pageManager;
void * setState(int state) {
this->exitState = state;
return nullptr;
}
void setData(int staffel, int folge) { this->staffel = staffel; this->folge = folge; }
};
class ProgramManager
{
public:
ProgramManager();
~ProgramManager();
int start(Settings *setting);
int listDir(std::string &list, std::string path, int maxDepth);
private:
int defaultModus(Settings * settings);
int directLinkModus(Settings * settings);
int searchModus(Settings * settings, std::string *saveTo = nullptr, bool noPrint = false);
int infoModus(Settings * settings);
int newsModus(Settings *settings);
int updateModus(Settings *settings);
int cleanUpSettingsAndCache(Settings *settings);
PageManager pageManager;
std::vector<ThreadData*> threadList;
unsigned nextThread;
int convertLink(std::string redirectLink, AccountManager *accountManager, Settings * settings, int Staffel = -1, int Folge = -1, std::string allLinks = "NOT_EMPTY");
int searchModus_update(Settings * settings);
int waitForThreads();
int sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName);
int checkLastUpdate(Settings * settings);
};
#endif // MANAGEPROGRAM_H