# HG changeset patch # User Paper # Date 1762440369 18000 # Node ID 04a894e9635544fcb46a95f0c371bf98eff5629d # Parent e89901683d7224a25b5cb10508a53733240ccf95 kitsu: implement anime search yay diff -r e89901683d72 -r 04a894e96355 src/gui/pages/now_playing.cc --- a/src/gui/pages/now_playing.cc Thu Nov 06 08:59:44 2025 -0500 +++ b/src/gui/pages/now_playing.cc Thu Nov 06 09:46:09 2025 -0500 @@ -27,6 +27,7 @@ QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); + // TODO this has more text in it in Taiga... title_.SetText(Strings::Translate("Now Playing")); layout->addWidget(&title_); diff -r e89901683d72 -r 04a894e96355 src/services/kitsu.cc --- a/src/services/kitsu.cc Thu Nov 06 08:59:44 2025 -0500 +++ b/src/services/kitsu.cc Thu Nov 06 09:46:09 2025 -0500 @@ -496,6 +496,16 @@ return 1; } +/* :) */ +static const std::map anime_params = { + {"include", Strings::Implode( + { + "categories", + "animeProductions", + "animeProductions.producer", + }, ",")} +}; + bool RetrieveAnimeMetadata(int id) { /* TODO: the genres should *probably* be a std::optional */ @@ -509,16 +519,7 @@ session.SetStatusBar(Strings::Translate("Kitsu: Retrieving anime metadata...")); - static const std::map params = { - {"include", Strings::Implode( - { - "categories", - "animeProductions", - "animeProductions.producer", - }, ",")} - }; - - std::optional response = SendJSONAPIRequest("/anime/" + service_id.value(), params); + std::optional response = SendJSONAPIRequest("/anime/" + service_id.value(), anime_params); if (!response) return false; @@ -540,7 +541,36 @@ /* unimplemented for now */ std::vector Search(const std::string &search) { - return {}; + session.SetStatusBar(Strings::Translate("Kitsu: Retrieving search results...")); + + std::map params = anime_params; + params["filter[text]"] = search; + // ... for some reason, this seems to be buggy + //AddAnimeFilters(params); + + std::optional response = SendJSONAPIRequest("/anime", params); + if (!response) + return {}; + + const auto &json = response.value(); + + if (!json.contains("/data"_json_pointer) || !json["/data"_json_pointer].is_array()) { + session.SetStatusBar( + Strings::Translate("Kitsu: Server returned bad data when trying to retrieve search results!")); + return {}; + } + + std::vector ids; + + for (const auto &item : json["/data"_json_pointer]) { + int id = ParseAnimeJson(item); + if (!id) + return {}; + + ids.push_back(id); + } + + return ids; } bool GetSeason(Anime::Season season)