mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor(source/local): Merge epub fill metadata functions
This commit is contained in:
parent
6990bccd02
commit
f7584b1d5b
2 changed files with 10 additions and 28 deletions
|
@ -12,8 +12,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
|
||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||
import eu.kanade.tachiyomi.util.storage.EpubFile
|
||||
import eu.kanade.tachiyomi.util.storage.fillChapterMetadata
|
||||
import eu.kanade.tachiyomi.util.storage.fillMangaMetadata
|
||||
import eu.kanade.tachiyomi.util.storage.fillMetadata
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.system.e
|
||||
import eu.kanade.tachiyomi.util.system.extension
|
||||
|
@ -306,15 +305,10 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
}
|
||||
.toList()
|
||||
|
||||
// Copy the cover from the first chapter found.
|
||||
if (manga.thumbnail_url.isNullOrBlank()) {
|
||||
chapters.lastOrNull()?.let { chapter ->
|
||||
try {
|
||||
val format = getFormat(chapter)
|
||||
if (format is Format.Epub)
|
||||
EpubFile(format.file.archiveReader(context)).use { epub ->
|
||||
epub.fillMangaMetadata(manga)
|
||||
}
|
||||
// Copy the cover from the first chapter found.
|
||||
updateCover(chapter, manga)
|
||||
} catch (e: Exception) {
|
||||
Logger.e(e)
|
||||
|
@ -400,7 +394,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
}
|
||||
is Format.Epub -> {
|
||||
EpubFile(format.file.archiveReader(context)).use { epub ->
|
||||
epub.fillChapterMetadata(chapter)
|
||||
epub.fillMetadata(chapter, manga)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
@ -7,37 +7,25 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
|
||||
/**
|
||||
* Fills manga metadata using this epub file's metadata.
|
||||
* Fills manga and chapter metadata using this epub file's metadata.
|
||||
*/
|
||||
fun EpubFile.fillMangaMetadata(manga: SManga) {
|
||||
val ref = getPackageHref()
|
||||
val doc = getPackageDocument(ref)
|
||||
|
||||
val creator = doc.getElementsByTag("dc:creator").first()
|
||||
val description = doc.getElementsByTag("dc:description").first()
|
||||
|
||||
manga.author = creator?.text()
|
||||
manga.description = description?.text()
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills chapter metadata using this epub file's metadata.
|
||||
*/
|
||||
fun EpubFile.fillChapterMetadata(chapter: SChapter) {
|
||||
fun EpubFile.fillMetadata(chapter: SChapter, manga: SManga) {
|
||||
val ref = getPackageHref()
|
||||
val doc = getPackageDocument(ref)
|
||||
|
||||
val title = doc.getElementsByTag("dc:title").first()
|
||||
val publisher = doc.getElementsByTag("dc:publisher").first()
|
||||
val creator = doc.getElementsByTag("dc:creator").first()
|
||||
val description = doc.getElementsByTag("dc:description").first()
|
||||
var date = doc.getElementsByTag("dc:date").first()
|
||||
if (date == null) {
|
||||
date = doc.select("meta[property=dcterms:modified]").first()
|
||||
}
|
||||
|
||||
if (title != null) {
|
||||
chapter.name = title.text()
|
||||
}
|
||||
creator?.text()?.let { manga.author = it }
|
||||
description?.text()?.let { manga.description = it}
|
||||
|
||||
title?.text()?.let { chapter.name = it }
|
||||
|
||||
if (publisher != null) {
|
||||
chapter.scanlator = publisher.text()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue