Clean up ComicInfo stuff a bit more

This commit is contained in:
arkon 2022-11-13 12:01:19 -05:00
parent 4f00af3173
commit 6017229d1b
2 changed files with 55 additions and 52 deletions

View File

@ -12,8 +12,7 @@ const val COMIC_INFO_FILE = "ComicInfo.xml"
/** /**
* Creates a ComicInfo instance based on the manga and chapter metadata. * Creates a ComicInfo instance based on the manga and chapter metadata.
*/ */
fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String): ComicInfo { fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String) = ComicInfo(
return ComicInfo(
title = ComicInfo.Title(chapter.name), title = ComicInfo.Title(chapter.name),
series = ComicInfo.Series(manga.title), series = ComicInfo.Series(manga.title),
web = ComicInfo.Web(chapterUrl), web = ComicInfo.Web(chapterUrl),
@ -22,15 +21,45 @@ fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String): ComicInfo
penciller = manga.artist?.let { ComicInfo.Penciller(it) }, penciller = manga.artist?.let { ComicInfo.Penciller(it) },
translator = chapter.scanlator?.let { ComicInfo.Translator(it) }, translator = chapter.scanlator?.let { ComicInfo.Translator(it) },
genre = manga.genre?.let { ComicInfo.Genre(it.joinToString()) }, genre = manga.genre?.let { ComicInfo.Genre(it.joinToString()) },
publishingStatusTachiyomi = ComicInfo.PublishingStatusTachiyomi( publishingStatus = ComicInfo.PublishingStatusTachiyomi(
ComicInfoPublishingStatusMap.toComicInfoValue(manga.status), ComicInfoPublishingStatus.toComicInfoValue(manga.status),
), ),
inker = null, inker = null,
colorist = null, colorist = null,
letterer = null, letterer = null,
coverArtist = null, coverArtist = null,
tags = null, tags = null,
)
fun SManga.copyFromComicInfo(comicInfo: ComicInfo) {
comicInfo.series?.let { title = it.value }
comicInfo.writer?.let { author = it.value }
comicInfo.summary?.let { description = it.value }
listOfNotNull(
comicInfo.genre?.value,
comicInfo.tags?.value,
) )
.flatMap { it.split(", ") }
.distinct()
.joinToString(", ") { it.trim() }
.takeIf { it.isNotEmpty() }
?.let { genre = it }
listOfNotNull(
comicInfo.penciller?.value,
comicInfo.inker?.value,
comicInfo.colorist?.value,
comicInfo.letterer?.value,
comicInfo.coverArtist?.value,
)
.flatMap { it.split(", ") }
.distinct()
.joinToString(", ") { it.trim() }
.takeIf { it.isNotEmpty() }
?.let { artist = it }
status = ComicInfoPublishingStatus.toSMangaValue(comicInfo.publishingStatus?.value)
} }
@Serializable @Serializable
@ -49,7 +78,7 @@ data class ComicInfo(
val genre: Genre?, val genre: Genre?,
val tags: Tags?, val tags: Tags?,
val web: Web?, val web: Web?,
val publishingStatusTachiyomi: PublishingStatusTachiyomi?, val publishingStatus: PublishingStatusTachiyomi?,
) { ) {
@Suppress("UNUSED") @Suppress("UNUSED")
@XmlElement(false) @XmlElement(false)
@ -119,7 +148,7 @@ data class ComicInfo(
data class PublishingStatusTachiyomi(@XmlValue(true) val value: String = "") data class PublishingStatusTachiyomi(@XmlValue(true) val value: String = "")
} }
enum class ComicInfoPublishingStatusMap( private enum class ComicInfoPublishingStatus(
val comicInfoValue: String, val comicInfoValue: String,
val sMangaModelValue: Int, val sMangaModelValue: Int,
) { ) {
@ -129,17 +158,18 @@ enum class ComicInfoPublishingStatusMap(
PUBLISHING_FINISHED("Publishing finished", SManga.PUBLISHING_FINISHED), PUBLISHING_FINISHED("Publishing finished", SManga.PUBLISHING_FINISHED),
CANCELLED("Cancelled", SManga.CANCELLED), CANCELLED("Cancelled", SManga.CANCELLED),
ON_HIATUS("On hiatus", SManga.ON_HIATUS), ON_HIATUS("On hiatus", SManga.ON_HIATUS),
UNKNOWN("Unknown", SManga.UNKNOWN),
; ;
companion object { companion object {
fun toComicInfoValue(value: Long): String { fun toComicInfoValue(value: Long): String {
return values().firstOrNull { it.sMangaModelValue == value.toInt() }?.comicInfoValue return values().firstOrNull { it.sMangaModelValue == value.toInt() }?.comicInfoValue
?: "Unknown" ?: UNKNOWN.comicInfoValue
} }
fun toSMangaValue(value: String?): Int { fun toSMangaValue(value: String?): Int {
return values().firstOrNull { it.comicInfoValue == value }?.sMangaModelValue return values().firstOrNull { it.comicInfoValue == value }?.sMangaModelValue
?: SManga.UNKNOWN ?: UNKNOWN.sMangaModelValue
} }
} }
} }

View File

@ -5,7 +5,7 @@ import com.github.junrar.Archive
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.domain.manga.model.COMIC_INFO_FILE import eu.kanade.domain.manga.model.COMIC_INFO_FILE
import eu.kanade.domain.manga.model.ComicInfo import eu.kanade.domain.manga.model.ComicInfo
import eu.kanade.domain.manga.model.ComicInfoPublishingStatusMap import eu.kanade.domain.manga.model.copyFromComicInfo
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
@ -245,34 +245,7 @@ class LocalSource(
xml.decodeFromReader<ComicInfo>(it) xml.decodeFromReader<ComicInfo>(it)
} }
comicInfo.series?.let { manga.title = it.value } manga.copyFromComicInfo(comicInfo)
comicInfo.writer?.let { manga.author = it.value }
comicInfo.summary?.let { manga.description = it.value }
listOfNotNull(
comicInfo.genre?.value,
comicInfo.tags?.value,
)
.flatMap { it.split(", ") }
.distinct()
.joinToString(", ") { it.trim() }
.takeIf { it.isNotEmpty() }
?.let { manga.genre = it }
listOfNotNull(
comicInfo.penciller?.value,
comicInfo.inker?.value,
comicInfo.colorist?.value,
comicInfo.letterer?.value,
comicInfo.coverArtist?.value,
)
.flatMap { it.split(", ") }
.distinct()
.joinToString(", ") { it.trim() }
.takeIf { it.isNotEmpty() }
?.let { manga.artist = it }
manga.status = ComicInfoPublishingStatusMap.toSMangaValue(comicInfo.publishingStatusTachiyomi?.value)
} }
@Serializable @Serializable