Compare commits

...

75 Commits

Author SHA1 Message Date
Markus
7b92a22ef0 3.6.3: finish defines for SystemCheck for Updater + info to helpmenü 2019-11-04 18:02:42 +01:00
Markus
d338ed9465 fix defins for updater 2019-11-04 17:54:11 +01:00
Markus
9e223fd99b fix defin messages 2019-11-04 17:36:25 +01:00
Markus
b04bde2ed6 füge ifedf bei festlegen der updater links hinzu 2019-11-04 17:32:14 +01:00
Markus
631a18bb16 v3.6.2: füge changelog hinzu 2019-11-04 15:44:49 +01:00
Markus
4bbce450b1 Merge branch 'master' of ssh://code.obermui.de:3232/markus/S_New4 2019-11-04 14:56:50 +01:00
Markus
7ec961a457 mv source files to src folder 2019-11-04 14:56:32 +01:00
Markus
8c852a77f2 fix readme 2019-11-04 14:21:15 +01:00
Markus
c8ad9fd891 add infos to readme 2019-11-04 14:20:15 +01:00
Markus
12337b4963 3_11 2019-11-03 15:38:23 +01:00
Markus
61995f0587 v3.6.1: extra ausgabe für ungültige link vorallem beu snew4 url 2019-11-01 20:06:56 +01:00
Markus
812df40b98 v3.6.0: füge Möglichkkeit hinzu keinen Proxy zu verwenden & keinen Proxy bei standert paramater bei upgrade Modus 2019-11-01 19:52:32 +01:00
Markus
de69b0bc59 v3.5.6: S_New4 help == S_New4 --help 2019-11-01 19:27:10 +01:00
Markus
923e699d30 clean Up S_New Project Folder 2019-11-01 19:23:12 +01:00
Markus
debe9f7bd1 v3.5.5: extra return value -2 bei checkName, -2 != -1, -1 name error, -2 download error, stoppe bei -2 immer sofort 2019-10-31 15:25:45 +01:00
Markus
6216ee60c0 v3.5.4 fix errors 2019-10-31 15:09:09 +01:00
Markus
f00d85c8d1 v3.5.3: füge 2ten Name augabe bei 1ner gefunden serie auch hinzu & ' bei errors 2019-10-31 14:28:30 +01:00
Markus
65f7a4eead v3.5.2: füge zweitnamenausgabe bei namenauswahl hinzu 2019-10-31 14:16:27 +01:00
Markus
8b21630e8f v3.5.1: serienliste nun alphabetisch komplett sortiert 2019-10-31 13:27:35 +01:00
Markus
f3f125b562 v3.5.0: bei info Subfunction: Parameter um Folgenausgabe zu verhind(Namen ausgabe 2019-10-31 13:15:54 +01:00
Markus
6a526269db v3.4.6: fix error: sonderzeicehn in der serienliste 2019-10-30 16:37:35 +01:00
Markus
a450f87e0d 3.4.5: add colors to info function 2019-10-30 16:32:30 +01:00
Markus
5cdd485b4f v3.4.4 2019-10-30 14:54:51 +01:00
Markus
c415a475ca fix error with html sonderzeichen && better looking at info name ausgabe 2019-10-30 14:54:23 +01:00
Markus
f2fdaa54a3 v3.4.3 2019-10-27 21:34:19 +01:00
Markus
c4bbb35e11 fix big errors: 1. in listDir add to subdir in Windows an / ,too not an ; 2.: names with an / in the name: error with search modos etc: function looks for / at url name => now: looks for |/ 2019-10-27 21:34:03 +01:00
Markus
e79caf03af v3.4.2: add error messagt to --remove when no dir is called 2019-10-27 20:50:36 +01:00
Markus
3ed500205c v3.4.1 2019-10-27 20:44:22 +01:00
Markus
66260307f6 fix helpmenue: missing subfunction --remove && wrong path symbol in windows && wromng path symbol in some functions 2019-10-27 20:43:53 +01:00
Markus
2b6af638c0 add check in checkNameFunction 2019-10-27 20:35:16 +01:00
Markus
fce2707f54 Merge branch 'master' of ssh://code.obermui.de:3232/markus/S_New4 2019-10-27 19:49:54 +01:00
Markus
ed125f4eb6 default modus in settings to exit 2019-10-27 19:13:11 +01:00
Markus
fbfc7caab7 v3.4.0 fix subfunction --remove 2019-10-27 10:55:53 +01:00
Markus
82160eab80 add in parameter manager functions 2019-10-26 16:27:46 +02:00
Markus
173bcc8d7e add new subfunction and function for removing dir / removing settings and cachedir 2019-10-26 16:18:47 +02:00
Markus
4cfdde076d v3.3.2 remove http error checking at gethtml function 2019-10-21 18:16:57 +02:00
Markus
6b0b8ade73 refix same error 2019-10-21 18:03:20 +02:00
Markus
5ab931c6db fix smal error 2019-10-21 18:01:19 +02:00
Markus
7db87488af error bug could not be fixed untill now 2019-10-17 19:47:19 +02:00
Markus
224153886e Merge branch 'master' of ssh://code.obermui.de:3232/markus/S_New4 2019-10-17 18:25:43 +02:00
Markus
7ae7f4ed83 v3.3.1: better VersionCheck 2019-10-17 18:10:13 +02:00
Markus
93e0106483 v3.3.0 2019-10-15 19:32:41 +02:00
Markus
4917d25fc9 überarbeitete update function ( mit löschen der dateien (bei windows nötig) und verschieben der exe datei (für windows nötig)) 2019-10-15 19:32:27 +02:00
Markus
42f66b673f v3.2.8: fix missing removing file before rename in windows 2019-10-14 19:49:53 +02:00
Markus
a9f80ec4d1 v3.2.7 2019-10-14 19:24:10 +02:00
Markus
b3d09524c6 add missing .exe at windows downloadLink 2019-10-14 19:23:03 +02:00
Markus
2dc779f080 füge 4 sversuche beim downloaden in datei hinzu; v2.5.6 2019-10-14 18:57:48 +02:00
Markus
6233d854c3 v3.2.5 2019-10-14 18:46:51 +02:00
Markus
9e2db246fd add printing info text from downloadet file && commits in functions 2019-10-14 18:34:14 +02:00
Markus
f9dce0a911 v3.2.3 2019-10-14 18:27:29 +02:00
Markus
298a4603c6 fix html error like 404; fix check version missing atoi 2019-10-14 18:27:14 +02:00
Markus
03332c66d6 überarbeite alles + überarbeitete infoausgabe + zu parametern als usb function hinzugefügt 2019-10-14 17:59:59 +02:00
Markus
f2f9a37a64 change getExePath to function + ... 2019-10-14 15:34:49 +02:00
Markus
2a76c4c10e change to diferned download urls 2019-10-14 15:16:15 +02:00
Markus
27b33bfad4 v3.2.0: add updater tests 2019-10-13 14:28:53 +02:00
Markus
0bda3b6c4c add download to file function for curl 2019-10-13 12:54:58 +02:00
Markus
b1d4aaee17 update readme 2019-10-11 15:43:53 +02:00
Markus
496849d41e updating reeadme... commit for testlokking on gitea 2019-10-11 15:37:26 +02:00
Markus
801139ac8f v3.1.1 fix in helpmenuüe file_path -> dirPath 2019-10-11 15:29:27 +02:00
Markus
44df19a633 update readme 2019-10-11 15:26:34 +02:00
Markus
98637e944d add windows libs_ 2019-10-11 15:25:30 +02:00
Markus
bb4d8b5e26 add windows libs 2019-10-11 15:24:14 +02:00
Markus
17a80f74f2 v3.1.0 add selection serie wehn invalid name at default and autosearch 2019-10-10 17:39:57 +02:00
Markus
ee46da07cb v3.0.6: fix error: overrite name in function select 1 serien && new look for debug messages 2019-10-08 20:10:12 +02:00
Markus
6a74f47102 add debug messages 2019-10-08 20:03:15 +02:00
Markus
f4918c5322 fix error: stop when season is finished, but doesn't wait for threads 2019-10-08 18:56:53 +02:00
Markus
b6fe7c8497 v3.0.4 2019-10-04 22:28:09 +02:00
Markus
7c7d87d898 fix error first update when file doesn't exists 2019-10-04 22:27:58 +02:00
Markus
3c2cc0af79 v3.0.3 2019-10-04 22:06:24 +02:00
Markus
cdf03e7d86 fix helpmenues and add hoster * ( for admins) 2019-10-04 21:29:37 +02:00
Markus
238f5181aa v3.0.2: update search helpmenüe && !! completly update Defaults file 2019-10-04 20:55:50 +02:00
Markus
192433cbb7 v3.0.1: can use search Name and -u && fix errors 2019-10-04 20:24:51 +02:00
Markus
43aff4b348 add update warn system => V3.0.0 2019-10-04 20:11:01 +02:00
Markus
61772afeb8 v2.9.0 add info new and deleted serien when update searchlist with colormode 2019-10-04 13:38:59 +02:00
Markus
1eed669a8f v2.8.3: list new serien wehean update at s -u 2019-10-02 22:13:15 +02:00
18 changed files with 2367 additions and 1124 deletions

106
Changelog.md Normal file
View File

@@ -0,0 +1,106 @@
## Changelog
### v3.6.2
* Füge ChangeLog Datei hinzu
### v3.6.1
* Extra ausgabe bei ungültigen Redirect Links, vorallem bei Unterfunktion url
* Verschiebe Source Dateien in den Order src/
### v3.6.0
* Deaktivireung des Proxy mit Port 0 nun möglich
### v3.5.6
* Bei Haupt Helpmenüe kann man nun -- weglassen bei --help
### v3.5.5
* Stoppe nun sofort, wenn checkName Function durch fehlerhaften HTML code fehlschlägt
### v3.5.4
* Größere Fehlerbehebungen
### v3.5.3
* Bei Serienauswahl wird nun auch der 2.te Name falls vorhanden angezeigt ( bei 1ner Möglichkeiten (1 Serien gefunden) )
### v3.5.2
* Bei Serienauswahl wird nun auch der 2.te Name falls vorhanden angezeigt ( bei mehren Möglichkeiten (verschiedenen Serien) )
### v3.5.1
* Serienliste: Seriensortierung: Genres -> Alphabet
### v3.5.0
* Neuer Parameter: -s bei der Unterfunktion info um Namenausgabe der einzelnen Folgen zu verhindern
### v3.4.6
* Behebe Fehler bei Serien mit HTML Sonderzeichen im Namen in der Serienliste
### v3.4.5
* Füge Farbausgabe bei der Unterfuktion info hinzu
### v3.4.4
* Erseze HTML Sonderzeichen mit Asci Zeichen in info Unterfunktion
* Verbessere Ausgabe bei der Unterfunktion info
### v3.4.3
* Behbe bei manchen Function: In Windows Pfadzeichen / -> \
* Behebe Fehler in Suchfunktion bei Serien mit einem / im Namen
### v3.4.2
* Füge Fehlernachricht bei --remove hinzu, wenn kein Ordner ausgewählt wurde
### v3.4.1
* Größere Fehlerbehebungen
* Füge Unterfunktion --remove dem Helpmenü hinzu
### v3.4.0
* Neue Unterfunktion: --remove
### v3.3.2
* Entferne vor kurzem hinzugefügtes überprüfen nach HTML Fehlern beim herunterladen der Internetseiten
### v3.3.1
* Verbesserung der Überprüfung der Versionen beim Updaten
### v3.3.0
* Überarbeitung der Unterfunkion --update
### v3.2.0
* Füge Update hinzu: Vorsicht fehlerhaft -> v3.2.0
* Füge Function zum Downloaden in Dateien
* Update Readme
### v3.1.1
* Behebe Pfade im Helpmenü
* Update Readme
* füge Windows Libraries hinzu
### v3.1.0
* Mann kan nun bei Ungültiger Serie 1ne Serie aus mehreren Möglichkeiten auswählen, falls vorhanden
### v3.0.6 / v3.0.5
* Behebe Überschreibung des Namens in der Serienauswahlfunktion
* Debug Nachrichten & Besseres Aussehen der Debug nachrichten
* Behebe Fehler: Programm stoppt wenn Staffel beendet ist, wartet aber nicht auf die Threads
### v3.0.4
* Behebe Fehler beim 1. mal Updaten der Serienliste, wenn die Datei noch nicht existiert
### v3.0.3
* Behebe Helpmenü fehler
* Füge Hoster * hinzu, aber nur mit Trick möglich, da dieser Vorgang unnötig viele Accounts braucht
### v3.0.2
* Aktualisiere Unterfuktion search's Helpmenü
* Aktualisiere Defaults-Datei (neue Bezeichnungen)
### v3.0.1
* Größere Fehlerbehebungen
* Nun möglich: Updaten der serienliste und Namesuche
### v3.0.0
* Füge Updatewarnsystem bei Serienliste hinzu
### Vorher
* -

View File

@@ -17,22 +17,46 @@ Aufruf: S_New4 [Unteroption] [PARAMETER]...
"search" Modus um Serien zu suchen.
"info" Modus um Infos einer Serien zu bekommen.
"clean" Modus um Cookie-Files zu löschen.
"news" Modus um neusten 75 Folgen auf s.to zu sehen.
### Verzeichnisse:
Ordner zum zwischenspeichern der Cookies und der AccountNummer:
> '/home/markus/.cache/S_New4/S_New4_cookies'
> '/home/*/.cache/S_New4/' - Linux
> '%LocalAppData%/S_New4' - Windows
Ordner zum speichern der Accounts und Default-Einstellungen:
> '/home/markus/.config/S_New4/Defaults'
> '/home/*/.config/S_New4/' - Linux
> '%AppData%/S_New4' - Windows
# Compilieren
### Linux:
##### Abhängigkeiten:
```sh
./autogen.sh
sudo apt install libcurl4-openssl-dev
```
### Windows:
#### g++
```sh
g++ --std=c++14 accountManager.cpp accountManager.h main.cpp pageManager.cpp pageManager.h parameterManager.cpp parameterManager.h programManager.cpp programManager.h -lcurl -lpthread -o S_New4
```
nutze den QT-Creator
#### QT-Style:
```sh
qmake && make
```
### Windows: (x86_64 Architekture)
##### Abhängigkeiten:
Empfohlen: Verwende S_New4 mit einem Unicode Compatiblem Terminal: Zum Beispiel mit dem
Git Bash Terminal
#### QT-Style: ( MinGW-64Bit )
Nutze den QT-Creator:
> In dem Unterordner curl/ befinden sich die benötigten Header- und Curl-Lib-Dateien für curl
> C++ und Winpthread Libs befinden sich in dem Ordner x86_64-WIN_LIBS/

View File

@@ -1,5 +0,0 @@
#!/bin/bash
g++ --std=c++14 accountManager.cpp accountManager.h main.cpp pageManager.cpp pageManager.h parameterManager.cpp parameterManager.h programManager.cpp programManager.h -lcurl -lpthread -o S_New4
sleep 3

0
curl/LIBCURL.DLL Executable file → Normal file
View File

View File

@@ -1,12 +0,0 @@
#include "programManager.h"
int main(int argc, char *argv[])
{
ProgramManager mainProgram;
Settings settings;
int res = manageParameter(settings, argc, argv);
if(res != 0)
return (res == -1) ? 0 : res;
return mainProgram.start(&settings);
}

View File

@@ -1,124 +0,0 @@
#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()
#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
};
struct Settings {
Settings() {}
Settings(std::string name) : name(name) {}
const std::string programName = "S_New4";
std::string name,
accountFilePath = "/tmp/a",
accountNumberPath= "/tmp/a_n",
cookieFilePath = "/tmp/S_New4_cookies",
serienListPath = "/tmp/SerienListe",
defaultsFilePath = "/tmp/defaults",
proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng",
genaueHoster = "",
version = "2.8.2",
defaultFileVersion="1.3",
outputFilePath = "",
default_checkPath = "",
default_Searchmuster = "S%Staffel%E%Folge%";
Modus modus = Modus::DEFAULT_MODUS;
bool colorless = false,
debugMode = false,
search_IgnoreUpperLower = true,
search_wantUpdate = false;
int startEpisode = 1,
stopEpisode = 0,
startSeason = 1,
stopSeason = 0,
proxy_port = 9050,
default_maxDirs = 20;
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);
int unterOption_help(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 setS5ProxytoSettings(Settings &settings, std::string optarg);
#endif // PARAMETERMANAGER_H

View File

@@ -1,893 +0,0 @@
#include "programManager.h"
ProgramManager::ProgramManager()
: nextThread(0)
{
}
ProgramManager::~ProgramManager()
{
for(auto e : threadList) {
delete e->pageManager;
delete e;
e = nullptr;
}
}
int ProgramManager::start(Settings *settings)
{
pageManager.setProxy(settings->proxy_ip, settings->proxy_port);
pageManager.setDebugMode(settings->debugMode);
pageManager.setCookieFilePath(settings->cookieFilePath);
if(dirExists(settings->cookieFilePath)) {
std::cout << " => Error: Kann Cokkie-File nicht erstellen: Es existiert bereits ein Ordner mit diesem Namen: \n '"
<< settings->cookieFilePath << "'." << std::endl;
return 174;
}
switch (settings->modus) {
case Modus::DEFAULT_MODUS:
return defaultModus(settings);
case Modus::DIRECT_LINK_MODUS:
return directLinkModus(settings);
case Modus::SEARCH_MODUS:
return searchModus(settings);
case Modus::INFO_MODUS:
return infoModus(settings);
case Modus::NEWS_MODUS:
return newsModus(settings);
default:
return -1;
}
}
void * threadFunction(void * data) {
ThreadData * myThreadData = reinterpret_cast<struct ThreadData*>(data);
myThreadData->returnValue="";
myThreadData->exitState=0;
Reply tmp_reply = myThreadData->pageManager->getServerRequest(myThreadData->pageManager->UrlPraefix + myThreadData->nameInUrl
+ "/staffel-" + std::to_string(myThreadData->staffel) + "/episode-" + std::to_string(myThreadData->folge));
if(tmp_reply.html == "-1")
return myThreadData->setState(10);
std::string allLinks = myThreadData->pageManager->getLinks(tmp_reply.html);
std::string Link = myThreadData->pageManager->chooseHosterLink(allLinks, myThreadData->settings->genaueHoster, myThreadData->settings->languages);
if(myThreadData->settings->debugMode)
std::cout << " > Thread " << myThreadData->id << allLinks << std::endl << ( (Link == "") ? "" : " -> Link: 'https://s.to") << Link << ( (Link == "") ? "" : "'\n" );
std::string folgenID = std::string((myThreadData->staffel == -1 || myThreadData->folge == -1 ) ? "" : "S" + std::string( (myThreadData->staffel < 10) ? "0" : "" ) + std::to_string(myThreadData->staffel)
+ "E" + std::string( (myThreadData->folge < 10) ? "0" : "" ) + std::to_string( myThreadData->folge ) );
std::string green = ((myThreadData->settings->colorless) ? "" : "\033[32m"),
red = ((myThreadData->settings->colorless) ? "" : "\033[31m"),
orange =((myThreadData->settings->colorless) ? "" : "\033[33m"),
blue = ((myThreadData->settings->colorless) ? "" : "\033[34m");
if(Link == "") {
if(allLinks == "") {
myThreadData->returnValue = " => " + red + "KEINEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m";
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("KEINEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
return myThreadData->setState(14);
}
else {
myThreadData->returnValue = " => " + orange + "Keinen PASSENDEN Hoster für die Folge " + folgenID + " gefunden." + "\033[0m" + "\n"
+ "Alle Links:" + "\n"
+ myThreadData->pageManager->replace( myThreadData->pageManager->replace( myThreadData->pageManager->replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
"data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\"");
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, std::string("Keinen PASSENDEN Hoster für die Folge ") + folgenID + std::string(" gefunden.")) != 0)
return myThreadData->setState(15);
}
return myThreadData->setState(0);
}
for (int i = 1; i <= 3; ++i) {
std::string newUrl = myThreadData->pageManager->getUrlAfterRedirect("https://s.to" + Link);
if (newUrl == "-1") {
return myThreadData->setState(16);
} else if(newUrl.find("/s.to/redirect/") != std::string::npos ) {
if(myThreadData->settings->debugMode)
std::cout << " > Thread " << myThreadData->id << "Warnung: Redirect Link nach umwandlung (Capcha?) --> Neuer Account" << std::endl;
if(myThreadData->pageManager->login(myThreadData->accountManager->getNextAccount()) != 0)
return myThreadData->setState(17);
continue;
} else {
myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + green + newUrl + "\033[0m";
if(myThreadData->settings->outputFilePath != "")
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0)
return myThreadData->setState(18);
return myThreadData->setState(0);
}
}
myThreadData->returnValue = " => " + folgenID + ( (folgenID == "") ? "" : ": " ) + red + "https://s.to" + Link + "\033[0m";
if(myThreadData->settings->outputFilePath != "")
if(myThreadData->pageManager->writeToFile(myThreadData->settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + Link) != 0)
return myThreadData->setState(19);
return myThreadData->setState(0);
}
int ProgramManager::waitForThreads()
{
for( auto &e : threadList) {
if( e->exitState != -1 && pthread_join(e->thread, nullptr) == 0) {
if(e->exitState != 0) {
std::cout << "\33[2K\r => Error: Thread gab error zurück." << std::endl;
return e->exitState;
} else
if(e->returnValue != "")
std::cout << ("\33[2K\r(T" + std::to_string(e->id) + ")" + e->returnValue ) << std::endl;
}
e->exitState = -1;
e->returnValue = "";
e->setData(0, 0);
e->thread = 0;
}
return 0;
}
int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName)
{
std::string finds;
if(searchModus(settings, &finds) != 0)
return 24;
else if(finds.find("/") == std::string::npos || finds.find("|") == std::string::npos || finds.find("\n") != std::string::npos)
return 45;
else if ( (finds = finds.substr( finds.find("/") + 1, finds.find("|", finds.find("/")) - finds.find("/") -1) ) == "" ) {
std::cout << " => Error: Konnte den Namen aus der zurückgegebenen Zeile nicht extrahieren." << std::endl;
return 46;
} else if ( (newName = pageManager.checkName(finds)) == "-1") {
std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl;
return 47;
}
std::cout << "Ist das deine gewünschte Serie? Drücke nur Enter um fortzufahren: " << std::flush;
std::getline(std::cin, finds);
if ( finds != "") {
std::cout << " => Abbruch..." << std::endl;
return 48;
}
return 0;
}
int ProgramManager::defaultModus(Settings *settings)
{
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
//Wenn kein Name mit -n Angegeben wurde:
if(settings->name == "") {
if(settings->default_checkPath != "") {
if(settings->default_checkPath[settings->default_checkPath.length()-1] == settings->pathSymbol)
settings->default_checkPath.pop_back();
size_t pos = settings->default_checkPath.find_last_of(std::string(1, settings->pathSymbol));
if( pos != std::string::npos) {
settings->name = settings->default_checkPath.substr(pos + 1);
if(settings->debugMode)
std::cout << " > Use Path from -C for Name: " << settings->default_checkPath << " -> " << settings->name << std::endl;
}
} if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << settings->programName << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " default --help\" liefert weitere Informationen." << std::endl;
return 27;
}
}
//Überprüfe ob ein Muster existiert:
if(settings->default_checkPath != "" && settings->default_Searchmuster == "") {
std::cout << " => Error: [-m]: Kein Muster angegeben." << std::endl;
return 31;
}
//Liste alle Dateien in dem Ornder von -C auf und speichere diese
std::string dirFiles;
if(settings->default_checkPath != "")
if(listDir(dirFiles, settings->default_checkPath, settings->default_maxDirs ) != 0)
return 28;
if(dirFiles.length() > 0) //Entferne von der liste das \n am ende
dirFiles.pop_back();
if(settings->debugMode && settings->default_checkPath != "") //Wenn Debug Mode, gib die Liste aus
std::cout << " > [-C] Files:\n" << dirFiles << std::endl;
//Führe Function aus, die überprüft ob die serie existiert
std::string nameInUrl =pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch && Wenn nur 1ne dacnn frag ob es diese ist.
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0)
return 202;
}
/* Wenn multihtreading seaktiviert ist, normal login sonst bereite threads vor
if(settings->maxThreads == 0) {
// melde bei s.to an und speicher cookies.
if (pageManager.login(accountManager.getNextAccount()) != 0) //----------------------------------------
return 29;
}*/
if(settings->maxThreads > 0) {
for (unsigned i = 0; i < settings->maxThreads; ++i) {
if(dirExists(settings->cookieFilePath + std::to_string( i ))) {
std::cout << " => Error: Kann Cokkie-File nicht erstellen: Es existiert bereits ein Ordner mit diesem Namen: \n '"
<< settings->cookieFilePath + std::to_string( i ) << "'." << std::endl;
return 174;
}
PageManager * pm = new PageManager(settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i ));
pm->setDebugMode(settings->debugMode);
//pm->setProxy(settings->proxy_ip, settings->proxy_port);
//pm->setCookieFilePath(settings->cookieFilePath + std::to_string( i ));
ThreadData * newThreadData = new ThreadData(i, 0, nameInUrl, -1, settings, &accountManager, pm);
threadList.push_back(newThreadData);
}
}
//Write Name to File if -o is set und kein TXT-FILE angegeben wird
if(settings->outputFilePath != "" && !fileExists( settings->default_checkPath ))
if(pageManager.writeToFile(settings->outputFilePath, "Name: " + settings->name) != 0)
return 31;
//Finde die anzahl der staffel heraus:
//download html von der startpage einer serie
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
return 32;
//speicher zahl -1, ab da wo /staffel-x nicht mehr vorkommt
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
if(settings->startSeason == 0)
settings->startSeason = maxStaffel;
for (int staffel = settings->startSeason; staffel <= maxStaffel; ++staffel) {
//Test for stopping Program caused -E, -S
if(staffel > settings->stopSeason && settings->stopSeason > 0) {
if(settings->debugMode)
std::cout << " > Stoppe, weil Staffel: " << staffel << " > StopStaffel " << settings->stopSeason << std::endl;
std::cout << " > Fertig, da Staffel " << staffel << " größer ist als StopStaffel " << settings->stopSeason << std::endl;
return 0;
}
//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) {
// stoppe wenn stopfolge größer der folge ist und stopstaffel nicht gesetzt wurde. und stopepisode gröser 0, also aktiv ist
if(folge > settings->stopEpisode && settings->stopSeason < 1 && settings->stopEpisode > 0) {
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
return 261;
std::cout << " > Fertig, da Folge " << folge << " größer ist als Stopfolge " << settings->stopEpisode << "."<< std::endl;
return 0;
} else if ( folge > settings->stopEpisode && staffel >= settings->stopSeason && settings->stopEpisode > 0) { // stoppe wenn stopfolge > folge && stopstaffel >= staffel und stopepisode gröser 0, also aktiv ist
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
return 267;
std::cout << " > Fertig, da Folge " << folge << " größer ist als Stopfolge " << settings->stopEpisode << std::endl
<< " und Staffel " << staffel << " größer gleich Stopstaffel " << settings->stopSeason << " ist." << std::endl;
return 0;
}
//Überprüfe ob, wenn -C vorhanden, die Folge in dem Ordner bereits vorkommt.
if(settings->default_checkPath != "") {
if(dirFiles.find(pageManager.replace( pageManager.replace( settings->default_Searchmuster, "%Staffel%", ((staffel < 10) ? "0" : "") + std::to_string(staffel) ),
"%Folge%", ((folge < 10) ? "0" : "") + std::to_string(folge) ) ) != std::string::npos) {
if(settings->debugMode)
std::cout << " > Skippe Folge: S" << staffel << "E" << folge << std::endl;
continue;
}
}
//Multihreading Mode
if(settings->maxThreads > 0) {
//Wenn nex Thread noch in den Vector passt(weniger Threads als Max), dann Starte neuen mit data aus dem Vector...
if(nextThread < threadList.size()) {
threadList[nextThread]->exitState = 0;
threadList[nextThread]->setData(staffel, folge);
if(pthread_create(&threadList[nextThread]->thread, nullptr, threadFunction, reinterpret_cast<void*>(threadList[nextThread])) != 0 ) {
perror("pthread_creat failed");
return 48;
}
++nextThread;
} else { // Sonnst warte bis alle Fertig sind und restarte die Folge
if(waitForThreads() != 0)
return 231;
nextThread=0;
folge--;
continue;
}
} else { // Default Mode
tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge));
if(tmp_reply.html == "-1")
return 50;
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 << ( (Link == "") ? "" : "'\n" );
if(convertLink(Link, &accountManager, settings, staffel, folge, allLinks) != 0)
return 51;
}
}
//Setzte Startepisode zurück für nächste Staffel
settings->startEpisode = 1;
}
if(settings->maxThreads != 0)
if(waitForThreads() != 0)
return 292;
std::cout << " > Fertig" << std::endl;
return 0;
}
int ProgramManager::directLinkModus(Settings *settings)
{
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
if(settings->name == "") {
std::cout << " => Error: Kein(e) Link(s) angegeben." << std::endl;
std::cout << "Aufruf: " << settings->programName << " url [OPTION]... [URL]..." << std::endl;
std::cout << "\"" << settings->programName << " url --help\" liefert weitere Informationen." << 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("/redirect/") == std::string::npos) {
std::cout << " => Error: Invalid Redirect Link: '" << line << "'" << std::endl;
continue;
} else if(convertLink(line.erase(0, ((line.find("s.to") == std::string::npos) ? 0 : line.find("s.to") + 4 )), &accountManager, settings) != 0)
return 78;
}
return 0;
}
int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
{
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 << " => Error: Das updaten der Serienliste ist fehlgeschlagen." << std::endl;
return res;
} else if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << settings->programName << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " search --help\" liefert weitere Informationen." << 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(" => Error: 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>());
//Suche alle Möglichkeiten
std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower);
serienListe.clear(); // Speicher freigeben
/*//Text mit Farben versehen
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");
}*/
if(saveTo) {
//Save List to Variable if set
*saveTo=finds;
}
//Text mit Farben versehen
if(!settings->colorless) {
std::string UpperFinds = pageManager.upper_string( finds );
std::string UpperName = pageManager.upper_string( settings->name );
for (size_t pos = UpperFinds.find( UpperName, 0); pos != std::string::npos; pos = UpperFinds.find( UpperName, pos + settings->name.length() + strlen("\033[37m\033[0m"))) {
bool exaktGeschrieben = (finds.find(settings->name, pos) == pos);
finds.insert(pos, ( (exaktGeschrieben) ? "\033[32m" : "\033[36m" ) ).insert(pos + settings->name.length() + strlen("\033[37m"), "\033[0m");
UpperFinds.insert(pos, ( (exaktGeschrieben ) ? "\033[32m" : "\033[36m" ) ).insert(pos + settings->name.length() + strlen("\033[37m"), "\033[0m");
}
}
//Ausgabe
if(finds == "") {
std::cout << " => Für '" << settings->name << "' wurde(n) keine Serie(n) gefunden." << std::endl;
return 0;
}
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::infoModus(Settings *settings)
{
if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
return 27;
}
//Führe Function aus, die überprüft ob die serie existiert
std::string nameInUrl = pageManager.checkName(settings->name);
if(nameInUrl == "-1") {
//Wenn nicht, dann fühe noch eine Suche nach ähnlichen durch.
if( sucheNach_1_Serien(settings, pageManager, nameInUrl) != 0)
return 28;
}
//Finde Anzahl der Staffel heraus:
Reply tmp_reply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl);
if(tmp_reply.html == "-1")
return 32;
//speicher (zahl -1), ab da wo /staffel-x nicht mehr vorkommt
int maxStaffel = pageManager.counterContains(tmp_reply.html, "/staffel-%i");
//Um namen der Folge für jede Staffel zu bekommen
for (int staffel = 1; staffel <= maxStaffel; ++staffel) {
Reply tmpReply = pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel));
if(tmpReply.html == "-1")
return 40;
std::cout << "Die Staffel " << staffel << " hat " << pageManager.counterContains(tmpReply.html, "/episode-%i") << " Folge(n)." << std::endl;
std::string html = tmpReply.html;
size_t pos = 0;
if( (pos = html.find("<tr ")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '<tr ' nicht finden." << std::endl;
return 41;
} else
html.erase(0, pos);
if( (pos = html.find("</tbody>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '</tbody>' nicht finden." << std::endl;
return 42;
} else
html.erase(pos, std::string::npos);
html = pageManager.replace(html, "\n", "");
html = pageManager.replace(html, "</tr>", "\n");
std::stringstream folgenListe(html);
std::string line;
while (std::getline(folgenListe, line).good()) {
std::string titel;
if( (pos = line.find("\"> Folge")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '\"> Folge' nicht finden." << std::endl;
return 43;
} else
line.erase(0, pos + 3);
if( (pos = line.find(" </a>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von ' </a>' nicht finden." << std::endl;
return 44;
}
std::cout << " Staffel " << staffel << " " << line.substr(0, pos) << ":" <<std::endl;
if( (pos = line.find("<strong>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '<strong>' nicht finden." << std::endl;
return 43;
} else
line.erase(0, pos + 8);
if( (pos = line.find("</strong>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '</strong>' nicht finden." << std::endl;
return 44;
}
titel = line.substr(0, pos);
if(titel != "")
std::cout << " > Titel1: " << titel << std::endl;
if( (pos = line.find("<span>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '<span>' nicht finden." << std::endl;
return 43;
} else
line.erase(0, pos + 6);
if( (pos = line.find("</span>")) == std::string::npos) {
std::cout << " => Error: Konnte Position von '</span>' nicht finden." << std::endl;
return 44;
}
titel = line.substr(0, pos);
if(titel != "")
std::cout << " > Titel2: " << titel << std::endl;
}
}
//Datum & FSK
std::string line = pageManager.grep(tmp_reply.html, "<small> (<span itemprop=\"startDate\"><a");
if(line == "") {
std::cout << " => Error: Konnte '<small> (<span itemprop=\"startDate\"><a' nicht finden." << std::endl;
return 83;
}
std::string startStopDates[2];
size_t pos = 0, pos2 = 0;
//Date
for (int i = 0; i < 2; ++i) {
if( (pos = line.find("href=")) == std::string::npos ) {
std::cout << " => Error: Konnte 'href=' nicht finden." << std::endl;
return 84;
} else
line.erase(0, pos + 5);
if( (pos = line.find(">")) == std::string::npos ) {
std::cout << " => Error: Konnte '>' nicht finden." << std::endl;
return 85;
} else if ((pos2 = line.find("</a>")) == std::string::npos ) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 86;
}
startStopDates[i] = line.substr(pos + 1, pos2 - pos -1);
}
//FSK
if( (pos = line.find("data-fsk=\"")) == std::string::npos ) {
std::cout << " => Error: Konnte 'data-fsk=\"' nicht finden." << std::endl;
return 87;
} else if ((pos2 = line.find("\" class=\"fsk")) == std::string::npos ) {
std::cout << " => Error: Konnte '\" class=\"fsk' nicht finden." << std::endl;
return 86;
}
std::string fsk = line.substr(pos + 10, pos2 -pos - 10);
//Deskription
if( (pos = tmp_reply.html.find("data-full-description=")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-full-description=' nicht finden." << std::endl;
return 83;
} else if ((pos2 = tmp_reply.html.find("\">", pos)) == std::string::npos ) {
std::cout << " => Error: Konnte '\">' nicht finden." << std::endl;
return 86;
}
std::string description = pageManager.replace( pageManager.replace( tmp_reply.html.substr(pos + 23, pos2 - pos - 23), "\n", "" ), "<br />", "" );
//Genres
std::vector<std::string> genres;
line = pageManager.grep(tmp_reply.html, "\"genre\">");
if(line == "") {
std::cout << " => Error: Konnte '\"genre\">' nicht finden." << std::endl;
return 87;
}
for (pos = line.find("\"genre\">"); pos != std::string::npos; pos = line.find("\"genre\">", pos + 7)) {
if( (pos2 = line.find("</a>", pos)) == std::string::npos) {
std::cout << " => Error: Konnte '</a>' nicht finden." << std::endl;
return 89;
}
genres.push_back(line.substr(pos + 8, pos2 - pos - 8));
}
//CoverLink
line = pageManager.grep(tmp_reply.html, "title=\"Cover");
if( (pos = line.find("data-src=\"")) == std::string::npos) {
std::cout << " => Error: Konnte 'data-src=\"' nicht finden." << std::endl;
return 90;
} else if ((pos2 = line.find("\"", pos + 10)) == std::string::npos ) {
std::cout << " => Error: Konnte '\"' nicht finden." << std::endl;
return 86;
}
std::string coverLink = line.substr(pos + 10, pos2 - pos -10);
std::cout << "Produktion von " << startStopDates[0] << " bis " << startStopDates[1] << std::endl
<< "FSK: " << fsk << std::endl
<< "Cover Bild: " << coverLink << std::endl
<< "Genre(s): " << std::flush;
for( const auto &e : genres)
std::cout << e << " ";
std::cout << std::endl << "\nBeschreibung: " << description << std::endl;
return 0;
}
int ProgramManager::newsModus(Settings *settings)
{
size_t pos = 0;
std::string html = pageManager.getServerRequest("https://s.to/neue-episoden").html;
if(html == "-1")
return 1;
if( (pos = html.find("<div class=\"row\">")) == std::string::npos ) {
std::cout << " => Error: Konnte Position von '<div class=\"row\">'' nicht finden" <<std::endl;
return 2;
} else
html.erase(0, pos + 17);
if( (pos = html.find("<div class=\"cf\"></div>")) == std::string::npos ) {
std::cout << " => Error: Konnte Position von '<div class=\"cf\"></div>' nicht finden" <<std::endl;
return 2;
} else
html.erase(pos + 12);
html = pageManager.replace(html, "\n", "");
html = pageManager.replace(html, "class=\"row\"", "\n");
std::stringstream strstream(html + "\n");
html.clear();
std::string line;
while (std::getline(strstream, line).good()) {
size_t pos = line.find("<strong>");
size_t pos2 = line.find("</strong>");
if(pos == std::string::npos) {
std::cout << " => Error: Konnte Position von '<strong>' nicht finden" <<std::endl;
return 3;
} else if(pos2 == std::string::npos) {
std::cout << " => Error: Konnte Position von '</strong>' nicht finden" <<std::endl;
return 4;
}
std::string name = line.substr(pos + 8, pos2 - pos - 8);
if( (pos = line.find("blue2\">")) == std::string::npos) {
std::cout << " => Error: Konnte Position von 'blue2\">' nicht finden" <<std::endl;
return 5;
} else if( (pos2 = line.find("</span>", pos)) == std::string::npos) {
std::cout << " => Error: Konnte Position von '' nicht finden" <<std::endl;
return 6;
}
std::string id = pageManager.replace( line.substr(pos + 7, pos2 - pos - 7), " ", "");
if( (pos = line.find("Right\">")) == std::string::npos) {
std::cout << " => Error: Konnte Position von 'Right\">' nicht finden" <<std::endl;
return 5;
} else if( (pos2 = line.find("</span>", pos)) == std::string::npos) {
std::cout << " => Error: Konnte Position von '</span>' nicht finden" <<std::endl;
return 6;
}
std::string date = line.substr(pos + 7, pos2 - pos - 7);
std::cout << " > " << ((settings->colorless) ? "" : "\033[97m") << date << ((settings->colorless) ? "" : "\033[0m") << ": "
<< ((settings->colorless) ? "" : "\033[96m") << name << ((settings->colorless) ? "" : "\033[0m") << ": "
<< ((settings->colorless) ? "" : "\033[92m") << id << ((settings->colorless) ? "" : "\033[0m") << std::endl;
}
return 0;
}
int ProgramManager::searchModus_update(Settings *settings)
{
Reply reply = pageManager.getServerRequest("https://s.to/serien");
if(reply.html == "-1")
return 21;
else if(reply.html.find("</html>") == std::string::npos ) {
std::cout << " => Error: Konnte </html> in searchModus_update() nicht finden." << std::endl;
return 22;
}
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/", "|/");
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";
}
if(serienListe.length() > 0)
serienListe.pop_back();
//Anzahl der Serien/Zeilen vorher:
ssize_t countBef = 0;
std::ifstream myFileBef(settings->serienListPath);
if(myFileBef.is_open())
for(countBef = 0; std::getline(myFileBef,line); ++countBef);
myFileBef.close();
//Schreibe die Liste in das TextFile
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();
//Anzahl der Zeile nachher
ssize_t countAf = 0;
std::ifstream myFileAf(settings->serienListPath);
if(myFileAf.is_open())
for(countAf = 0; std::getline(myFileAf,line); ++countAf);
myFileAf.close();
std::cout << "Serienunterschied: " << ( ((countAf - countBef) > 0) ? "+" : "") << countAf - countBef << " Serien." << std::endl;
return 0;
}
int ProgramManager::listDir(std::string &list,std::string path, int maxDepth)
{
//Wenn Pfad zu einem TextFile geht
if(fileExists(path)) {
std::ifstream ifs(path);
if(!ifs.is_open()) {
perror(" => Error: Konnte Textdatei nicht öffnen.");
return -1;
}
list = std::string((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
return 0;
} // Sonst normal Ordner listen
else if(maxDepth <= 0)
return 0;
else if(nothingExists(path)) {
std::cout << " => Warnug: Datei oder Verzeichnis existiert nicht: '" << path << "'" << std::endl;
return 0;
}
//verkleiner varibable um 1, um zu verhindern, das endlose schleife entsteht
maxDepth--;
if(path[path.length()-1] != '/')
path.push_back('/');
DIR* dirp = opendir(path.c_str());
if(!dirp) {
perror(std::string(" => Error: Konnte Verzeichnis nicht öffnen: " + path).c_str());
return -1;
}
struct dirent * dp;
while ((dp = readdir(dirp)) != nullptr) {
if(strcmp( dp->d_name, "." ) == 0 || strcmp ( dp->d_name, ".." ) == 0)
continue;
else if(dirExists((path + dp->d_name + "/"))) { //if(dp->d_type == DT_DIR) {
listDir(list, (path + dp->d_name + "/"), maxDepth);
} else
list.append( std::string(dp->d_name) + "\n" );
}
closedir(dirp);
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");
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
<< pageManager.replace( pageManager.replace( pageManager.replace( allLinks, "data-lang-key=\"1\"", "language=\"GerDub\"" ),
"data-lang-key=\"2\"", "language=\"Eng\"" ), "data-lang-key=\"3\"", "language=\"GerSub\"") << 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 << "Warnung: Redirect Link nach umwandlung (Capcha?) --> Neuer Account" << std::endl;
if(pageManager.login(accountManager->getNextAccount()) != 0)
return -1;
continue;
} else {
std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << green << newUrl << "\033[0m" << std::endl;
if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath,folgenID + ( (folgenID == "") ? "" : ": " ) + newUrl) != 0)
return 108;
return 0;
}
}
std::cout << " => " << folgenID << ( (folgenID == "") ? "" : ": " ) << red << "https://s.to" << redirectLink << "\033[0m" << std::endl;
if(settings->outputFilePath != "")
if(pageManager.writeToFile(settings->outputFilePath, folgenID + ( (folgenID == "") ? "" : ": " ) + redirectLink) != 0)
return 114;
return 0;
}

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

View File

@@ -13,7 +13,15 @@ PageManager::~PageManager()
void PageManager::setProxy(std::string ip, int port)
{
this->sock5Proxy = "socks5://" + ip + ":" + std::to_string(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)
@@ -26,6 +34,7 @@ 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
@@ -33,6 +42,13 @@ size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
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;
@@ -41,7 +57,8 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin
char *url;
std::string returnUrl;
std::cout << ( "\33[2K\rLade: '" + Url + "'..." ) << std::flush;
//info ausgabe
std::cout << ( "\33[2K\rLade: '" + Url + "'..." + ((debugMode) ? "\n" : "" )) << std::flush;
curl = curl_easy_init();
if(!curl) {
@@ -50,8 +67,14 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin
}
//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_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
@@ -98,6 +121,88 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin
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)
@@ -134,13 +239,13 @@ std::string PageManager::checkName(std::string 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;
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") {
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;
@@ -267,6 +372,80 @@ std::string PageManager::upper_string(const std::string &str)
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 == "")
@@ -294,8 +473,9 @@ std::string PageManager::chooseHosterLink(std::string HosterList, std::string Ho
//Für jede Sprache:
while (getline(SListLang, langId).good()) {
if ( langId == "GerDub" )
if(langId == "")
continue;
else if ( langId == "GerDub" )
LangId=1;
else if ( langId == "Eng" )
LangId=2;

View File

@@ -3,10 +3,12 @@
#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 {
@@ -29,6 +31,8 @@ public:
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);
@@ -39,6 +43,10 @@ public:
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);

View File

@@ -37,46 +37,55 @@ int setPaths(Settings &settings)
settings.cookieFilePath = CacheDir + "S_New4_cookies";
settings.accountNumberPath = CacheDir + "Account_Number";
settings.lastUpdateDateFilePath = CacheDir + "LastUpdateDate";
settings.accountFilePath = SettingsDir + "Accounts";
settings.serienListPath = SettingsDir + "SerienListe";
settings.defaultsFilePath = SettingsDir + "Defaults";
settings.cacheDir = CacheDir;
settings.configDir = SettingsDir;
return 0;
}
int manageParameter(Settings &settings, int argc, char **argv)
{
//Path settings
if(setPaths(settings) != 0)
if(setPaths(settings) != 0) {
if(settings.debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": setPaths f() failed." << std::endl;
return -1;
if(loadDefaulOptions(settings) != 0)
} else if(loadDefaulOptions(settings) != 0) {
if(settings.debugMode)
std::cerr << ">>> Debug In " << __FUNCTION__ << ": loadDefaulOptions f() failed." << std::endl;
return 28;
if(argc < 2) {
} else if(argc < 2) {
std::cout << " => Error: Keine Unteroption angegeben." << std::endl;
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
return 1;
}
std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews", argv[1]);
std::vector<std::string> res = compare("help\n--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update\n--remove", argv[1]);
if(res.size() != 1) {
if(res.size() == 0)
std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl;
else if(res.size() > 1) {
std::cout << " => Error: Mehrere Unteroptionen für '" << argv[1] << "' gefunden:" << std::endl;
for (auto &e : res)
std::cout << " > '" << argv[1] << "' =? " << e << std::endl;
std::cout << " > '" << argv[1] << "' ?= '" << e << "'" << std::endl;
}
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
return 2;
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
return 2;
}
res.clear();
if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
if((strncmp(argv[1], "--help", strlen(argv[1])) == 0) || (strncmp(argv[1], "help", strlen(argv[1])) == 0)) {
argv[1][0] = '\0';
return unterOption_help(settings);
@@ -89,17 +98,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
return unterOption_url(&settings, argc, argv);
} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
std::cout << "Programinfos:" << std::endl
<< " > Program Version: " << settings.version << std::endl
<< " > Defaults Datei Version: " << settings.defaultFileVersion << std::endl
<< " > C++ Standart: ";
if(__cplusplus == 1) std::cout << "C++_Pre_C++98" << std::endl;
else if (__cplusplus == 199711) std::cout << "C++98" << std::endl;
else if (__cplusplus == 201103) std::cout << "C++11" << std::endl;
else if (__cplusplus == 201402) std::cout << "C++14" << std::endl;
else if (__cplusplus == 201703) std::cout << "C++17" << std::endl;
else std::cout << "C++_Newer_C++17" << std::endl;
std::cout << " > " << sizeof (void *) * 8 << " Bit Version" << std::endl;
unterOption_printVersion(settings);
return -1;
} else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) {
@@ -119,12 +118,35 @@ int manageParameter(Settings &settings, int argc, char **argv)
argv[1][0] = '\0';
return unterOption_news(&settings, argc, argv);
} else if (strncmp(argv[1], "--update", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
return unterOption_update(&settings, argc, argv);
} else if (strncmp(argv[1], "--remove", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
return unterOption_RemoveSettings_or_CacheDir(&settings, argc, argv);
} else {
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
return 3;
}
}
void unterOption_printVersion(Settings &settings)
{
std::cout << "Programinfos:" << std::endl
<< " > Program Version: " << settings.version << std::endl
<< " > Defaults Datei Version: " << settings.defaultFileVersion << std::endl
<< " > C++ Standart: ";
if(__cplusplus == 1) std::cout << "C++_Pre_C++98" << std::endl;
else if (__cplusplus == 199711) std::cout << "C++98" << std::endl;
else if (__cplusplus == 201103) std::cout << "C++11" << std::endl;
else if (__cplusplus == 201402) std::cout << "C++14" << std::endl;
else if (__cplusplus == 201703) std::cout << "C++17" << std::endl;
else std::cout << "C++_Newer_C++17" << std::endl;
std::cout << " > " << sizeof (void *) * 8 << " Bit Version" << std::endl;
}
int loadDefaulOptions(Settings &settings)
{
std::fstream ifs(settings.defaultsFilePath);
@@ -135,22 +157,49 @@ int loadDefaulOptions(Settings &settings)
return 89;
} else {
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
ofs << "#Mit # kann man eine Zeile deaktivieren." << std::endl;
ofs << "DefaultFileVersion="<< settings.defaultFileVersion << std::endl;
ofs << "#DebugModus=false" << std::endl;
ofs << std::endl;
ofs << "#Socks5Proxy=127.0.0.1:9050" << std::endl;
ofs << "#FarbloseAusgabe=false" << std::endl;
ofs << "#OutputFile=/tmp/a" << std::endl;
ofs << std::endl;
ofs << "default-GenaueHoster=Vivo,GoUnlimited" << std::endl;
ofs << "#default-Sprachen=GerDub,GerSub,Eng" << std::endl;
ofs << "#default-CheckSuchMuster=S%Staffel%E%Folge%" << std::endl;
ofs << "#default-CheckMaxDirs=20" << std::endl;
ofs << "#default-maxThreads=0" << std::endl;
ofs << std::endl;
ofs << "#search-AchteAufGroßUndKleinschreibung=false" << std::endl;
ofs << "# -> Mit # kann man eine Zeile deaktivieren." << std::endl;
ofs << "DefaultFileVersion="<< settings.defaultFileVersion << std::endl << std::endl;
ofs << "#" << std::endl << "# -> Globale Einstellungen:" << std::endl << "#" << std::endl << std::endl;
ofs << "# -> Einstellung gleicht dem Parameter -d, --debug-mode:" << std::endl;
ofs << "#DebugModus=false" << std::endl << std::endl;
ofs << "# -> Einstellung gleicht dem Parameter -p, --socks5-proxy:" << std::endl;
ofs << "# Verwende den Port 0 um keinen Proxy zu verwenden." << std::endl;
ofs << "#Socks5Proxy=127.0.0.1:9050" << std::endl << std::endl;
ofs << "# -> Einstellung gleicht dem Parameter -c, --colorless:" << std::endl;
ofs << "#FarbloseAusgabe=false" << std::endl << std::endl;
ofs << "# -> Einstellung gleicht dem Parameter -o [Pfad], --output-file," << std::endl;
ofs << "# falls dieser in der ausgeführeten Unterfunktion vorhanden ist:" << std::endl;
ofs << "#OutputFile=/tmp/a" << std::endl << std::endl;
ofs << "#" << std::endl << "# -> Einstellungen für default Modus:" << std::endl << "#" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -g, --genaue-hoster:" << std::endl;
ofs << "default_GenaueHoster=Vivo,GoUnlimited" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -l, --languages:" << std::endl;
ofs << "#default_Sprachen=GerDub,GerSub,Eng" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -m, --check-muster:" << std::endl;
ofs << "#default_CheckSuchMuster=S%Staffel%E%Folge%" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -D, --check-max-dirs:" << std::endl;
ofs << "#default_CheckMaxDirs=20" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -t, --threads:" << std::endl;
ofs << "#default_maxThreads=0" << std::endl << std::endl;
ofs << "#" << std::endl << "# -> Einstellungen für search Modus:" << std::endl << "#" << std::endl << std::endl;
ofs << "# -> Standart Wert für Parameter: -e, --exactly-writing:" << std::endl;
ofs << "#search-AchteAufGroßUndKleinschreibung=false" << std::endl << std::endl;
ofs << "# -> Mit 0 Können Sie die Warnung deaktivieren:" << std::endl;
ofs << "#search-UpdateWarnungNachTagen=10" << std::endl << std::endl;
ofs.close();
}
@@ -169,8 +218,13 @@ int loadDefaulOptions(Settings &settings)
std::cout << " => Warnung: Bitte Info-Texte mit '#' am Anfang: Ungültige Option '" << line << "'." << std::endl;
continue;
}
std::string what = line.substr(0, line.find("=")), data = line.substr(line.find("=") + 1, line.length() - line.find("=") -1);
//extrahiere einstellung und wert aus Zeile:
std::string what = line.substr(0, line.find("=")),
data = line.substr(line.find("=") + 1, line.length() - line.find("=") -1);
if(what == "") {
continue;
} else if (what == "Socks5Proxy") {
if(setS5ProxytoSettings(settings, data) != 0)
@@ -192,32 +246,32 @@ int loadDefaulOptions(Settings &settings)
if(settings.debugMode)
std::cout << " > Defaults: DebugMode: true" << std::endl;
} else if (what == "default-GenaueHoster") {
} else if (what == "default_GenaueHoster") {
settings.genaueHoster=data;
if(settings.debugMode)
std::cout << " > Defaults: GenaueHoster: " << settings.genaueHoster << std::endl;
} else if (what == "default-Sprachen") {
} else if (what == "default_Sprachen") {
settings.languages=data;
if(settings.debugMode)
std::cout << " > Defaults: Sprachen: " << settings.languages << std::endl;
} else if (what == "default-CheckSuchMuster") {
} else if (what == "default_CheckSuchMuster") {
settings.default_Searchmuster=data;
if(settings.debugMode)
std::cout << " > Defaults: SuchMuster: " << settings.default_Searchmuster << std::endl;
} else if (what == "default-CheckMaxDirs") {
} else if (what == "default_CheckMaxDirs") {
settings.default_maxDirs = atoi(data.c_str());
if(!isNumber(data) ) {
std::cout << " => Error_Defaults: default-CheckMaxDirs: Ungültige Zahl: " << data << std::endl;
std::cout << " => Error_Defaults: default_CheckMaxDirs: Ungültige Zahl: " << data << std::endl;
return 18;
}
if(settings.debugMode)
std::cout << " > Defaults: default-CheckMaxDirs: " << settings.default_maxDirs << std::endl;
std::cout << " > Defaults: default_CheckMaxDirs: " << settings.default_maxDirs << std::endl;
} else if (what == "default-maxThreads") {
} else if (what == "default_maxThreads") {
settings.maxThreads = static_cast<unsigned>(atoi(data.c_str()));
if(!isNumber(data) ) {
std::cout << " => Error_Defaults: Thread-Max Ungültige Zahl: " << data << std::endl;
@@ -258,7 +312,15 @@ int loadDefaulOptions(Settings &settings)
if(settings.debugMode)
std::cout << " > Defaults: OutputFile: " << settings.outputFilePath << std::endl;
} else if (what == "") {
} else if (what == "search-UpdateWarnungNachTagen") {
if(!isNumber(data)) {
std::cout << " Error_Defaults: search-UpdateWarnungNachTagen: Wert ist keine Zahl." << std::endl;
return 228;
} else {
settings.updateWarningDays = atoi(data.c_str());
}
if(settings.debugMode)
std::cout << " > Defaults: search-UpdateWarnungNachTagen: " << settings.updateWarningDays << std::endl;
} else if (what == "") {
@@ -288,6 +350,11 @@ int unterOption_help(Settings &settings)
std::cout << "Unteroptionen:" << std::endl
<< "\t\"--help\"\tGibt dieses Helpmenue aus." << std::endl
<< "\t\"--version\"\tGibt die Version des Programmes aus." << std::endl
<< "\t\"--update\"\tModus um das Programm zu aktualisieren." << std::endl
<< "\t \tUpdater funktioniert nur bei: Windows/Linux -" << std::endl
<< "\t \tx86 Architekutur - 64 Bit Systemen." << std::endl
<< "\t\"--remove\"\tModus um Ordner mit Einstellungen/" << std::endl
<< "\t \tZwischengespeicherte-Dateien zu löschen." << 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\"search\"\tModus um Serien zu suchen." << std::endl
@@ -297,10 +364,12 @@ int unterOption_help(Settings &settings)
<< std::endl;
std::cout << "Verzeichnisse:" << std::endl
<< "\tOrdner zum zwischenspeichern der Cookies und der AccountNummer:" << std::endl
<< "\t > '" << settings.cookieFilePath << "'" << std::endl
<< "\tOrdner zum speichern der Accounts und Default-Einstellungen:" << std::endl
<< "\t > '" << settings.defaultsFilePath << "'" << std::endl;
<< "\tOrdner zum zwischenspeichern der Cookies, AccountNummer" << std::endl
<< "\tund des letzten Update Datums:" << std::endl
<< " => > '" << std::string(settings.cookieFilePath).erase(settings.cookieFilePath.find_last_of(settings.pathSymbol) + 1) << "'" << std::endl
<< "\tOrdner zum speichern der Accounts, Default-Einstellungen" << std::endl
<< "\tund der Serienliste:" << std::endl
<< " => > '" << std::string(settings.defaultsFilePath).erase(settings.defaultsFilePath.find_last_of(settings.pathSymbol) + 1) << "'" << std::endl;
return -1;
}
@@ -339,7 +408,7 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
while( ( c = getopt_long (argc, argv, "p:g:l:o:e:E:s:S:C:m:D:t:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'g':
@@ -542,7 +611,7 @@ void unterOption_default_help(std::string programName)
<< "SOCK5PROXY:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
<< " Standart: 127.0.0.1:9050 - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< "AUSGABEOPTIONEN:" << std::endl
<< " -o [Pfad], --output-file [Pfad]" << std::endl
<< " Mit diere Option kann man ein (nichtvorhandenes) Text-Datei" << std::endl
@@ -617,7 +686,7 @@ int unterOption_url(Settings *settings, int argc, char **argv)
while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'o':
@@ -670,16 +739,16 @@ void unterOption_url_help(std::string programName)
std::cout << "Aufruf: " << programName << " url [OPTION]... [URL]..." << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunction von " << programName << " können eigene" << std::endl
<< " Mit dieser Unterfunktion von " << programName << " können eigene" << std::endl
<< " Redirect-Links umgewandelt werden. Beispiel:" << std::endl
<< " https://s.to/redirect/4449825 -> http://vivo.sx/d20b111ade" << std::endl
<< " Achtung: Achte, dass Url mit https:// nicht mit http:// beginnt." << std::endl
<< " https://s.to/redirect/44498xy -> https://vivolvox.xy/123xy" << std::endl
<< " Der Link kann folgen Aussehen: {[*]s.to}/redirect/[*]." << std::endl
<< " Standartwerte können im Defaultfile geändert werden." << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
<< " Standart: 127.0.0.1:9050 - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< " -o [Pfad], --output-file [Pfad]" << std::endl
<< " Mit diere Option kann man ein (nichtvorhandenes) Text-Datei angeben," << std::endl
<< " inwelches die umgewandelten Redirect-Links geschrieben werden." << std::endl << std::endl
@@ -714,7 +783,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
while( ( c = getopt_long (argc, argv, "p:hcdeu", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'h':
@@ -767,26 +836,31 @@ int unterOption_search(Settings *settings, int argc, char **argv)
void unterOption_search_help(std::string programName)
{
std::cout << "Aufruf: " << programName << " search [OPTION]... [NAME]" << std::endl
<< " " << programName << " search [-u, --update] [OPTION]... [NAME]" << std::endl
<< " " << programName << " search [-u, --update]" << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunction des Programms kann man Serien auf s.to suchen." << std::endl
<< " Mit dieser Unterfunktion des Programms kann man Serien auf s.to suchen." << std::endl
<< " Tipp: Falls deine Serie nicht gefunden wird, entferne einen Teil" << std::endl
<< " am Ende deines SuchNamens und wiederhole die Suche." << std::endl
<< " Tipp: Wenn deine Serie sehr neu auf s.to ist, und deshalb nicht gefunden" << std::endl
<< " wird, verwende die Option -u, um die Liste zu aktualisieren." << std::endl << std::endl;
std::cout << "AKTUALISIERUNG:" << std::endl
<< " -u, --update" << std::endl
<< " Mit dieser Option wird die Liste der Serien, die bei der Suche durchsucht " << std::endl
<< " wird, aktualisiert." << std::endl << std::endl;
<< " Mit dieser Option wird die Liste der Serien, die bei der" << std::endl
<< " Suche durchsucht wird, aktualisiert." << std::endl << std::endl;
std::cout << "AKTUALISIERUNGSWARNUNG:" << std::endl
<< " In der Defaults Datei findest du die Einstellung" << std::endl
<< " 'search-UpdateWarnungNachTagen' mit der du festlegen kannst," << std::endl
<< " nach wie vielen Tagen du an das Updaten erinert wirst." << std::endl
<< " Default: 10 Tage." << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
<< " Standart: 127.0.0.1:9050 - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< " -e, --exactly-writing" << std::endl
<< " Mit dieser Option achtet das Programm auf Groß- und Kleinschreibung." << std::endl << std::endl
<< " -c, --colorless" << std::endl
@@ -810,15 +884,16 @@ int unterOption_info(Settings *settings, int argc, char **argv)
{"help", no_argument, nullptr, 'h'},
{"colorless", no_argument, nullptr, 'c'},
{"debug-mode", no_argument, nullptr, 'd'},
{"skip-episoden-names", no_argument, nullptr, 's'},
{nullptr, no_argument, nullptr, 0}
};
while( ( c = getopt_long (argc, argv, "p:hcd", long_opts, nullptr) ) != -1 ) {
while( ( c = getopt_long (argc, argv, "p:hcds", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'h':
@@ -834,6 +909,11 @@ int unterOption_info(Settings *settings, int argc, char **argv)
if(settings->debugMode)
std::cout << "Debug Modus: true" << std::endl;
break;
case 's':
settings->skipEpisodenNameOutput = true;
if(settings->debugMode)
std::cout << "skipEpisodenNameOutput: true" << std::endl;
break;
default:
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
@@ -852,7 +932,7 @@ int unterOption_info(Settings *settings, int argc, char **argv)
settings->name.pop_back();
if(settings->debugMode) {
std::cout << "Name: " << settings->name << std::endl;
std::cout << "Modus: Search_MODUS" << std::endl;
std::cout << "Modus: IndosModus" << std::endl;
}
return 0;
@@ -868,12 +948,15 @@ void unterOption_info_help(std::string programName)
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
<< " Standart: 127.0.0.1:9050 - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< " -c, --colorless" << std::endl
<< " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl
<< " -d, --debug-mode" << std::endl
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
<< " -s, --skip-episoden-names" << std::endl
<< " Mit dieser Option kann man die Ausgabe der Namen der" << std::endl
<< " einzelnen Folgen ausschalten." << std::endl << std::endl
<< " -h, --help" << std::endl
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
}
@@ -884,7 +967,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
if(argc > 2)
if(strncmp("--help", argv[2], strlen(argv[2])) == 0) {
std::cout << "Aufruf: " << settings->programName << " clean\n " << settings->programName << " clean --help" << std::endl << std::endl
<< "Beschreibung:" << std::endl << " Mit dieser Unterfunction kann man die Cookie-Dateien löschen." << std::endl << std::endl;
<< "Beschreibung:" << std::endl << " Mit dieser Unterfunktion kann man die Cookie-Dateien löschen." << std::endl << std::endl;
return;
}
@@ -968,7 +1051,7 @@ int setS5ProxytoSettings(Settings &settings, std::string Optarg)
if(optarg.find("localhost") != std::string::npos)
optarg.insert(optarg.find("localhost"), "127.0.0.1").erase(optarg.find("localhost"), 9);
//Wenn optarg keine vollständige Addresse ( ip:port ) ist:
//Wenn optarg keine vollständige Addresse ( ip:port ) ist: ip || port
if(optarg.find(":") == std::string::npos) {
//Wenn optarg eine Zahl ist, also Port:
if(isNumber(optarg)) {
@@ -1083,7 +1166,7 @@ int unterOption_news(Settings *settings, int argc, char **argv)
while( ( c = getopt_long (argc, argv, "p:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'h':
@@ -1100,14 +1183,14 @@ int unterOption_news(Settings *settings, int argc, char **argv)
std::cout << "Debug Modus: true" << std::endl;
break;
default:
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " news [OPTION]..." << std::endl;
std::cout << "\"" << settings->programName << " news --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
if(settings->debugMode)
std::cout << "Modus: Search_MODUS" << std::endl;
std::cout << "Modus: NewsModus" << std::endl;
return 0;
}
@@ -1118,12 +1201,12 @@ void unterOption_news_help(std::string programName)
std::cout << "Aufruf: " << programName << " news [OPTION]..." << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man die neuesten Folgen auf s.to sehen." << std::endl << std::endl;
<< " Mit dieser Unterfunktion kann man die neuesten 75 Folgen auf s.to sehen." << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
<< " Standart: 127.0.0.1:9050 - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< " -c, --colorless" << std::endl
<< " Mit dieser Option kann man die farbige Ausgabe ausstellen." << std::endl << std::endl
<< " -d, --debug-mode" << std::endl
@@ -1132,3 +1215,204 @@ void unterOption_news_help(std::string programName)
<< " -h, --help" << std::endl
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
}
int unterOption_update(Settings *settings, int argc, char **argv)
{
settings->modus = Modus::UPDATE_MODUS;
//deaktiviere Proxy als Standert
settings->proxy_port = 0;
int c = 0;
const option long_opts[] = {
{"socks5-proxy", required_argument, nullptr, 'p'},
{"help", no_argument, nullptr, 'h'},
{"debug-mode", no_argument, nullptr, 'd'},
{nullptr, no_argument, nullptr, 0}
};
while( ( c = getopt_long (argc, argv, "p:hd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'p':
if(!optarg || setS5ProxytoSettings(*settings, optarg) != 0)
return 2;
break;
case 'h':
unterOption_update_help(settings->programName);
return -1;
case 'd':
settings->debugMode = true;
if(settings->debugMode)
std::cout << "Debug Modus: true" << std::endl;
break;
default:
std::cout << "Aufruf: " << settings->programName << " --update [OPTION]..." << std::endl;
std::cout << "\"" << settings->programName << " --update --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
if(settings->debugMode)
std::cout << "Modus: UpdateModus" << std::endl;
return 0;
}
void unterOption_update_help(std::string programName)
{
std::cout << "Aufruf: " << programName << " --update [OPTION]..." << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man das Programm updaten." << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
<< " Standart: 'Port 0' - Port 0 um Proxy zu deaktivieren." << std::endl << std::endl
<< " -d, --debug-mode" << std::endl
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
<< " -h, --help" << std::endl
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
}
bool removeDirIsOk(std::string path, Settings *settings)
{
if(path == "") {
std::cout << " => Error: Ungültiger Pfad: '" << path << "'." << std::endl;
return false;
} else if(path.back() != settings->pathSymbol )
path.push_back(settings->pathSymbol);
if(settings->askForEveryDir) {
std::cout << "Zur Bestätigung des Löschens des Ordners: '" << path << "'," << std::endl
<< "geben sie 'OK' ein: " << std::flush;
std::string input;
std::getline(std::cin, input);
if(input != "OK") {
std::cout << "Abbruch..." << std::endl;
return false;
}
}
DIR* dirp = nullptr;
if( (dirp = opendir( path.c_str() )) == nullptr ) {
perror(std::string(" => Error: Konnte Verzeichnis nicht öffnen: '" + path + "'").c_str());
return false;
}
struct dirent * dp;
while ((dp = readdir(dirp)) != nullptr) {
if(strcmp( dp->d_name, "." ) == 0 || strcmp ( dp->d_name, ".." ) == 0)
continue;
else if(dirExists((path + dp->d_name + settings->pathSymbol ))) { //if(dp->d_type == DT_DIR) {
if( ! removeDirIsOk(path + dp->d_name + settings->pathSymbol , settings)) {
if(settings->debugMode)
std::cout << " => Error im Unterordner: '" << path + dp->d_name << "'" << std::endl;
return false;
}
} else if(fileExists( path + dp->d_name )) {
if(remove((path + dp->d_name).c_str()) != 0) {
perror((" => Error: Das Löschen von '" + path + dp->d_name + "' ist fehlgeschlagen").c_str());
return false;
} else {
if(settings->debugMode)
std::cout << " => DEBUG: Erfolgreich '" << path + dp->d_name << "' gelöscht." << std::endl;
}
} else {
std::cout << " => Error: '" << path << dp->d_name << "'ist keine Datei oder Ordner." << std::endl;
return false;
}
}
closedir(dirp);
if(rmdir(path.c_str()) != 0) {
perror((" => Das löschen des Ordners '" + path + "' ist fehlgeschlagen.").c_str());
return false;
} else if (settings->debugMode)
std::cout << " => DEBUG: Ordner '" << path << "' erfolgreich gelöscht." << std::endl;
return true;
}
int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char **argv)
{
settings->modus = Modus::REMOVE_SETTINGS_AND_CACHE_MODUS;
int c = 0;
const option long_opts[] = {
{"help", no_argument, nullptr, 'h'},
{"debug-mode", no_argument, nullptr, 'd'},
{nullptr, no_argument, nullptr, 0}
};
while( ( c = getopt_long (argc, argv, "hd", long_opts, nullptr) ) != -1 ) {
switch(c) {
case 'h':
unterOption_RemoveSettings_or_CacheDire_help(settings->programName);
return -1;
case 'd':
settings->debugMode = true;
if(settings->debugMode)
std::cout << "Debug Modus: true" << std::endl;
break;
default:
std::cout << "Aufruf: " << settings->programName << " --remove [OPTION]... [settings|cache|all]" << std::endl;
std::cout << "\"" << settings->programName << " --remove --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
//Alle nicht verwendeten Parameter == Name
while (optind < argc) {
if(argv[optind][0]) {
settings->name.append(argv[optind++]).append(" ");
} else
++optind;
}
if(settings->name.length() > 0)
settings->name.pop_back();
else {
std::cout << " => Error: Keinen Ordner angegeben." << std::endl;
std::cout << "Aufruf: " << settings->programName << " --remove [OPTION]... [settings|cache|all]" << std::endl;
std::cout << "\"" << settings->programName << " --remove --help\" liefert weitere Informationen." << std::endl;
return 22;
}
if(settings->debugMode)
std::cout << "Modus: RemoveModus" << std::endl;
return 0;
}
void unterOption_RemoveSettings_or_CacheDire_help(std::string programName)
{
std::cout << "Aufruf: " << programName << " --remove [OPTION]... [settings|cache|all]" << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man die erstellten Settings/Cache" << std::endl
<< " Ordner löschen." << std::endl
<< " 'settings': Nur den Ordner mit den Einstellungen löschen." << std::endl
<< " 'cache': Nur den Ordner mit den Zwischengespeicherten Dateien löschen." << std::endl
<< " 'all': Beide Ordner löschen." << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -d, --debug-mode" << std::endl
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
<< " -h, --help" << std::endl
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
}

168
src/parameterManager.h Normal file
View File

@@ -0,0 +1,168 @@
#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";
// Wenn das Betriebsystem x86 ist:
#if defined (_X86_) || defined (__amd64__) || defined (_M_IX86)
// Wenn das Betriebsystem LINUX ist und 64 Bit ist:
#if defined (__linux) && ( defined (_LP64) || defined (__LP64__))
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";
#else
//Wenn das Betriebsystem Windows ist und 64 Bit ist
#if defined (_WIN64)
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";
#else
//Ungültiges Betriebsystem => Error
#error Kein Windows oder Linux 64 Bit System: Der Updater Fuktion wird nicht Funktionieren! Remove this Line in the Code to use S_New4 without the Updater. ( But your System must be Windows or Linux )
const std::string VersionFileUrl = "";
const std::string ProgrammFileUrl = "";
#endif
#endif
//Nicht x86 Architekture
#else
#error Falsche Architektur: Der Updater Fuktion wird nicht Funktionieren! Remove this Line in the Code to use S_New4 without the Updater. ( But your System must be Windows or Linux )
const std::string VersionFileUrl = "";
const std::string ProgrammFileUrl = "";
#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.3",
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

1486
src/programManager.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,6 @@
#include "accountManager.h"
#include <sys/types.h>
#include <dirent.h>
#include <pthread.h>
@@ -44,9 +43,12 @@ public:
private:
int defaultModus(Settings * settings);
int directLinkModus(Settings * settings);
int searchModus(Settings * settings, std::string *saveTo = nullptr);
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;
@@ -56,6 +58,7 @@ private:
int searchModus_update(Settings * settings);
int waitForThreads();
int sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName);
int checkLastUpdate(Settings * settings);
};

View File

@@ -0,0 +1 @@
../curl/