|
@@ -92,7 +92,7 @@ class EpubFile(var book: Book) {
|
|
|
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
|
cover.compress(Bitmap.CompressFormat.JPEG, 90, out)
|
|
|
out.flush()
|
|
out.flush()
|
|
|
out.close()
|
|
out.close()
|
|
|
- }
|
|
|
|
|
|
|
+ } ?: AppLog.putDebug("Epub: 封面获取为空. path: ${book.bookUrl}")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
@@ -131,25 +131,34 @@ class EpubFile(var book: Book) {
|
|
|
val startFragmentId = chapter.startFragmentId
|
|
val startFragmentId = chapter.startFragmentId
|
|
|
val endFragmentId = chapter.endFragmentId
|
|
val endFragmentId = chapter.endFragmentId
|
|
|
val elements = Elements()
|
|
val elements = Elements()
|
|
|
- var isChapter = false
|
|
|
|
|
|
|
+ var hasMoreResources = false
|
|
|
|
|
+ val includeNextChapterResource = !endFragmentId.isNullOrBlank()
|
|
|
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
|
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
|
|
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
|
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
|
|
for (res in epubBook.contents) {
|
|
for (res in epubBook.contents) {
|
|
|
- if (chapter.url.substringBeforeLast("#") == res.href) {
|
|
|
|
|
- elements.add(getBody(res, startFragmentId, endFragmentId))
|
|
|
|
|
- isChapter = true
|
|
|
|
|
- /**
|
|
|
|
|
- * fix https://github.com/gedoor/legado/issues/1927 加载全部内容的bug
|
|
|
|
|
- * content src text/000001.html(当前章节)
|
|
|
|
|
- - * content src text/000001.html#toc_id_x (下一章节)
|
|
|
|
|
- */
|
|
|
|
|
- if (res.href == nextUrl?.substringBeforeLast("#")) break
|
|
|
|
|
- } else if (isChapter) {
|
|
|
|
|
- // fix 最后一章存在多个html时 内容缺失
|
|
|
|
|
- if (res.href == nextUrl?.substringBeforeLast("#")) {
|
|
|
|
|
|
|
+ val isFirstResource = chapter.url.substringBeforeLast("#") == res.href
|
|
|
|
|
+ val isNextChapterResource = res.href == nextUrl?.substringBeforeLast("#")
|
|
|
|
|
+ if (isFirstResource) {
|
|
|
|
|
+ // add first resource to elements
|
|
|
|
|
+ elements.add(
|
|
|
|
|
+ /* pass endFragmentId if only has one resource */
|
|
|
|
|
+ getBody(res, startFragmentId, endFragmentId)
|
|
|
|
|
+ )
|
|
|
|
|
+ // check current resource
|
|
|
|
|
+ if (isNextChapterResource) {
|
|
|
|
|
+ /* FragmentId should not be same in same resource */
|
|
|
|
|
+ if (!endFragmentId.isNullOrBlank() && endFragmentId == startFragmentId)
|
|
|
|
|
+ AppLog.putDebug("Epub: Resource (${res.href}) has same FragmentId, check the file: ${book.bookUrl}")
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ hasMoreResources = true
|
|
|
|
|
+ } else if (hasMoreResources) {
|
|
|
|
|
+ if (isNextChapterResource) {
|
|
|
|
|
+ if (includeNextChapterResource) elements.add(getBody(res, null/* FragmentId may be same in different resources, pass null */, endFragmentId))
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
- elements.add(getBody(res, startFragmentId, endFragmentId))
|
|
|
|
|
|
|
+ // rest resource should not have fragmentId, pass null
|
|
|
|
|
+ elements.add(getBody(res, null, null))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//title标签中的内容不需要显示在正文中,去除
|
|
//title标签中的内容不需要显示在正文中,去除
|
|
@@ -226,7 +235,7 @@ class EpubFile(var book: Book) {
|
|
|
epubBook?.let { eBook ->
|
|
epubBook?.let { eBook ->
|
|
|
val refs = eBook.tableOfContents.tocReferences
|
|
val refs = eBook.tableOfContents.tocReferences
|
|
|
if (refs == null || refs.isEmpty()) {
|
|
if (refs == null || refs.isEmpty()) {
|
|
|
- AppLog.put("NCX file parse error, check the epub file")
|
|
|
|
|
|
|
+ AppLog.putDebug("Epub: NCX file parse error, check the file: ${book.bookUrl}")
|
|
|
val spineReferences = eBook.spine.spineReferences
|
|
val spineReferences = eBook.spine.spineReferences
|
|
|
var i = 0
|
|
var i = 0
|
|
|
val size = spineReferences.size
|
|
val size = spineReferences.size
|
|
@@ -340,4 +349,4 @@ class EpubFile(var book: Book) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+}
|