Skip to content

Commit

Permalink
Made some changes to ComicInfo metadata (#459)
Browse files Browse the repository at this point in the history
* Made some changes to ComicInfo metadata

The web field now contains a " " separated list of source and tracker urls.
The translator field will now use the source name if the scanlator field is empty.

* lint

* use already existing source instance

* made translator not nullable

* implemented requested changes

created new Mihon exclusive ComicInfo source field  and populated it with SourceName

reverted previous changes to translator field

* Update core-metadata/src/main/java/tachiyomi/core/metadata/comicinfo/ComicInfo.kt

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* Update app/src/main/java/eu/kanade/domain/manga/model/Manga.kt

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* Update app/src/main/java/eu/kanade/domain/manga/model/Manga.kt

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* Update app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>

* Update app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt

---------

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
  • Loading branch information
Shamicen and AntsyLich authored Feb 29, 2024
1 parent 5859a8b commit 4bfc5e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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()
}
.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

0 comments on commit 4bfc5e7

Please sign in to comment.