Merge pull request #1591 from Xwite/master

书源校验分组提示优化
pull/1592/head
kunfei 3 years ago committed by GitHub
commit f744e19f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/assets/help/SourceMBookHelp.md
  2. 1
      app/src/main/assets/help/SourceMRssHelp.md
  3. 6
      app/src/main/assets/updateLog.md
  4. 12
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  5. 8
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  6. 5
      app/src/main/java/io/legado/app/model/Debug.kt
  7. 4
      app/src/main/java/io/legado/app/model/localBook/TextFile.kt
  8. 29
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt

@ -22,4 +22,4 @@
* 置底所选
* 导出所选
* 校验所选
* 校验失败的书源分组会加上"失效",选择"失效"分组即可批量操作
* "校验成功"是指所选的校验项目全部通过,"失败:发现为空"不视为"失效",校验结束后会自动筛选"失效"书源

@ -18,4 +18,3 @@
* 置顶所选
* 置底所选
* 导出所选
* 校验失败的书源分组会加上"失效",选择"失效"分组即可批量操作

@ -11,6 +11,12 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2022/02/07**
* 校验失效分组具体到搜索发现目录正文
* txt文件初次解析目录不选择禁用的正则
* txt单章字数超102400均分txt
**2022/02/03**
* 字符串大于1024时禁用代码高亮

@ -81,6 +81,12 @@ data class BookChapter(
): String {
var displayTitle = title.replace(AppPattern.rnRegex, "")
val mDisplayTitle = displayTitle
if (chineseConvert) {
when (AppConfig.chineseConverterType) {
1 -> displayTitle = ChineseUtils.t2s(displayTitle)
2 -> displayTitle = ChineseUtils.s2t(displayTitle)
}
}
if (useReplace && replaceRules != null) {
replaceRules.forEach { item ->
if (item.pattern.isNotEmpty()) {
@ -97,12 +103,6 @@ data class BookChapter(
}
}
if (displayTitle.isBlank()) displayTitle = mDisplayTitle
if (chineseConvert) {
when (AppConfig.chineseConverterType) {
1 -> displayTitle = ChineseUtils.t2s(displayTitle)
2 -> displayTitle = ChineseUtils.s2t(displayTitle)
}
}
return when {
!isVip -> displayTitle
isPay -> appCtx.getString(R.string.payed_title, displayTitle)

@ -77,10 +77,6 @@ class ContentProcessor private constructor(
//重新分段
mContent = ContentHelp.reSegment(mContent, chapter.title)
}
if (useReplace && book.getUseReplaceRule()) {
//替换
mContent = replaceContent(mContent)
}
if (chineseConvert) {
//简繁转换
try {
@ -92,6 +88,10 @@ class ContentProcessor private constructor(
appCtx.toastOnUi("简繁转换出错")
}
}
if (useReplace && book.getUseReplaceRule()) {
//替换
mContent = replaceContent(mContent)
}
if (includeTitle) {
//重新添加标题
mContent = chapter.getDisplayTitle(getReplaceRules()) + "\n" + mContent

@ -95,10 +95,9 @@ object Debug {
fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!!
debugTimeMap[sourceUrl] = if (state == "成功") spendingTime else 180000L
debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else 180000L
val printTime = debugTimeFormat.format(Date(spendingTime))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$printTime $originalMessage $state"
debugMessageMap[sourceUrl] = "$printTime $state"
}
}

@ -45,6 +45,8 @@ class TextFile(private val book: Book) {
//没有标题的时候,每个章节的最大长度
private val maxLengthWithNoToc = 10 * 1024
//使用正则划分目录,每个章节的最大允许长度
private val maxLengthWithToc = 102400
private val tocRules = arrayListOf<Pattern>()
private var charset: Charset = book.fileCharset()
@ -126,7 +128,7 @@ class TextFile(private val book: Book) {
val chapterContent = blockContent.substring(seekPos, chapterStart)
val chapterLength = chapterContent.toByteArray(charset).size
val lastStart = toc.lastOrNull()?.start ?: curOffset
if (curOffset + chapterLength - lastStart > 102400) {
if (curOffset + chapterLength - lastStart > maxLengthWithToc) {
bis.close()
return analyze()
}

@ -15,6 +15,8 @@ import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.CheckSource
import io.legado.app.model.Debug
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ContentEmptyException
import io.legado.app.model.TocEmptyException
import io.legado.app.model.webBook.WebBook
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.activityPendingIntent
@ -121,6 +123,11 @@ class CheckSourceService : BaseService() {
searchWord = it
}
}
source.bookSourceComment = source.bookSourceComment
?.split("\n\n")
?.filterNot {
it.startsWith("Error: ")
}?.joinToString("\n")
//校验搜索 用户设置校验搜索 并且 搜索链接不为空
if (CheckSource.checkSearch && !source.searchUrl.isNullOrBlank()) {
val searchBooks = WebBook.searchBookAwait(this, source, searchWord)
@ -173,9 +180,10 @@ class CheckSourceService : BaseService() {
if (CheckSource.checkCategory) {
val toc = WebBook.getChapterListAwait(this, source, book)
val nextChapterUrl = toc.getOrNull(1)?.url ?: toc.first().url
source.removeGroup("目录失效")
//校验正文
if (CheckSource.checkContent) {
val content = WebBook.getContentAwait(
WebBook.getContentAwait(
this,
bookSource = source,
book = book,
@ -183,9 +191,7 @@ class CheckSourceService : BaseService() {
nextChapterUrl = nextChapterUrl,
needSave = false
)
if ( !toc.first().isVolume && content.isBlank()) {
throw NoStackTraceException("正文内容为空")
}
source.removeGroup("正文失效")
}
}
}
@ -193,20 +199,15 @@ class CheckSourceService : BaseService() {
if (source.hasGroup("发现失效")) throw NoStackTraceException("发现失效")
}.timeout(CheckSource.timeout)
.onError(searchCoroutine) {
source.addGroup("失效")
if (source.bookSourceComment?.contains("Error: ") == false) {
when(it) {
is ContentEmptyException -> source.addGroup("正文失效")
is TocEmptyException -> source.addGroup("目录失效")
}
source.bookSourceComment =
"Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}"
}
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}")
}.onSuccess(searchCoroutine) {
source.removeGroup("失效")
source.bookSourceComment = source.bookSourceComment
?.split("\n\n")
?.filterNot {
it.startsWith("Error: ")
}?.joinToString("\n")
Debug.updateFinalMessage(source.bookSourceUrl, "成功")
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
}.onFinally(searchCoroutine) {
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)

@ -92,7 +92,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
var isFinalMessage =
ivDebugText.text.toString().contains(Regex("成功|失败"))
if (!isEmpty && !Debug.isChecking && !isFinalMessage) {
Debug.updateFinalMessage(item.bookSourceUrl, "失败")
Debug.updateFinalMessage(item.bookSourceUrl, "校验失败")
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
isFinalMessage = true
}

Loading…
Cancel
Save