Mercurial > minori
diff src/core/anime_db.cc @ 254:d14f8e0e40c3
[UNFINISHED] *: update anime button
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 07 Feb 2024 07:57:37 -0500 |
parents | 4d461ef7d424 |
children | 862d0d8619f6 |
line wrap: on
line diff
--- a/src/core/anime_db.cc Tue Feb 06 16:56:32 2024 -0500 +++ b/src/core/anime_db.cc Wed Feb 07 07:57:37 2024 -0500 @@ -123,47 +123,23 @@ } /* - * This fairly basic algorithm is only in effect because - * there are some special cases, e.g. Another and Re:ZERO, where - * we get the wrong match, so we have to create Advanced Techniques - * to solve this - * - * This algorithm: - * 1. searches each anime item for a match to the preferred title - * AND all synonyms and marks those matches with - * `synonym.length() - (synonym.find(needle) + needle.length());` - * which should never be less than zero and will be zero if, and only if - * the titles match exactly. - * 2. returns the id of the match that is the lowest, which will most - * definitely match anything that exactly matches the title of the - * filename + * TODO: separate this from the anime DB, + * provide *some* sort of normalization */ int Database::GetAnimeFromTitle(const std::string& title) { if (title.empty()) return 0; - std::unordered_map<int, size_t> map; - - static const auto process_title = [&map](const Anime& anime, const std::string& title, const std::string& needle) -> bool { - const std::string title_l = Strings::ToLower(title), needle_l = Strings::ToLower(needle); - size_t ret = title_l.find(needle_l); - if (ret == std::string::npos) - return false; - - map[anime.GetId()] = title.length() - (ret + needle.length()); - return true; - }; - for (const auto& [id, anime] : items) { - if (process_title(anime, anime.GetUserPreferredTitle(), title)) - continue; + if (anime.GetUserPreferredTitle() == title) + return id; for (const auto& synonym : anime.GetTitleSynonyms()) - if (process_title(anime, synonym, title)) - continue; + if (synonym == title) + return id; } - return get_lowest_in_map(map); + return 0; } static bool GetListDataAsJSON(const Anime& anime, nlohmann::json& json) {