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.chapter.ChapterRecognition
|
||||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||||
import eu.kanade.tachiyomi.util.storage.EpubFile
|
import eu.kanade.tachiyomi.util.storage.EpubFile
|
||||||
import eu.kanade.tachiyomi.util.storage.fillChapterMetadata
|
import eu.kanade.tachiyomi.util.storage.fillMetadata
|
||||||
import eu.kanade.tachiyomi.util.storage.fillMangaMetadata
|
|
||||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||||
import eu.kanade.tachiyomi.util.system.e
|
import eu.kanade.tachiyomi.util.system.e
|
||||||
import eu.kanade.tachiyomi.util.system.extension
|
import eu.kanade.tachiyomi.util.system.extension
|
||||||
|
@ -306,15 +305,10 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
|
// Copy the cover from the first chapter found.
|
||||||
if (manga.thumbnail_url.isNullOrBlank()) {
|
if (manga.thumbnail_url.isNullOrBlank()) {
|
||||||
chapters.lastOrNull()?.let { chapter ->
|
chapters.lastOrNull()?.let { chapter ->
|
||||||
try {
|
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)
|
updateCover(chapter, manga)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Logger.e(e)
|
Logger.e(e)
|
||||||
|
@ -400,7 +394,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
||||||
}
|
}
|
||||||
is Format.Epub -> {
|
is Format.Epub -> {
|
||||||
EpubFile(format.file.archiveReader(context)).use { epub ->
|
EpubFile(format.file.archiveReader(context)).use { epub ->
|
||||||
epub.fillChapterMetadata(chapter)
|
epub.fillMetadata(chapter, manga)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,37 +7,25 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
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) {
|
fun EpubFile.fillMetadata(chapter: SChapter, 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) {
|
|
||||||
val ref = getPackageHref()
|
val ref = getPackageHref()
|
||||||
val doc = getPackageDocument(ref)
|
val doc = getPackageDocument(ref)
|
||||||
|
|
||||||
val title = doc.getElementsByTag("dc:title").first()
|
val title = doc.getElementsByTag("dc:title").first()
|
||||||
val publisher = doc.getElementsByTag("dc:publisher").first()
|
val publisher = doc.getElementsByTag("dc:publisher").first()
|
||||||
val creator = doc.getElementsByTag("dc:creator").first()
|
val creator = doc.getElementsByTag("dc:creator").first()
|
||||||
|
val description = doc.getElementsByTag("dc:description").first()
|
||||||
var date = doc.getElementsByTag("dc:date").first()
|
var date = doc.getElementsByTag("dc:date").first()
|
||||||
if (date == null) {
|
if (date == null) {
|
||||||
date = doc.select("meta[property=dcterms:modified]").first()
|
date = doc.select("meta[property=dcterms:modified]").first()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title != null) {
|
creator?.text()?.let { manga.author = it }
|
||||||
chapter.name = title.text()
|
description?.text()?.let { manga.description = it}
|
||||||
}
|
|
||||||
|
title?.text()?.let { chapter.name = it }
|
||||||
|
|
||||||
if (publisher != null) {
|
if (publisher != null) {
|
||||||
chapter.scanlator = publisher.text()
|
chapter.scanlator = publisher.text()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue