v6.0.1: add levinshtein to search

This commit is contained in:
M4RKUS28
2023-09-23 03:30:29 +02:00
parent dade791f35
commit 25fe37e647
174 changed files with 67023 additions and 3 deletions

Binary file not shown.

View File

@ -933,6 +933,7 @@ void unterOption_url_help(std::string programName)
int unterOption_search(Settings *settings, int argc, char **argv)
{
settings->modus = Modus::SEARCH_MODUS;
bool changedInternetPages = false;
int c = 0;
const option long_opts[] = {
@ -963,6 +964,8 @@ int unterOption_search(Settings *settings, int argc, char **argv)
break;
if(setUpInternetPages(*settings, optarg) != 0)
return 4356;
else
changedInternetPages = true;
break;
case 'h':
unterOption_search_help(settings->programName);
@ -1004,6 +1007,11 @@ int unterOption_search(Settings *settings, int argc, char **argv)
}
}
if( ! changedInternetPages) {
if(setUpInternetPages(*settings, "all") != 0)
return 4356;
}
//Alle nicht verwendeten Parameter == Name
while (optind < argc) {
if(argv[optind][0]) {
@ -1052,7 +1060,8 @@ void unterOption_search_help(std::string programName)
<< " nach Serien gesucht werden soll. (Nur Seiten aus Default Wert möglich)" << std::endl
<< " Die Seiten Kommagetrennt nach Priorität angeben. (Höchste am Anfang)" << std::endl
<< " Das Aktualisieren der Liste kann damit nicht beeinflusst werden." << std::endl
<< " Standart: AniWorld.to,serienstream.to" << std::endl << std::endl;
<< " Die Suchoption ignoriert im Defaultfile Standartseiten und nimmt standartmäßig 'all'!" << std::endl
<< " Standart: all" << std::endl << std::endl;
std::cout << "OPTIONEN:" << std::endl
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl

View File

@ -25,7 +25,7 @@
#define UpdaterCloudUrlWithPath "https://cloud.obermui.de/s/tXz7SWdaPJ7TacZ/download?path=%2F&files="
#define SecondUpdaterCloudUrlWithPath "https://snew4.obermui.de/download?path=%2F&files="
#define VERSION "6.0.0"
#define VERSION "6.1.0"
#define DEFAULT_FILE_VERSION "2.5"
//default, anime, normal,

View File

@ -876,6 +876,36 @@ int ProgramManager::directLinkModus(Settings *settings)
return 0;
}
int levenshtein_distance(const std::string& str1, const std::string& str2) {
int m = str1.length();
int n = str2.length();
// Initialize a matrix to store the distances
int* dp = new int[(m + 1) * (n + 1)];
memset(dp, 0, (m + 1) * (n + 1) * sizeof(int));
for (int i = 0; i <= m; ++i)
dp[i * (n + 1)] = i;
for (int j = 0; j <= n; ++j)
dp[j] = j;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
int cost = (str1[i - 1] == str2[j - 1]) ? 0 : 1;
dp[i * (n + 1) + j] = std::min({dp[(i - 1) * (n + 1) + j] + 1, dp[i * (n + 1) + (j - 1)] + 1, dp[(i - 1) * (n + 1) + (j - 1)] + cost});
}
}
int distance = dp[(m + 1) * (n + 1) - 1];
delete[] dp;
return distance;
}
int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool noPrint)
{
ssize_t dayddiff;
@ -948,7 +978,6 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
//Suche alle Möglichkeiten
std::string fullList = pageManager.grep(serienListe, settings->name, settings->search_IgnoreUpperLower);
serienListe.clear(); // Speicher freigeben
/*//Text mit Farben versehen
if(!settings->colorless) {
@ -985,6 +1014,38 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
if(settings->debugMode)
std::cout << " <DEBUG> FiNDS: '" << finds << "'" << std::endl;
if(finds == "" ) {
if(settings->debugMode)
std::cout << " NICHTS GEFUNDEN -> Levenshtein Suche..." << std::endl;
std::istringstream stream(serienListe + "\n");
std::string line;
while (std::getline(stream, line)) {
if(line == "") continue;
size_t ind_1 = line.find("|");
if(ind_1 == std::string::npos)
continue;
size_t ind_2 = line.find("|", ind_1 + 1);
if(ind_2 == std::string::npos)
continue;
size_t ind_3 = line.find("|", ind_2 + 1);
if(ind_3 == std::string::npos)
continue;
// if(allUrlsInUSe.find( line.substr(ind_3 + 1) ) == std::string::npos)
// continue;
if(levenshtein_distance(line.substr(ind_2 + 1, ind_3 - ind_2 - 1), settings->name) <= 2)
finds += line + "\n";
}
if(finds.size() >= 1)
finds.pop_back();
}
serienListe.clear(); // Speicher freigeben
if(saveTo) {
//Save List to Variable if set
*saveTo=finds;
@ -1005,6 +1066,10 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
//Ausgabe
if(finds == "") {
std::cout << " => Für '" << settings->name << "' wurde(n) keine Serie(n) gefunden." << std::endl;
return 0;
}
std::stringstream strstream(finds);