Use & write Year, Month, Day info in ComicInfo (#3967)
* Use & write Year, Month, Day info in ComicInfo Currently, users can only modify the date Mihon displays in the chapter list by manipulating the _last modified date_ of the file. This is obviously inconvenient, especially since the ComicInfo spec includes Year, Month, and Day fields for this exact purpose. If present, this reads the date at start of day in the current default system time zone (which matches how we use Chapter.dateUpload with relativeDateText, for example). If Year is not specified, the entire date process is skipped. If Month is not specified, it is set to January. If Day is not specified, it is set to the first. The parsed date (if any) is set as the Chapter's `date_upload` which is used for display in the app. Additionally, Mihon now includes this info in the written ComicInfo.xml file for downloaded chapters. This will be convenient for many more users, not least of which those who move source-downloaded chapters to Local Source to read from there. --- I used kotlinx.datetime because it's what we use for date parsing in non-i18n places already. * Changelog
This commit is contained in:
@@ -5,6 +5,9 @@ import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.ReadingMode
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.number
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import mihon.app.di.appGraph
|
||||
import tachiyomi.core.common.preference.TriState
|
||||
import tachiyomi.core.metadata.comicinfo.ComicInfo
|
||||
@@ -13,6 +16,7 @@ import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.time.Instant
|
||||
|
||||
// TODO: move these into the domain model
|
||||
val Manga.readingMode: Long
|
||||
@@ -85,30 +89,41 @@ fun getComicInfo(
|
||||
urls: List<String>,
|
||||
categories: List<String>?,
|
||||
sourceName: String,
|
||||
) = ComicInfo(
|
||||
title = ComicInfo.Title(chapter.name),
|
||||
series = ComicInfo.Series(manga.title),
|
||||
number = chapter.chapterNumber.takeIf { it >= 0 }?.let {
|
||||
if ((it.rem(1) == 0.0)) {
|
||||
ComicInfo.Number(it.toInt().toString())
|
||||
} else {
|
||||
ComicInfo.Number(it.toString())
|
||||
): ComicInfo {
|
||||
val date = chapter.dateUpload
|
||||
.takeIf { it != 0L }
|
||||
?.let {
|
||||
Instant.fromEpochMilliseconds(it).toLocalDateTime(TimeZone.currentSystemDefault())
|
||||
}
|
||||
},
|
||||
web = ComicInfo.Web(urls.joinToString(" ")),
|
||||
summary = manga.description?.let { ComicInfo.Summary(it) },
|
||||
writer = manga.author?.let { ComicInfo.Writer(it) },
|
||||
penciller = manga.artist?.let { ComicInfo.Penciller(it) },
|
||||
translator = chapter.scanlator?.let { ComicInfo.Translator(it) },
|
||||
genre = manga.genre?.let { ComicInfo.Genre(it.joinToString()) },
|
||||
publishingStatus = ComicInfo.PublishingStatusTachiyomi(
|
||||
ComicInfoPublishingStatus.toComicInfoValue(manga.status),
|
||||
),
|
||||
categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) },
|
||||
source = ComicInfo.SourceMihon(sourceName),
|
||||
inker = null,
|
||||
colorist = null,
|
||||
letterer = null,
|
||||
coverArtist = null,
|
||||
tags = null,
|
||||
)
|
||||
|
||||
return ComicInfo(
|
||||
title = ComicInfo.Title(chapter.name),
|
||||
series = ComicInfo.Series(manga.title),
|
||||
number = chapter.chapterNumber.takeIf { it >= 0 }?.let {
|
||||
if ((it.rem(1) == 0.0)) {
|
||||
ComicInfo.Number(it.toInt().toString())
|
||||
} else {
|
||||
ComicInfo.Number(it.toString())
|
||||
}
|
||||
},
|
||||
web = ComicInfo.Web(urls.joinToString(" ")),
|
||||
summary = manga.description?.let { ComicInfo.Summary(it) },
|
||||
writer = manga.author?.let { ComicInfo.Writer(it) },
|
||||
penciller = manga.artist?.let { ComicInfo.Penciller(it) },
|
||||
translator = chapter.scanlator?.let { ComicInfo.Translator(it) },
|
||||
genre = manga.genre?.let { ComicInfo.Genre(it.joinToString()) },
|
||||
publishingStatus = ComicInfo.PublishingStatusTachiyomi(
|
||||
ComicInfoPublishingStatus.toComicInfoValue(manga.status),
|
||||
),
|
||||
categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) },
|
||||
source = ComicInfo.SourceMihon(sourceName),
|
||||
inker = null,
|
||||
colorist = null,
|
||||
letterer = null,
|
||||
coverArtist = null,
|
||||
tags = null,
|
||||
year = date?.year?.let { ComicInfo.Year(it) },
|
||||
month = date?.month?.number?.let { ComicInfo.Month(it) },
|
||||
day = date?.day?.let { ComicInfo.Day(it) },
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user