add option -C, -m, -t at default modus

This commit is contained in:
Markus 2019-08-03 21:48:27 +02:00
parent 3891dd5a1d
commit 1c16ddeb97
4 changed files with 157 additions and 56 deletions

View File

@ -89,8 +89,7 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"name", required_argument, nullptr, 'n'}, {"name", required_argument, nullptr, 'n'},
{"ip-addresse", required_argument, nullptr, 'i'}, {"socks5-proxy", required_argument, nullptr, 'p'},
{"port", required_argument, nullptr, 'p'},
{"genauer-hoster", required_argument, nullptr, 'g'}, {"genauer-hoster", required_argument, nullptr, 'g'},
{"languages", required_argument, nullptr, 'l'}, {"languages", required_argument, nullptr, 'l'},
{"output-file", required_argument, nullptr, 'o'}, {"output-file", required_argument, nullptr, 'o'},
@ -100,6 +99,10 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
{"start-season", required_argument, nullptr, 's'}, {"start-season", required_argument, nullptr, 's'},
{"stop-season", required_argument, nullptr, 'S'}, {"stop-season", required_argument, nullptr, 'S'},


{"check-dir", required_argument, nullptr, 'C'},
{"check-muster", required_argument, nullptr, 'm'},
{"check-max-dirs", required_argument, nullptr, 't'},



{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"colorless", no_argument, nullptr, 'c'}, {"colorless", no_argument, nullptr, 'c'},
@ -109,7 +112,7 @@ int unterOption_default(Settings *settings, int argc, char ** argv)


}; };


while( ( c = getopt_long (argc, argv, "n:i:p:g:l:o:e:E:s:S:hcd", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "n:p:g:l:o:e:E:s:S:C:m:t:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'n': case 'n':
if(optarg) if(optarg)
@ -117,20 +120,29 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
if(settings->debugMode) if(settings->debugMode)
std::cout << "Name: " << settings->name << std::endl; std::cout << "Name: " << settings->name << std::endl;
break; break;
case 'i': case 'p': {
if(optarg) if(!optarg || std::string(optarg) == "")
settings->proxy_ip = optarg; break;
if(settings->debugMode) std::string optarg = ::optarg;
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl; if(optarg.find(":") == std::string::npos) {
break; std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
case 'p': return 31;
if(optarg) }
settings->proxy_port = atoi( optarg ) ; std::string ip = optarg.substr(0, optarg.find(":"));
if(std::to_string(settings->proxy_port) != optarg) { std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
std::cout << "Invalid Port: " << optarg << std::endl; int port = atoi(portStr.c_str());
return 10; if(std::to_string(port) != portStr || port <= 0) {
} else if(settings->debugMode) std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
std::cout << "Proxy Port: " << settings->proxy_port << std::endl; return 32;
} else if (ip == "") {
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
return 34;
} else if(settings->debugMode) {
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
}
settings->proxy_ip = ip;
settings->proxy_port = port;
}
break; break;
case 'g': case 'g':
if(optarg) if(optarg)
@ -151,7 +163,6 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl;
break; break;



case 'e': case 'e':
if(!optarg) if(!optarg)
break; break;
@ -205,7 +216,31 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
} else if(settings->debugMode) } else if(settings->debugMode)
std::cout << "StopSeason: " << settings->stopSeason << std::endl; std::cout << "StopSeason: " << settings->stopSeason << std::endl;
break; break;
case 'm':
if(optarg)
settings->default_Searchmuster = optarg;
if(settings->debugMode)
std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl;
break;
case 't':
if(!optarg)
break;
settings->default_maxDirs = atoi(optarg);
if(std::to_string(settings->default_maxDirs) != std::string(optarg) ) {
std::cout << "[-t]: Invalid Count: " << optarg << std::endl;
return 18;
}
if(settings->debugMode)
std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl;


break;
case 'C':
if(!optarg)
break;
settings->default_checkDirPath = optarg;
if(settings->debugMode)
std::cout << "To check Dir: " << settings->default_checkDirPath << std::endl;
break;
case 'c': case 'c':
settings->colorless = true; settings->colorless = true;
if(settings->debugMode) if(settings->debugMode)
@ -245,10 +280,8 @@ void unterOption_default_help(Settings *, char * argv0)
<< "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl << "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl
<< std::endl << std::endl
<< " > Proxy-Optionen:" << std::endl << " > Proxy-Optionen:" << std::endl
<< "\t-i [ProxyIPAddresse], --ip-addresse [ProxyIPAddresse]" << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl
<< "\t -> Ip Addresse eines Socks5-Proxys angeben. Default: 127.0.0.1" << std::endl << "\t -> Ip Addresse eines Socks5-Proxys angeben. Default: 127.0.0.1:9050" << std::endl
<< "\t-p [ProxyPort], --port [ProxyPort]" << std::endl
<< "\t -> Port eines Socks5-Proxy angeben. Default: 9050" << std::endl
<< std::endl << std::endl
<< " > Outputoptionen:" << std::endl << " > Outputoptionen:" << std::endl
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl
@ -258,6 +291,17 @@ void unterOption_default_help(Settings *, char * argv0)
<< "\t-d, --debug-mode" << std::endl << "\t-d, --debug-mode" << std::endl
<< "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl
<< std::endl << std::endl
<< " > Check-Dir Optionen:" << std::endl
<< "\t-C [Pfad], --check-dir [Pfad]" << std::endl
<< "\t -> Überprüfe ob in diesem, oder in einen der Unterordnern die Folge vorkommt." << std::endl
<< "\t -> Wenn ja, dann überspringe diese." << std::endl
<< "\t-m, --check-muster" << std::endl
<< "\t -> Muster mit dem Überprüft wird, ob diese Folge in einem Ordner ist. Default: S%Staffel%E%Folge%" << std::endl
<< "\t -> %Staffel% ist eine Variable für die Staffel mit 0 + Staffel, wenn Staffel < 10. " << std::endl
<< "\t -> %Folge% ist eine Variable für die Folge mit 0 + Folge, wenn Folge < 10. " << std::endl
<< "\t-t, --check-max-dirs" << std::endl
<< "\t -> Maximale Anzahl der Ordner, die auf Dateien untersucht werden. Default: 20" << std::endl
<< std::endl
<< " > Durchlaufoptionen:" << std::endl << " > Durchlaufoptionen:" << std::endl
<< "\t-e [Folge], --start-episode [Folge]" << std::endl << "\t-e [Folge], --start-episode [Folge]" << std::endl
<< "\t -> Das Programm startet mit dieser Folge." << std::endl << "\t -> Das Programm startet mit dieser Folge." << std::endl
@ -287,8 +331,7 @@ int unterOption_url(Settings *settings, int argc, char **argv)
int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"url", required_argument, nullptr, 'u'}, {"url", required_argument, nullptr, 'u'},
{"ip-addresse", required_argument, nullptr, 'i'}, {"socks5-proxy", required_argument, nullptr, 'p'},
{"port", required_argument, nullptr, 'p'},
{"output-file", required_argument, nullptr, 'o'}, {"output-file", required_argument, nullptr, 'o'},


{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
@ -299,7 +342,7 @@ int unterOption_url(Settings *settings, int argc, char **argv)


}; };


while( ( c = getopt_long (argc, argv, "u:i:p:o:hcd", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "u:p:o:hcd", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'u': case 'u':
if(optarg) if(optarg)
@ -308,21 +351,29 @@ int unterOption_url(Settings *settings, int argc, char **argv)
std::cout << "Urls: " << settings->name << std::endl; std::cout << "Urls: " << settings->name << std::endl;
break; break;


case 'i': case 'p': {
if(optarg) if(!optarg || std::string(optarg) == "")
settings->proxy_ip = optarg; break;
if(settings->debugMode) std::string optarg = ::optarg;
std::cout << "Proxy Ip Addresse: " << settings->proxy_ip << std::endl; if(optarg.find(":") == std::string::npos) {
break; std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
case 'p': return 31;
if(optarg) }
settings->proxy_port = atoi( optarg ); std::string ip = optarg.substr(0, optarg.find(":"));
if(std::to_string(settings->proxy_port) != optarg) { std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
std::cout << "Invalid Port: " << optarg << std::endl; int port = atoi(portStr.c_str());
return 20; if(std::to_string(port) != portStr || port <= 0) {
std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
return 32;
} else if (ip == "") {
std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl;
return 34;
} else if(settings->debugMode) {
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
}
settings->proxy_ip = ip;
settings->proxy_port = port;
} }
if(settings->debugMode)
std::cout << "Proxy Port: " << settings->proxy_port << std::endl;
break; break;
case 'o': case 'o':
if(optarg) if(optarg)
@ -360,10 +411,8 @@ void unterOption_url_help(Settings *, char * argv0)
<< "Parameter:" << std::endl << "Parameter:" << std::endl
<< "\t-u [Url1,Url2,...], --url [Url1,Url2,...]" << std::endl << "\t-u [Url1,Url2,...], --url [Url1,Url2,...]" << std::endl
<< "\t -> Die zu umwandelnden redirect-Links." << std::endl << "\t -> Die zu umwandelnden redirect-Links." << std::endl
<< "\t-i [ProxyIPAddresse], --ip-addresse [ProxyIPAddresse]" << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl
<< "\t -> Default: 127.0.0.1." << std::endl << "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl
<< "\t-p [ProxyPort], --port [ProxyPort]" << std::endl
<< "\t -> Default: 9050." << std::endl
<< "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl
<< "\t-c, --colorless" << std::endl << "\t-c, --colorless" << std::endl
<< "\t -> Default: false ." << std::endl << "\t -> Default: false ." << std::endl
@ -411,7 +460,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
{nullptr, no_argument, nullptr, 0} {nullptr, no_argument, nullptr, 0}


}; };
std::string optarg2;
while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) {
switch(c) { switch(c) {
case 'n': case 'n':
@ -421,15 +470,15 @@ int unterOption_search(Settings *settings, int argc, char **argv)
std::cout << "Name: " << settings->name << std::endl; std::cout << "Name: " << settings->name << std::endl;
break; break;
case 'p': { case 'p': {
optarg2 = optarg; if(!optarg || std::string(optarg) == "")
if(!optarg || optarg2 == "")
break; break;
else if(optarg2.find(":") == std::string::npos) { std::string optarg = ::optarg;
if(optarg.find(":") == std::string::npos) {
std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl; std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl;
return 31; return 31;
} }
std::string ip = optarg2.substr(0, optarg2.find(":")); std::string ip = optarg.substr(0, optarg.find(":"));
std::string portStr = optarg2.substr(optarg2.find(":") + 1, optarg2.length() - optarg2.find(":")); std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":"));
int port = atoi(portStr.c_str()); int port = atoi(portStr.c_str());
if(std::to_string(port) != portStr || port <= 0) { if(std::to_string(port) != portStr || port <= 0) {
std::cout << "[-p]: Invalid Port: " << portStr << std::endl; std::cout << "[-p]: Invalid Port: " << portStr << std::endl;
@ -441,7 +490,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl; std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl;
} }
settings->proxy_ip = ip; settings->proxy_ip = ip;
settings->proxy_port = port; settings->proxy_port = port;
} }
break; break;
case 'h': case 'h':

View File

@ -11,7 +11,8 @@ enum Modus {
EXIT = -1, EXIT = -1,
DEFAULT_MODUS = 0, DEFAULT_MODUS = 0,
DIRECT_LINK_MODUS = 1, DIRECT_LINK_MODUS = 1,
Search_MODUS = 2 Search_MODUS = 2,

}; };




@ -28,7 +29,10 @@ struct Settings {
languages = "GerDub,GerSub,Eng", languages = "GerDub,GerSub,Eng",
genaueHoster = "", genaueHoster = "",
version = "2.0.0", version = "2.0.0",
outputFilePath; outputFilePath = "",
default_checkDirPath = "",
default_Searchmuster = "S%Staffel%E%Folge%";

Modus modus = Modus::DEFAULT_MODUS; Modus modus = Modus::DEFAULT_MODUS;
bool colorless = false, bool colorless = false,
debugMode = false, debugMode = false,
@ -38,7 +42,8 @@ struct Settings {
stopEpisode = 0, stopEpisode = 0,
startSeason = 1, startSeason = 1,
stopSeason = 0, stopSeason = 0,
proxy_port = 9050; proxy_port = 9050,
default_maxDirs = 20;




}; };

View File

@ -37,6 +37,11 @@ int ProgramManager::defaultModus(Settings *settings)
return 27; return 27;
} }


std::string dirFiles;
if(settings->default_checkDirPath != "")
if(listDir(dirFiles, settings->default_checkDirPath, settings->default_maxDirs ) != 0)
return 28;

std::string nameInUrl =pageManager.checkName(settings->name); std::string nameInUrl =pageManager.checkName(settings->name);
if(nameInUrl == "-1") { if(nameInUrl == "-1") {
searchModus(settings); searchModus(settings);
@ -68,6 +73,15 @@ int ProgramManager::defaultModus(Settings *settings)
//for every episode //for every episode
for (int folge = settings->startEpisode; folge <= maxFolge; ++folge) { for (int folge = settings->startEpisode; folge <= maxFolge; ++folge) {


if(settings->default_checkDirPath != "") {
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 << "Skipping Folge: S" << staffel << "E" << folge << std::endl;
continue;
}
}

tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge)); tmp_reply =pageManager.getServerRequest(pageManager.UrlPraefix + nameInUrl + "/staffel-" + std::to_string(staffel) + "/episode-" + std::to_string(folge));
if(tmp_reply.html == "-1") if(tmp_reply.html == "-1")
return 47; return 47;
@ -232,6 +246,37 @@ int ProgramManager::searchModus_update(Settings *settings)
return 0; return 0;
} }


int ProgramManager::listDir(std::string &list,std::string path, int maxDepth)
{
if(maxDepth == 0)
return 0;
else if(!dirExists(path))
return -1;
else
maxDepth--;

if(path[path.length()-1] != '/')
path.push_back('/');

DIR* dirp = opendir(path.c_str());
if(!dirp) {
perror(std::string("Cannot open directory: " + 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(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, int ProgramManager::convertLink(std::string redirectLink, AccountManager * accountManager,
Settings * settings, int Staffel, int Folge, std::string allLinks) Settings * settings, int Staffel, int Folge, std::string allLinks)
{ {

View File

@ -6,24 +6,26 @@
#include "accountManager.h" #include "accountManager.h"
#include <unistd.h> #include <unistd.h>


#include <sys/types.h>
#include <dirent.h>

class ProgramManager class ProgramManager
{ {
public: public:
ProgramManager(); ProgramManager();
~ProgramManager(); ~ProgramManager();
int start(Settings setting); int start(Settings setting);
int listDir(std::string &list, std::string path, int maxDepth);


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



PageManager pageManager; PageManager pageManager;



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


}; };