Better handle decimal chapter numbers and add categories in ComicInfo.xml files (#9604)

* Serialize whole chapter numbers without decimal point and add library categories to genre

* added Tachiyomi specific ComicInfo Category field

* lint

* implemented requested changes
This commit is contained in:
Shamicen 2023-06-23 23:56:01 +02:00 committed by GitHub
parent 25b0458930
commit fcfa62f220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -95,10 +95,16 @@ fun Manga.hasCustomCover(coverCache: CoverCache = Injekt.get()): Boolean {
/** /**
* 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, categories: List<String>?) = ComicInfo(
title = ComicInfo.Title(chapter.name), title = ComicInfo.Title(chapter.name),
series = ComicInfo.Series(manga.title), series = ComicInfo.Series(manga.title),
number = chapter.chapterNumber.takeIf { it >= 0 }?.let { ComicInfo.Number(it.toString()) }, number = chapter.chapterNumber.takeIf { it >= 0 }?.let {
if ((it.rem(1) == 0.0F)) {
ComicInfo.Number(it.toInt().toString())
} else {
ComicInfo.Number(it.toString())
}
},
web = ComicInfo.Web(chapterUrl), web = ComicInfo.Web(chapterUrl),
summary = manga.description?.let { ComicInfo.Summary(it) }, summary = manga.description?.let { ComicInfo.Summary(it) },
writer = manga.author?.let { ComicInfo.Writer(it) }, writer = manga.author?.let { ComicInfo.Writer(it) },
@ -108,6 +114,7 @@ fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String) = ComicInfo
publishingStatus = ComicInfo.PublishingStatusTachiyomi( publishingStatus = ComicInfo.PublishingStatusTachiyomi(
ComicInfoPublishingStatus.toComicInfoValue(manga.status), ComicInfoPublishingStatus.toComicInfoValue(manga.status),
), ),
categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) },
inker = null, inker = null,
colorist = null, colorist = null,
letterer = null, letterer = null,

View File

@ -50,6 +50,7 @@ import tachiyomi.core.util.lang.withIOContext
import tachiyomi.core.util.lang.withUIContext import tachiyomi.core.util.lang.withUIContext
import tachiyomi.core.util.system.ImageUtil import tachiyomi.core.util.system.ImageUtil
import tachiyomi.core.util.system.logcat import tachiyomi.core.util.system.logcat
import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
@ -75,6 +76,7 @@ class Downloader(
private val chapterCache: ChapterCache = Injekt.get(), private val chapterCache: ChapterCache = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(),
private val xml: XML = Injekt.get(), private val xml: XML = Injekt.get(),
private val getCategories: GetCategories = Injekt.get(),
) { ) {
/** /**
@ -621,14 +623,15 @@ class Downloader(
/** /**
* Creates a ComicInfo.xml file inside the given directory. * Creates a ComicInfo.xml file inside the given directory.
*/ */
private fun createComicInfoFile( private suspend fun createComicInfoFile(
dir: UniFile, dir: UniFile,
manga: Manga, manga: Manga,
chapter: Chapter, chapter: Chapter,
source: HttpSource, source: HttpSource,
) { ) {
val chapterUrl = source.getChapterUrl(chapter.toSChapter()) val chapterUrl = source.getChapterUrl(chapter.toSChapter())
val comicInfo = getComicInfo(manga, chapter, chapterUrl) val categories = getCategories.await(manga.id).map { it.name.trim() }.takeUnless { it.isEmpty() }
val comicInfo = getComicInfo(manga, chapter, chapterUrl, categories)
// Remove the old file // Remove the old file
dir.findFile(COMIC_INFO_FILE)?.delete() dir.findFile(COMIC_INFO_FILE)?.delete()
dir.createFile(COMIC_INFO_FILE).openOutputStream().use { dir.createFile(COMIC_INFO_FILE).openOutputStream().use {

View File

@ -16,8 +16,8 @@ fun SManga.copyFromComicInfo(comicInfo: ComicInfo) {
listOfNotNull( listOfNotNull(
comicInfo.genre?.value, comicInfo.genre?.value,
comicInfo.tags?.value, comicInfo.tags?.value,
comicInfo.categories?.value,
) )
.flatMap { it.split(", ") }
.distinct() .distinct()
.joinToString(", ") { it.trim() } .joinToString(", ") { it.trim() }
.takeIf { it.isNotEmpty() } .takeIf { it.isNotEmpty() }
@ -57,6 +57,7 @@ data class ComicInfo(
val tags: Tags?, val tags: Tags?,
val web: Web?, val web: Web?,
val publishingStatus: PublishingStatusTachiyomi?, val publishingStatus: PublishingStatusTachiyomi?,
val categories: CategoriesTachiyomi?,
) { ) {
@Suppress("UNUSED") @Suppress("UNUSED")
@XmlElement(false) @XmlElement(false)
@ -128,6 +129,10 @@ data class ComicInfo(
@Serializable @Serializable
@XmlSerialName("PublishingStatusTachiyomi", "http://www.w3.org/2001/XMLSchema", "ty") @XmlSerialName("PublishingStatusTachiyomi", "http://www.w3.org/2001/XMLSchema", "ty")
data class PublishingStatusTachiyomi(@XmlValue(true) val value: String = "") data class PublishingStatusTachiyomi(@XmlValue(true) val value: String = "")
@Serializable
@XmlSerialName("Categories", "http://www.w3.org/2001/XMLSchema", "ty")
data class CategoriesTachiyomi(@XmlValue(true) val value: String = "")
} }
enum class ComicInfoPublishingStatus( enum class ComicInfoPublishingStatus(