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 <Syer10@users.noreply.github.com>

---------

Co-authored-by: Mitchell Syer <Syer10@users.noreply.github.com>
This commit is contained in:
Antoine Aflalo
2024-08-31 18:55:13 -04:00
committed by GitHub
parent 301980ab14
commit 9a74ae5844
2 changed files with 60 additions and 31 deletions
@@ -58,6 +58,9 @@ data class ComicInfo(
val web: Web?, val web: Web?,
val publishingStatus: PublishingStatusTachiyomi?, val publishingStatus: PublishingStatusTachiyomi?,
val categories: CategoriesTachiyomi?, val categories: CategoriesTachiyomi?,
val day: Day?,
val month: Month?,
val year: Year?,
) { ) {
@Suppress("UNUSED") @Suppress("UNUSED")
@XmlElement(false) @XmlElement(false)
@@ -87,6 +90,24 @@ data class ComicInfo(
@XmlValue(true) val value: String = "", @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 @Serializable
@XmlSerialName("Summary", "", "") @XmlSerialName("Summary", "", "")
data class Summary( data class Summary(
@@ -15,46 +15,54 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.nio.file.Path import java.nio.file.Path
import java.time.Instant
import java.time.ZoneId
import kotlin.io.path.deleteIfExists import kotlin.io.path.deleteIfExists
import kotlin.io.path.div import kotlin.io.path.div
import kotlin.io.path.outputStream import kotlin.io.path.outputStream
/**
* Creates a ComicInfo instance based on the manga and chapter metadata.
*/
fun getComicInfo( fun getComicInfo(
manga: ResultRow, manga: ResultRow,
chapter: ResultRow, chapter: ResultRow,
chapterUrl: String, chapterUrl: String,
categories: List<String>?, categories: List<String>?,
) = ComicInfo( ): ComicInfo {
title = ComicInfo.Title(chapter[ChapterTable.name]), val dateUpload = chapter[ChapterTable.date_upload]
series = ComicInfo.Series(manga[MangaTable.title]), val localDate =
number = Instant.ofEpochMilli(dateUpload).atZone(ZoneId.systemDefault()).toLocalDate()
chapter[ChapterTable.chapter_number].takeIf { it >= 0 }?.let {
if ((it.rem(1) == 0.0f)) { return ComicInfo(
ComicInfo.Number(it.toInt().toString()) title = ComicInfo.Title(chapter[ChapterTable.name]),
} else { series = ComicInfo.Series(manga[MangaTable.title]),
ComicInfo.Number(it.toString()) number =
} chapter[ChapterTable.chapter_number].takeIf { it >= 0 }?.let {
}, if ((it.rem(1) == 0.0f)) {
web = ComicInfo.Web(chapterUrl), ComicInfo.Number(it.toInt().toString())
summary = manga[MangaTable.description]?.let { ComicInfo.Summary(it) }, } else {
writer = manga[MangaTable.author]?.let { ComicInfo.Writer(it) }, ComicInfo.Number(it.toString())
penciller = manga[MangaTable.artist]?.let { ComicInfo.Penciller(it) }, }
translator = chapter[ChapterTable.scanlator]?.let { ComicInfo.Translator(it) }, },
genre = manga[MangaTable.genre]?.let { ComicInfo.Genre(it) }, web = ComicInfo.Web(chapterUrl),
publishingStatus = summary = manga[MangaTable.description]?.let { ComicInfo.Summary(it) },
ComicInfo.PublishingStatusTachiyomi( writer = manga[MangaTable.author]?.let { ComicInfo.Writer(it) },
ComicInfoPublishingStatus.toComicInfoValue(manga[MangaTable.status].toLong()), penciller = manga[MangaTable.artist]?.let { ComicInfo.Penciller(it) },
), translator = chapter[ChapterTable.scanlator]?.let { ComicInfo.Translator(it) },
categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) }, genre = manga[MangaTable.genre]?.let { ComicInfo.Genre(it) },
inker = null, publishingStatus =
colorist = null, ComicInfo.PublishingStatusTachiyomi(
letterer = null, ComicInfoPublishingStatus.toComicInfoValue(manga[MangaTable.status].toLong()),
coverArtist = null, ),
tags = null, 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. * Creates a ComicInfo.xml file inside the given directory.