From 9a74ae5844fd059bf4e8e921a36e48348aa635ca Mon Sep 17 00:00:00 2001 From: Antoine Aflalo <197810+Belphemur@users.noreply.github.com> Date: Sat, 31 Aug 2024 18:55:13 -0400 Subject: [PATCH] feat(comicinfo): add date fields to comic info (#1021) * feat(comicinfo): add date fields to comic info This will be parsed by Komga, Kavita etc ... and any other library management to also have the date of the chapter. * refactor: improve code readability Co-authored-by: Mitchell Syer --------- Co-authored-by: Mitchell Syer --- .../source/local/metadata/ComicInfo.kt | 21 ++++++ .../tachidesk/manga/impl/util/GetComicInfo.kt | 70 +++++++++++-------- 2 files changed, 60 insertions(+), 31 deletions(-) diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/metadata/ComicInfo.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/metadata/ComicInfo.kt index d129d017..e299c24a 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/metadata/ComicInfo.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/source/local/metadata/ComicInfo.kt @@ -58,6 +58,9 @@ data class ComicInfo( val web: Web?, val publishingStatus: PublishingStatusTachiyomi?, val categories: CategoriesTachiyomi?, + val day: Day?, + val month: Month?, + val year: Year?, ) { @Suppress("UNUSED") @XmlElement(false) @@ -87,6 +90,24 @@ data class ComicInfo( @XmlValue(true) val value: String = "", ) + @Serializable + @XmlSerialName("Day", "", "") + data class Day( + @XmlValue(true) val value: Int = 0, + ) + + @Serializable + @XmlSerialName("Month", "", "") + data class Month( + @XmlValue(true) val value: Int = 0, + ) + + @Serializable + @XmlSerialName("Year", "", "") + data class Year( + @XmlValue(true) val value: Int = 0, + ) + @Serializable @XmlSerialName("Summary", "", "") data class Summary( diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/GetComicInfo.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/GetComicInfo.kt index 8b10eeb0..757d18bc 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/GetComicInfo.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/GetComicInfo.kt @@ -15,46 +15,54 @@ import suwayomi.tachidesk.manga.model.table.MangaTable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.nio.file.Path +import java.time.Instant +import java.time.ZoneId import kotlin.io.path.deleteIfExists import kotlin.io.path.div import kotlin.io.path.outputStream -/** - * Creates a ComicInfo instance based on the manga and chapter metadata. - */ fun getComicInfo( manga: ResultRow, chapter: ResultRow, chapterUrl: String, categories: List?, -) = ComicInfo( - title = ComicInfo.Title(chapter[ChapterTable.name]), - series = ComicInfo.Series(manga[MangaTable.title]), - number = - chapter[ChapterTable.chapter_number].takeIf { it >= 0 }?.let { - if ((it.rem(1) == 0.0f)) { - ComicInfo.Number(it.toInt().toString()) - } else { - ComicInfo.Number(it.toString()) - } - }, - web = ComicInfo.Web(chapterUrl), - summary = manga[MangaTable.description]?.let { ComicInfo.Summary(it) }, - writer = manga[MangaTable.author]?.let { ComicInfo.Writer(it) }, - penciller = manga[MangaTable.artist]?.let { ComicInfo.Penciller(it) }, - translator = chapter[ChapterTable.scanlator]?.let { ComicInfo.Translator(it) }, - genre = manga[MangaTable.genre]?.let { ComicInfo.Genre(it) }, - publishingStatus = - ComicInfo.PublishingStatusTachiyomi( - ComicInfoPublishingStatus.toComicInfoValue(manga[MangaTable.status].toLong()), - ), - categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) }, - inker = null, - colorist = null, - letterer = null, - coverArtist = null, - tags = null, -) +): ComicInfo { + val dateUpload = chapter[ChapterTable.date_upload] + val localDate = + Instant.ofEpochMilli(dateUpload).atZone(ZoneId.systemDefault()).toLocalDate() + + return ComicInfo( + title = ComicInfo.Title(chapter[ChapterTable.name]), + series = ComicInfo.Series(manga[MangaTable.title]), + number = + chapter[ChapterTable.chapter_number].takeIf { it >= 0 }?.let { + if ((it.rem(1) == 0.0f)) { + ComicInfo.Number(it.toInt().toString()) + } else { + ComicInfo.Number(it.toString()) + } + }, + web = ComicInfo.Web(chapterUrl), + summary = manga[MangaTable.description]?.let { ComicInfo.Summary(it) }, + writer = manga[MangaTable.author]?.let { ComicInfo.Writer(it) }, + penciller = manga[MangaTable.artist]?.let { ComicInfo.Penciller(it) }, + translator = chapter[ChapterTable.scanlator]?.let { ComicInfo.Translator(it) }, + genre = manga[MangaTable.genre]?.let { ComicInfo.Genre(it) }, + publishingStatus = + ComicInfo.PublishingStatusTachiyomi( + ComicInfoPublishingStatus.toComicInfoValue(manga[MangaTable.status].toLong()), + ), + categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) }, + inker = null, + colorist = null, + letterer = null, + coverArtist = null, + tags = null, + day = localDate?.dayOfMonth?.let { ComicInfo.Day(it) }, + month = localDate?.monthValue?.let { ComicInfo.Month(it) }, + year = localDate?.year?.let { ComicInfo.Year(it) }, + ) +} /** * Creates a ComicInfo.xml file inside the given directory.