🛠️ Fix some books cannot parse in EPUB

* Fixed the scenario when the book has "volume.opf" instead of "content.opf"
This commit is contained in:
Acclorite 2024-11-16 10:24:00 +02:00
parent a3a18e78a5
commit 0077241595
2 changed files with 3 additions and 3 deletions

View file

@ -24,7 +24,7 @@ class EpubFileParser @Inject constructor() : FileParser {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
ZipFile(file).use { zip -> ZipFile(file).use { zip ->
val opfEntry = zip.entries().asSequence().find { entry -> val opfEntry = zip.entries().asSequence().find { entry ->
entry.name.endsWith("content.opf") entry.name.endsWith(".opf", ignoreCase = true)
} ?: return@withContext } ?: return@withContext
val opfContent = zip val opfContent = zip

View file

@ -51,14 +51,14 @@ class EpubTextParser @Inject constructor(
entry.name.endsWith("toc.ncx", ignoreCase = true) entry.name.endsWith("toc.ncx", ignoreCase = true)
} }
val opfEntry = zip.entries().toList().find { entry -> val opfEntry = zip.entries().toList().find { entry ->
entry.name.endsWith("content.opf", ignoreCase = true) entry.name.endsWith(".opf", ignoreCase = true)
} }
val chapterEntries = zip.getChapterEntries(opfEntry) val chapterEntries = zip.getChapterEntries(opfEntry)
val chapterTitleEntries = zip.getChapterTitleMapFromToc(tocEntry) val chapterTitleEntries = zip.getChapterTitleMapFromToc(tocEntry)
Log.i(EPUB_TAG, "TOC Entry: ${tocEntry?.name ?: "no toc.ncx"}") Log.i(EPUB_TAG, "TOC Entry: ${tocEntry?.name ?: "no toc.ncx"}")
Log.i(EPUB_TAG, "OPF Entry: ${opfEntry?.name ?: "no content.opf"}") Log.i(EPUB_TAG, "OPF Entry: ${opfEntry?.name ?: "no .opf entry"}")
Log.i(EPUB_TAG, "Chapter entries, size: ${chapterEntries.size}") Log.i(EPUB_TAG, "Chapter entries, size: ${chapterEntries.size}")
Log.i(EPUB_TAG, "Title entries, size: ${chapterTitleEntries?.size}") Log.i(EPUB_TAG, "Title entries, size: ${chapterTitleEntries?.size}")