Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made some changes to ComicInfo metadata #459

Merged
merged 10 commits into from
Feb 29, 2024
11 changes: 9 additions & 2 deletions app/src/main/java/eu/kanade/domain/manga/model/Manga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ fun Manga.hasCustomCover(coverCache: CoverCache = Injekt.get()): Boolean {
/**
* Creates a ComicInfo instance based on the manga and chapter metadata.
*/
fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String, categories: List<String>?) = ComicInfo(
fun getComicInfo(
manga: Manga,
chapter: Chapter,
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 {
Expand All @@ -105,7 +111,7 @@ fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String, categories:
ComicInfo.Number(it.toString())
}
},
web = ComicInfo.Web(chapterUrl),
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) },
Expand All @@ -115,6 +121,7 @@ fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String, categories:
ComicInfoPublishingStatus.toComicInfoValue(manga.status),
),
categories = categories?.let { ComicInfo.CategoriesTachiyomi(it.joinToString()) },
source = ComicInfo.SourceMihon(sourceName),
inker = null,
colorist = null,
letterer = null,
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.domain.track.interactor.GetTracks
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
Expand All @@ -78,6 +79,7 @@ class Downloader(
private val downloadPreferences: DownloadPreferences = Injekt.get(),
private val xml: XML = Injekt.get(),
private val getCategories: GetCategories = Injekt.get(),
private val getTracks: GetTracks = Injekt.get(),
) {

/**
Expand Down Expand Up @@ -626,9 +628,22 @@ class Downloader(
chapter: Chapter,
source: HttpSource,
) {
val chapterUrl = source.getChapterUrl(chapter.toSChapter())
val categories = getCategories.await(manga.id).map { it.name.trim() }.takeUnless { it.isEmpty() }
val comicInfo = getComicInfo(manga, chapter, chapterUrl, categories)
val urls = getTracks.await(manga.id)
.mapNotNull { track ->
track.remoteUrl.takeUnless { url -> url.isBlank() }?.trim()
}
AntsyLich marked this conversation as resolved.
Show resolved Hide resolved
.plus(source.getChapterUrl(chapter.toSChapter()).trim())
.distinct()

val comicInfo = getComicInfo(
manga,
chapter,
urls,
categories,
source.name
)

// Remove the old file
dir.findFile(COMIC_INFO_FILE, true)?.delete()
dir.createFile(COMIC_INFO_FILE)!!.openOutputStream().use {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fun SManga.getComicInfo() = ComicInfo(
coverArtist = null,
tags = null,
categories = null,
source = null,
)

fun SManga.copyFromComicInfo(comicInfo: ComicInfo) {
Expand Down Expand Up @@ -81,6 +82,7 @@ data class ComicInfo(
val web: Web?,
val publishingStatus: PublishingStatusTachiyomi?,
val categories: CategoriesTachiyomi?,
val source: SourceMihon?,
) {
@XmlElement(false)
@XmlSerialName("xmlns:xsd", "", "")
Expand Down Expand Up @@ -154,6 +156,10 @@ data class ComicInfo(
@Serializable
@XmlSerialName("Categories", "http://www.w3.org/2001/XMLSchema", "ty")
data class CategoriesTachiyomi(@XmlValue(true) val value: String = "")

@Serializable
@XmlSerialName("SourceMihon", "http://www.w3.org/2001/XMLSchema", "mh")
data class SourceMihon(@XmlValue(true) val value: String = "")
}

enum class ComicInfoPublishingStatus(
Expand Down
Loading