forked from markus/S_New4
mach suchFunktion inc. Suchappdater multipageable
This commit is contained in:
parent
b46a966cda
commit
9602da29e7
@ -290,24 +290,45 @@ std::string PageManager::getUrlAfterRedirect(std::string Url)
|
||||
return getServerRequest(Url, true, "", false, true).url;
|
||||
}
|
||||
|
||||
std::string PageManager::checkName(std::string Name)
|
||||
std::string PageManager::checkName(std::vector<PAGE> pages, std::string Name)
|
||||
{
|
||||
int count = 0;
|
||||
std::string name = replace(Name, " ", "-");
|
||||
std::string pagesonExist;
|
||||
|
||||
std::string html = getServerRequest("https://serienstream.sx/serie/stream/" + name).html;
|
||||
//für jede Seite
|
||||
for ( const auto &page : pages ) {
|
||||
|
||||
std::string html = getServerRequest("https://" + page.url +"/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 => Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: '" << Name << "'" << std::endl;
|
||||
return "-1";
|
||||
continue;
|
||||
|
||||
} else if (html.find("404 - Seite nicht gefunden") != std::string::npos) {
|
||||
std::cout << "\33[2K\r => Ungültiger Name: '" << Name << "'" << std::endl;
|
||||
return "-1";
|
||||
|
||||
} else if (html == "-1" || html == "") {
|
||||
return "-2";
|
||||
|
||||
}
|
||||
else {
|
||||
count ++;
|
||||
pagesonExist += page.url + " ";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if( count == 1 ) {
|
||||
std::cout << "\33[2K\r > Name: " << name << std::endl;
|
||||
return name;
|
||||
} else if ( count > 1) {
|
||||
std::cout << "\33[2K\r => Die Serie existiert auf mehreren Seiten " << pagesonExist << ": '" << name << "'" << std::endl;
|
||||
return "-1";
|
||||
} else {
|
||||
std::cout << "\33[2K\r => Die gewünschte Serie wurde nicht gefunden oder ist im Moment deaktiviert: '" << Name << "'" << std::endl;
|
||||
return "-1";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string PageManager::getLinks(std::string HTML)
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
|
||||
int login(Account account);
|
||||
std::string getUrlAfterRedirect(std::string Url);
|
||||
std::string checkName(std::string Name);
|
||||
std::string checkName(std::vector<PAGE> pages, std::string Name);
|
||||
std::string getLinks(std::string HTML);
|
||||
std::string chooseHosterLink(std::string HosterList, std::string Hoster_with_Highst_Priority_at_First, std::string languages_with_highst_priority_at_first, bool withWarnMsg);
|
||||
std::string getLinkAfterHosterBasedOperation(std::string url);
|
||||
|
@ -30,6 +30,10 @@
|
||||
#define VERSION "4.3.7"
|
||||
|
||||
|
||||
//default, anime, normal,
|
||||
//suche: für jede katego. eine
|
||||
//zu beginn, erst eiunmal serie suchen
|
||||
|
||||
|
||||
enum Modus {
|
||||
EXIT = -1,
|
||||
@ -44,9 +48,38 @@ enum Modus {
|
||||
|
||||
};
|
||||
|
||||
struct PAGE {
|
||||
PAGE( std::string url, std::string nameID )
|
||||
: name_id(nameID), url(url) {}
|
||||
|
||||
std::string name_id,
|
||||
url;
|
||||
std::string urlAlphabetSerienList,
|
||||
UrlDir;
|
||||
|
||||
|
||||
std::string accountFileName = "",
|
||||
accountNumberFileName= "",
|
||||
cookieFileName = "",
|
||||
serienListName = "";
|
||||
};
|
||||
|
||||
struct Settings {
|
||||
Settings() {}
|
||||
Settings(std::string name) : name(name) {}
|
||||
Settings() {
|
||||
PAGE sto( "serienstream.sx", "Normale_Serien");
|
||||
sto.urlAlphabetSerienList = "/serien-alphabet";
|
||||
sto.UrlDir = "/serie/stream/";
|
||||
|
||||
pages.push_back( sto );
|
||||
|
||||
PAGE anicio ( "anicloud.io", "Animes");
|
||||
anicio.urlAlphabetSerienList = "/animes-alphabet";
|
||||
anicio.UrlDir = "/anime/stream/";
|
||||
|
||||
pages.push_back( anicio );
|
||||
|
||||
|
||||
}
|
||||
const std::string programName = "S_New4";
|
||||
|
||||
// Wenn das Betriebsystem x86 ist:
|
||||
@ -81,11 +114,13 @@ struct Settings {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::vector<PAGE> pages;
|
||||
std::string name,
|
||||
accountFilePath = "",
|
||||
accountNumberPath= "",
|
||||
cookieFilePath = "",
|
||||
serienListPath = "",
|
||||
|
||||
lastUpdateDateFilePath = "",
|
||||
configDir="",
|
||||
cacheDir="",
|
||||
@ -102,6 +137,7 @@ struct Settings {
|
||||
|
||||
std::vector<std::string> outputFilePaths;
|
||||
|
||||
|
||||
Modus modus = Modus::EXIT;
|
||||
bool colorless = false,
|
||||
debugMode = false,
|
||||
|
@ -288,7 +288,7 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana
|
||||
}
|
||||
|
||||
//Überprüfe ob es die serie gibt wenn ja speicher ihn in newname und beende Function
|
||||
newName = pageManager.checkName(finds);
|
||||
//<>/newName = pageManager.checkName(finds);
|
||||
if(newName == "-2")
|
||||
return 23;
|
||||
else if( newName == "-1" ) {
|
||||
@ -391,8 +391,10 @@ int ProgramManager::defaultModus(Settings *settings)
|
||||
if(dirFiles.length() > 0) //Entferne von der liste das \n am ende
|
||||
dirFiles.pop_back();
|
||||
|
||||
|
||||
|
||||
//Führe Function aus, die überprüft ob die serie existiert
|
||||
std::string nameInUrl =pageManager.checkName(settings->name);
|
||||
std::string nameInUrl =pageManager.checkName(settings->pages, settings->name);
|
||||
if(nameInUrl == "-2")
|
||||
return 67;
|
||||
else if(nameInUrl == "-1") {
|
||||
@ -684,6 +686,14 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Check for last Update.. (glaub hier nocghmal die funktion, um datei zu erstellen, auch wenn ausgabe deaktiviert is, kann aber auch sein dass der teil ghier weg gehört)
|
||||
if(checkLastUpdate(settings) != 0) {
|
||||
if(settings->debugMode)
|
||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": checkLastUpdate function failed." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
std::ifstream ifs(settings->serienListPath);
|
||||
if(!ifs.is_open()) {
|
||||
std::cout << " => Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl;
|
||||
@ -702,15 +712,9 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
}
|
||||
}
|
||||
|
||||
//Check for last Update..
|
||||
if(checkLastUpdate(settings) != 0) {
|
||||
if(settings->debugMode)
|
||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": checkLastUpdate function failed." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Save file in string:
|
||||
std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
std::string serienListe = std::string((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
|
||||
//Suche alle Möglichkeiten
|
||||
std::string finds = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower);
|
||||
@ -749,11 +753,35 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
std::stringstream strstream(finds);
|
||||
std::string line;
|
||||
std::cout << " => Für '" << settings->name << "' wurde(n) folgende Serie(n) gefunden: " << std::endl;
|
||||
|
||||
std::string lastPageUrl;
|
||||
while (getline(strstream, line)) {
|
||||
std::cout << " > " << line.substr(line.find_last_of('|') + 1, std::string::npos )
|
||||
<< "\t[" << line.substr(line.find("|/") + 2, line.find("|", line.find("|/") + 2) - line.find("|/") - 2) << "]"
|
||||
<< ( (line[0] == '|') ? "" : "\t( " + line.substr(0, line.find("|")) + " )" ) << std::endl;
|
||||
|
||||
//splitting
|
||||
///Nadia The Secret, Fushigi no Nadia|/nadia-zauberstein|Nadia und Zauberstein|seriento
|
||||
// into Vector
|
||||
|
||||
std::vector<std::string> parts;
|
||||
std::istringstream f(line + "|");
|
||||
std::string p;
|
||||
while (getline(f, p, '|').good())
|
||||
parts.push_back(p);
|
||||
if(parts.size() != 4) {
|
||||
std::cout << " => Error: Invalid SerienListeEintrag: '" << line << "'" << parts.size() << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( lastPageUrl != parts.at(3) ) {
|
||||
std::cout << ((settings->colorless) ? "" : "\033[93m") << "Auf '" << parts.at(3) << "'..." << ((settings->colorless) ? "" : "\033[0m") << std::endl;
|
||||
lastPageUrl = parts.at(3);
|
||||
}
|
||||
|
||||
std::cout << " > " << parts.at(2) << "\t[" << parts.at(1).erase(0, 1) << "]"
|
||||
<< ( (line[0] == '|') ? "" : "\t( " + parts.at(0) + " )" ) << std::endl;
|
||||
|
||||
///That Time I Got Reincarnated as a Slime|/tensei-shitara-slime-datta-ken|Tensei Shitara Slime Datta Ken|ANIME
|
||||
} /// > Tensei Shitara Slime Datta Ken [tensei-shitara-slime-datta-ken] ( That Time I Got Reincarnated as a Slime ) <s.to>
|
||||
|
||||
if(settings->debugMode)
|
||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": success." << std::endl;
|
||||
return 0;
|
||||
@ -769,7 +797,7 @@ int ProgramManager::infoModus(Settings *settings)
|
||||
}
|
||||
|
||||
//Führe Function aus, die überprüft ob die serie existiert
|
||||
std::string nameInUrl = pageManager.checkName(settings->name);
|
||||
std::string nameInUrl;//<>/ = pageManager.checkName(settings->name);
|
||||
if(nameInUrl == "-2")
|
||||
return 145;
|
||||
else if(nameInUrl == "-1") {
|
||||
@ -1361,7 +1389,15 @@ int ProgramManager::cleanUpSettingsAndCache(Settings *settings)
|
||||
|
||||
int ProgramManager::searchModus_update(Settings *settings)
|
||||
{
|
||||
Reply reply = pageManager.getServerRequest("https://serienstream.sx/serien-alphabet");
|
||||
std::string list;
|
||||
std::string line;
|
||||
|
||||
for ( const auto &page : settings->pages ) {
|
||||
std::cout << " -> Updating '" << page.name_id << "'..." << std::endl;
|
||||
|
||||
Reply reply = pageManager.getServerRequest("https://" + page.url + page.urlAlphabetSerienList);
|
||||
|
||||
|
||||
if(reply.html == "-1") {
|
||||
if(settings->debugMode)
|
||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": getServerRequest function failed." << std::endl;
|
||||
@ -1374,7 +1410,7 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
|
||||
std::string serienListe = replace( pageManager.grep( reply.html, "data-alternative-title" ), "</li>", "\n" );
|
||||
|
||||
std::string tests[] = {"\" href=\"", "<li><a data-alternative-title=\"", "/serie/stream/", "</a>", };
|
||||
std::string tests[] = {"\" href=\"", "<li><a data-alternative-title=\"", page.UrlDir, "</a>", };
|
||||
for ( auto t : tests ) {
|
||||
if(reply.html.find( t ) == std::string::npos) {
|
||||
if(settings->debugMode)
|
||||
@ -1383,17 +1419,14 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//...\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...
|
||||
//...\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 = 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...
|
||||
//...\n" href="/serie /stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
|
||||
serienListe = replace(serienListe, "\" href=\"", "|");
|
||||
//...\n|/serie/stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
|
||||
serienListe = replace(serienListe, "|/serie/stream/", "|/");
|
||||
//...\n|/serie /stream/2012-das-jahr-null" title="2012 - Das Jahr Null Stream anschauen">2012 - Das Jahr Null</a>\n...
|
||||
serienListe = replace(serienListe, "|" + page.UrlDir, "|/");
|
||||
|
||||
std::stringstream strstream(serienListe);
|
||||
std::string line;
|
||||
serienListe.clear();
|
||||
|
||||
while (getline(strstream, line)) {
|
||||
@ -1401,13 +1434,14 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
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...
|
||||
//...\n|/serie/ stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null</a>\n...
|
||||
line = replace(line, "\">", "|");
|
||||
//...\n|/serie/stream/2012-das-jahr-null|2012 - Das Jahr Null</a>\n...
|
||||
//...\n|/serie/ stream/2012-das-jahr-null|2012 - Das Jahr Null</a>\n...
|
||||
line = replace(line, "</a>", "");
|
||||
//...\n|/serie/stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n...
|
||||
//...\n|/serie/ stream/2012-das-jahr-null"_weg_>2012 - Das Jahr Null|\n...
|
||||
|
||||
serienListe += line + "\n";
|
||||
///Nadia The Secret, Fushigi no Nadia|/nadia-zauberstein|Nadia und Zauberstein|seriento
|
||||
serienListe += line + "|" + page.url + "\n";
|
||||
}
|
||||
if(serienListe.length() > 0)
|
||||
serienListe.pop_back();
|
||||
@ -1423,20 +1457,23 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
serienListe = replace(serienListe, """, "\""); //
|
||||
serienListe = replace(serienListe, "'", "'"); //
|
||||
|
||||
list += serienListe;
|
||||
|
||||
}
|
||||
|
||||
//Anzahl der Serien/Zeilen vorher:
|
||||
ssize_t countBef = 0;
|
||||
std::ifstream myFileBef(settings->serienListPath);
|
||||
std::ifstream myFileBef(settings->serienListPath );
|
||||
std::string alteListe;
|
||||
if(myFileBef.is_open()) {
|
||||
for(countBef = 0; std::getline(myFileBef,line); ++countBef) {
|
||||
for(countBef = 0; std::getline(myFileBef, line); ++countBef) {
|
||||
//Speicher alteListe für verglkeich nach Update
|
||||
alteListe.append(line + "\n");
|
||||
|
||||
//Vergeliche neue und alte list => entfernte Serien
|
||||
if(line != "" && serienListe.find(line) == std::string::npos) {
|
||||
std::cout << ((settings->colorless) ? "" : "\033[91m") << "Entfernt: '" << line.substr(line.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m")
|
||||
if(line != "" && list.find(line) == std::string::npos) {
|
||||
std::string tmp = std::string(line).erase(line.find_last_of('|'));
|
||||
std::cout << ((settings->colorless) ? "" : "\033[91m") << "Entfernt: '" << tmp.substr(tmp.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m")
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
@ -1444,24 +1481,25 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
}
|
||||
|
||||
//Schreibe die Liste in das TextFile
|
||||
std::ofstream ofs(settings->serienListPath, std::ios::trunc);
|
||||
std::ofstream ofs(settings->serienListPath , std::ios::trunc);
|
||||
if(!ofs.is_open()) {
|
||||
perror("Konnte SerienListe-Datei nicht öffnen");
|
||||
return 111;
|
||||
} else {
|
||||
//Schreibe Liste in das TextFile
|
||||
ofs << serienListe << std::endl;
|
||||
ofs << list << std::endl;
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
//Anzahl der Zeile nachher
|
||||
ssize_t countAf = 0;
|
||||
std::ifstream myFileAf(settings->serienListPath);
|
||||
std::ifstream myFileAf(settings->serienListPath );
|
||||
if(myFileAf.is_open()) {
|
||||
for(countAf = 0; std::getline(myFileAf,line); ++countAf) {
|
||||
//Vergeliche neu mit Alt => gib neue Serien aus
|
||||
if(line != "" && alteListe.find(line) == std::string::npos) {
|
||||
std::cout << ((settings->colorless) ? "" : "\033[92m") << "Neu: '" << line.substr(line.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m")
|
||||
std::string tmp = std::string(line).erase(line.find_last_of('|'));
|
||||
std::cout << ((settings->colorless) ? "" : "\033[92m") << "Neu: '" << tmp.substr(tmp.find_last_of("|") + 1) << "'" << ((settings->colorless) ? "" : "\033[0m")
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
@ -1473,7 +1511,11 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
|
||||
std::cout << ((settings->colorless) ? "" : "\033[93m") << "Serienunterschied: " << ( ((countAf - countBef) > 0) ? "+" : "") << countAf - countBef << " Serien." << "\033[0m" << std::endl;
|
||||
|
||||
//Speicher Dateim des Updates...
|
||||
|
||||
|
||||
|
||||
|
||||
//Speicher Datum des Updates...
|
||||
ofs.open(settings->lastUpdateDateFilePath, std::ios::trunc);
|
||||
if(!ofs.is_open()) {
|
||||
perror("Konnte UpdateDate-Datei nicht öffnen");
|
||||
@ -1484,7 +1526,6 @@ int ProgramManager::searchModus_update(Settings *settings)
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user