changeset 324:5d3c9b31aa6e

anime: add completed date member
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 23:03:22 -0400
parents 1686fac290c5
children 78929794e7d8
files include/core/anime.h src/core/anime.cc src/core/anime_db.cc src/core/anime_season_db.cc src/gui/dialog/information.cc src/gui/pages/anime_list.cc src/gui/pages/search.cc src/gui/widgets/anime_button.cc src/gui/widgets/anime_info.cc src/services/anilist.cc src/services/kitsu.cc
diffstat 11 files changed, 56 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- 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<std::string> synonyms;
 	int episodes = 0;
 	SeriesStatus status = SeriesStatus::Unknown;
-	Date air_date;
+	Date started;
+	Date completed;
 	std::vector<std::string> genres;
 	std::vector<std::string> producers;
 	SeriesFormat format = SeriesFormat::Unknown;
@@ -176,7 +177,8 @@
 	std::vector<std::string> GetTitleSynonyms() const;
 	int GetEpisodes() const;
 	SeriesStatus GetAiringStatus() const;
-	Date GetAirDate() const;
+	Date GetStartedDate() const;
+	Date GetCompletedDate() const;
 	std::vector<std::string> GetGenres() const;
 	std::vector<std::string> 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<std::string>& genres);
 	void SetProducers(const std::vector<std::string>& producers);
 	void SetFormat(SeriesFormat format);
--- 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<std::string> Anime::GetGenres() const {
@@ -241,7 +245,7 @@
 }
 
 SeriesSeason Anime::GetSeason() const {
-	std::optional<Date::Month> month = info_.air_date.GetMonth();
+	std::optional<Date::Month> 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<std::string> const& synonyms) {
+void Anime::SetTitleSynonyms(const std::vector<std::string>& 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<std::string> const& genres) {
+void Anime::SetCompletedDate(const Date& date) {
+	info_.completed = date;
+}
+
+void Anime::SetGenres(const std::vector<std::string>& genres) {
 	info_.genres = genres;
 }
 
-void Anime::SetProducers(std::vector<std::string> const& producers) {
+void Anime::SetProducers(const std::vector<std::string>& producers) {
 	info_.producers = producers;
 }
 
--- 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<std::string>(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<std::vector<std::string>>(json, "/genres"_json_pointer, {}));
 	anime.SetProducers(JSON::GetArray<std::vector<std::string>>(json, "/producers"_json_pointer, {}));
 	anime.SetFormat(Translate::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
--- 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<int> ret;
 
 	for (const auto& [id, anime] : db.items) {
-		std::optional<Date::Year> anime_year = anime.GetAirDate().GetYear();
+		std::optional<Date::Year> anime_year = anime.GetStartedDate().GetYear();
 		if (anime.GetSeason() == season && anime_year && anime_year.value() == year)
 			ret.push_back(id);
 	}
--- 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);
--- 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<unsigned int> year = list[index.row()].GetAirDate().GetYear();
+					std::optional<unsigned int> 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<int>(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);
--- 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
 				 */
--- 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" + "...");
--- 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() << "%";
--- 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<std::string>(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<std::string>(json, "/coverImage/large"_json_pointer, ""));
 
--- 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<double>(attributes["/averageRating"_json_pointer].get<std::string>()));
 
 	if (attributes.contains("/startDate"_json_pointer) && attributes["/startDate"_json_pointer].is_string())
-		anime.SetAirDate(attributes["/startDate"_json_pointer].get<std::string>());
+		anime.SetStartedDate(attributes["/startDate"_json_pointer].get<std::string>());
 
-	// XXX endDate
+	if (attributes.contains("/endDate"_json_pointer) && attributes["/endDate"_json_pointer].is_string())
+		anime.SetCompletedDate(attributes["/endDate"_json_pointer].get<std::string>());
+	else
+		anime.SetCompletedDate(anime.GetStartedDate());
 
 	if (attributes.contains("/subtype"_json_pointer) && attributes["/subtype"_json_pointer].is_string())
 		ParseSubtype(anime, attributes["/subtype"_json_pointer].get<std::string>());