# HG changeset patch # User Paper # Date 1718247802 14400 # Node ID 5d3c9b31aa6e5636c2b837a79d280ea419c41118 # Parent 1686fac290c502251d29a5efc44973de2d660342 anime: add completed date member diff -r 1686fac290c5 -r 5d3c9b31aa6e include/core/anime.h --- a/include/core/anime.h Wed Jun 12 22:48:16 2024 -0400 +++ b/include/core/anime.h Wed Jun 12 23:03:22 2024 -0400 @@ -131,7 +131,8 @@ std::vector synonyms; int episodes = 0; SeriesStatus status = SeriesStatus::Unknown; - Date air_date; + Date started; + Date completed; std::vector genres; std::vector producers; SeriesFormat format = SeriesFormat::Unknown; @@ -176,7 +177,8 @@ std::vector GetTitleSynonyms() const; int GetEpisodes() const; SeriesStatus GetAiringStatus() const; - Date GetAirDate() const; + Date GetStartedDate() const; + Date GetCompletedDate() const; std::vector GetGenres() const; std::vector GetProducers() const; SeriesFormat GetFormat() const; @@ -194,7 +196,8 @@ void AddTitleSynonym(const std::string& synonym); void SetEpisodes(int episodes); void SetAiringStatus(SeriesStatus status); - void SetAirDate(const Date& date); + void SetStartedDate(const Date& date); + void SetCompletedDate(const Date& date); void SetGenres(const std::vector& genres); void SetProducers(const std::vector& producers); void SetFormat(SeriesFormat format); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/core/anime.cc --- a/src/core/anime.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/core/anime.cc Wed Jun 12 23:03:22 2024 -0400 @@ -142,12 +142,12 @@ list_info_->progress = progress; } -void Anime::SetUserDateStarted(Date const& started) { +void Anime::SetUserDateStarted(const Date& started) { assert(list_info_.has_value()); list_info_->started = started; } -void Anime::SetUserDateCompleted(Date const& completed) { +void Anime::SetUserDateCompleted(const Date& completed) { assert(list_info_.has_value()); list_info_->completed = completed; } @@ -172,7 +172,7 @@ list_info_->updated = updated; } -void Anime::SetUserNotes(std::string const& notes) { +void Anime::SetUserNotes(const std::string& notes) { assert(list_info_.has_value()); list_info_->notes = notes; } @@ -224,8 +224,12 @@ return info_.status; } -Date Anime::GetAirDate() const { - return info_.air_date; +Date Anime::GetStartedDate() const { + return info_.started; +} + +Date Anime::GetCompletedDate() const { + return info_.completed; } std::vector Anime::GetGenres() const { @@ -241,7 +245,7 @@ } SeriesSeason Anime::GetSeason() const { - std::optional month = info_.air_date.GetMonth(); + std::optional month = info_.started.GetMonth(); return (month.has_value() ? GetSeasonForMonth(month.value()) : SeriesSeason::Unknown); } @@ -289,11 +293,11 @@ info_.titles[language] = title; } -void Anime::SetTitleSynonyms(std::vector const& synonyms) { +void Anime::SetTitleSynonyms(const std::vector& synonyms) { info_.synonyms = synonyms; } -void Anime::AddTitleSynonym(std::string const& synonym) { +void Anime::AddTitleSynonym(const std::string& synonym) { info_.synonyms.push_back(synonym); } @@ -305,15 +309,19 @@ info_.status = status; } -void Anime::SetAirDate(Date const& date) { - info_.air_date = date; +void Anime::SetStartedDate(const Date& date) { + info_.started = date; } -void Anime::SetGenres(std::vector const& genres) { +void Anime::SetCompletedDate(const Date& date) { + info_.completed = date; +} + +void Anime::SetGenres(const std::vector& genres) { info_.genres = genres; } -void Anime::SetProducers(std::vector const& producers) { +void Anime::SetProducers(const std::vector& producers) { info_.producers = producers; } diff -r 1686fac290c5 -r 5d3c9b31aa6e src/core/anime_db.cc --- a/src/core/anime_db.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/core/anime_db.cc Wed Jun 12 23:03:22 2024 -0400 @@ -159,7 +159,8 @@ {"synonyms", anime.GetTitleSynonyms()}, {"episodes", anime.GetEpisodes()}, {"airing_status", Translate::ToString(anime.GetAiringStatus())}, - {"air_date", anime.GetAirDate().GetAsAniListJson()}, + {"started_date", anime.GetStartedDate().GetAsAniListJson()}, + {"completed_date", anime.GetCompletedDate().GetAsAniListJson()}, {"genres", anime.GetGenres()}, {"producers", anime.GetProducers()}, {"format", Translate::ToString(anime.GetFormat())}, @@ -260,7 +261,8 @@ anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0)); anime.SetAiringStatus( Translate::ToSeriesStatus(JSON::GetString(json, "/airing_status"_json_pointer, ""))); - anime.SetAirDate(Date(JSON::GetValue(json, "/air_date"_json_pointer))); + anime.SetStartedDate(Date(JSON::GetValue(json, "/started_date"_json_pointer))); + anime.SetCompletedDate(Date(JSON::GetValue(json, "/completed_date"_json_pointer))); anime.SetGenres(JSON::GetArray>(json, "/genres"_json_pointer, {})); anime.SetProducers(JSON::GetArray>(json, "/producers"_json_pointer, {})); anime.SetFormat(Translate::ToSeriesFormat(JSON::GetString(json, "/format"_json_pointer, ""))); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/core/anime_season_db.cc --- a/src/core/anime_season_db.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/core/anime_season_db.cc Wed Jun 12 23:03:22 2024 -0400 @@ -9,7 +9,7 @@ std::vector ret; for (const auto& [id, anime] : db.items) { - std::optional anime_year = anime.GetAirDate().GetYear(); + std::optional anime_year = anime.GetStartedDate().GetYear(); if (anime.GetSeason() == season && anime_year && anime_year.value() == year) ret.push_back(id); } diff -r 1686fac290c5 -r 5d3c9b31aa6e src/gui/dialog/information.cc --- a/src/gui/dialog/information.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/gui/dialog/information.cc Wed Jun 12 23:03:22 2024 -0400 @@ -230,7 +230,7 @@ _started = anime->GetUserDateStarted(); if (!_started.IsValid()) { date->SetEnabled(false); - _started = anime->GetAirDate(); + _started = anime->GetStartedDate(); } date->SetDate(_started); layout->addWidget(date, 1, 0); @@ -247,7 +247,7 @@ _completed = anime->GetUserDateCompleted(); if (!_completed.IsValid()) { date->SetEnabled(false); - _completed = anime->GetAirDate(); + _completed = anime->GetCompletedDate(); } date->SetDate(_completed); layout->addWidget(date, 1, 1); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/gui/pages/anime_list.cc --- a/src/gui/pages/anime_list.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/gui/pages/anime_list.cc Wed Jun 12 23:03:22 2024 -0400 @@ -143,7 +143,7 @@ case AL_SCORE: return Strings::ToQString(list[index.row()].GetUserPresentableScore()); case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat())); case AL_SEASON: { - std::optional year = list[index.row()].GetAirDate().GetYear(); + std::optional year = list[index.row()].GetStartedDate().GetYear(); if (!year) return tr("Unknown Unknown"); return Strings::ToQString(Translate::ToLocalString(list[index.row()].GetSeason()) + " " + @@ -166,7 +166,7 @@ case AL_PROGRESS: return list[index.row()].GetUserProgress(); case AL_SCORE: return list[index.row()].GetUserScore(); case AL_TYPE: return static_cast(list[index.row()].GetFormat()); - case AL_SEASON: return list[index.row()].GetAirDate().GetAsQDate(); + case AL_SEASON: return list[index.row()].GetStartedDate().GetAsQDate(); case AL_AVG_SCORE: return list[index.row()].GetAudienceScore(); case AL_UPDATED: return QVariant::fromValue(list[index.row()].GetUserTimeUpdated()); default: return data(index, Qt::DisplayRole); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/gui/pages/search.cc --- a/src/gui/pages/search.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/gui/pages/search.cc Wed Jun 12 23:03:22 2024 -0400 @@ -128,7 +128,7 @@ case SR_SCORE: return QString::number(anime.GetAudienceScore()) + "%"; case SR_SEASON: return Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) + " " + - QString::number(anime.GetAirDate().GetYear().value_or(2000)); + QString::number(anime.GetStartedDate().GetYear().value_or(2000)); default: return {}; } break; @@ -136,7 +136,7 @@ switch (index.column()) { case SR_SCORE: return anime.GetAudienceScore(); case SR_EPISODES: return anime.GetEpisodes(); - case SR_SEASON: return anime.GetAirDate().GetAsQDate(); + case SR_SEASON: return anime.GetStartedDate().GetAsQDate(); /* We have to use this to work around some stupid * "conversion ambiguous" error on Linux */ diff -r 1686fac290c5 -r 5d3c9b31aa6e src/gui/widgets/anime_button.cc --- a/src/gui/widgets/anime_button.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/gui/widgets/anime_button.cc Wed Jun 12 23:03:22 2024 -0400 @@ -92,7 +92,7 @@ { const QLocale& locale = session.config.locale.GetLocale(); - _info.GetData()->setText(locale.toString(anime.GetAirDate().GetAsQDate(), "dd MMM yyyy") + "\n" + + _info.GetData()->setText(locale.toString(anime.GetStartedDate().GetAsQDate(), "dd MMM yyyy") + "\n" + QString::number(anime.GetEpisodes()) + "\n" + Strings::ToQString(Strings::Implode(anime.GetGenres(), ", ")) + "\n" + "...\n" + QString::number(anime.GetAudienceScore()) + "%\n" + "..."); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/gui/widgets/anime_info.cc --- a/src/gui/widgets/anime_info.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/gui/widgets/anime_info.cc Wed Jun 12 23:03:22 2024 -0400 @@ -98,7 +98,7 @@ << anime.GetEpisodes() << "\n" << Strings::ToQString(Translate::ToLocalString(anime.GetAiringStatus())) << "\n" << Strings::ToQString(Translate::ToLocalString(anime.GetSeason())) << " " - << anime.GetAirDate().GetYear().value_or(2000) << "\n" + << anime.GetStartedDate().GetYear().value_or(2000) << "\n" << Strings::ToQString((genres.size() > 1) ? Strings::Implode(genres, ", ") : "-") << "\n" << Strings::ToQString((producers.size() > 1) ? Strings::Implode(producers, ", ") : "-") << "\n" << anime.GetAudienceScore() << "%"; diff -r 1686fac290c5 -r 5d3c9b31aa6e src/services/anilist.cc --- a/src/services/anilist.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/services/anilist.cc Wed Jun 12 23:03:22 2024 -0400 @@ -51,6 +51,11 @@ " month\n" \ " day\n" \ "}\n" \ + "endDate {\n" \ + " year\n" \ + " month\n" \ + " day\n" \ + "}\n" \ "studios {\n" \ " edges {\n" \ " node {\n" \ @@ -190,7 +195,13 @@ anime.SetAiringStatus( Translate::AniList::ToSeriesStatus(JSON::GetString(json, "/status"_json_pointer, ""))); - anime.SetAirDate(Date(json["/startDate"_json_pointer])); + if (json.contains("/startDate"_json_pointer) && json["/startDate"_json_pointer].is_object()) + anime.SetStartedDate(Date(json["/startDate"_json_pointer])); + + if (json.contains("/endDate"_json_pointer) && json["/endDate"_json_pointer].is_object()) + anime.SetCompletedDate(Date(json["/endDate"_json_pointer])); + else + anime.SetCompletedDate(anime.GetStartedDate()); anime.SetPosterUrl(JSON::GetString(json, "/coverImage/large"_json_pointer, "")); diff -r 1686fac290c5 -r 5d3c9b31aa6e src/services/kitsu.cc --- a/src/services/kitsu.cc Wed Jun 12 22:48:16 2024 -0400 +++ b/src/services/kitsu.cc Wed Jun 12 23:03:22 2024 -0400 @@ -297,9 +297,12 @@ anime.SetAudienceScore(Strings::ToInt(attributes["/averageRating"_json_pointer].get())); if (attributes.contains("/startDate"_json_pointer) && attributes["/startDate"_json_pointer].is_string()) - anime.SetAirDate(attributes["/startDate"_json_pointer].get()); + anime.SetStartedDate(attributes["/startDate"_json_pointer].get()); - // XXX endDate + if (attributes.contains("/endDate"_json_pointer) && attributes["/endDate"_json_pointer].is_string()) + anime.SetCompletedDate(attributes["/endDate"_json_pointer].get()); + else + anime.SetCompletedDate(anime.GetStartedDate()); if (attributes.contains("/subtype"_json_pointer) && attributes["/subtype"_json_pointer].is_string()) ParseSubtype(anime, attributes["/subtype"_json_pointer].get());