This commit is contained in:
kunfei
2023-05-16 23:05:33 +08:00
parent 74f2a3f731
commit 3b71c8e2a8
4 changed files with 21 additions and 3 deletions
+1
View File
@@ -15,6 +15,7 @@
**2023/05/16** **2023/05/16**
* 添加格式化目录规则,只能写js,不用@js:标志,提供变量index和title,index从1开始 * 添加格式化目录规则,只能写js,不用@js:标志,提供变量index和title,index从1开始
* 正文添加标题规则,结果更新到目录,有些网站只能在正文获取正确的标题
**2023/05/13** **2023/05/13**
@@ -11,6 +11,7 @@ import kotlinx.parcelize.Parcelize
@Parcelize @Parcelize
data class ContentRule( data class ContentRule(
var content: String? = null, var content: String? = null,
var title: String? = null, //有些网站只能在正文中获取标题
var nextContentUrl: String? = null, var nextContentUrl: String? = null,
var webJs: String? = null, var webJs: String? = null,
var sourceRegex: String? = null, var sourceRegex: String? = null,
@@ -51,11 +51,25 @@ object BookContent {
val content = StringBuilder() val content = StringBuilder()
val nextUrlList = arrayListOf(redirectUrl) val nextUrlList = arrayListOf(redirectUrl)
val contentRule = bookSource.getContentRule() val contentRule = bookSource.getContentRule()
val analyzeRule = AnalyzeRule(book, bookSource).setContent(body, baseUrl) val analyzeRule = AnalyzeRule(book, bookSource)
analyzeRule.setContent(body, baseUrl)
analyzeRule.setRedirectUrl(redirectUrl) analyzeRule.setRedirectUrl(redirectUrl)
analyzeRule.chapter = bookChapter analyzeRule.chapter = bookChapter
analyzeRule.nextChapterUrl = mNextChapterUrl analyzeRule.nextChapterUrl = mNextChapterUrl
coroutineContext.ensureActive() coroutineContext.ensureActive()
contentRule.title?.let {
if (it.isNotBlank()) {
val title = analyzeRule.runCatching {
getString(it)
}.onFailure { e ->
Debug.log(bookSource.bookSourceUrl, "获取标题出错, ${e.localizedMessage}")
}.getOrNull()
if (!title.isNullOrBlank()) {
bookChapter.title = title
appDb.bookChapterDao.upDate(bookChapter)
}
}
}
var contentData = analyzeContent( var contentData = analyzeContent(
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
) )
@@ -320,6 +320,7 @@ class BookSourceEditActivity :
contentEntities.clear() contentEntities.clear()
contentEntities.apply { contentEntities.apply {
add(EditEntity("content", cr.content, R.string.rule_book_content)) add(EditEntity("content", cr.content, R.string.rule_book_content))
add(EditEntity("title", cr.title, R.string.rule_chapter_name))
add(EditEntity("nextContentUrl", cr.nextContentUrl, R.string.rule_next_content)) add(EditEntity("nextContentUrl", cr.nextContentUrl, R.string.rule_next_content))
add(EditEntity("webJs", cr.webJs, R.string.rule_web_js)) add(EditEntity("webJs", cr.webJs, R.string.rule_web_js))
add(EditEntity("sourceRegex", cr.sourceRegex, R.string.rule_source_regex)) add(EditEntity("sourceRegex", cr.sourceRegex, R.string.rule_source_regex))
@@ -476,10 +477,11 @@ class BookSourceEditActivity :
} }
contentEntities.forEach { contentEntities.forEach {
when (it.key) { when (it.key) {
"content" -> contentRule.content = "content" -> contentRule.content = viewModel.ruleComplete(it.value)
viewModel.ruleComplete(it.value) "title" -> contentRule.title = viewModel.ruleComplete(it.value)
"nextContentUrl" -> contentRule.nextContentUrl = "nextContentUrl" -> contentRule.nextContentUrl =
viewModel.ruleComplete(it.value, type = 2) viewModel.ruleComplete(it.value, type = 2)
"webJs" -> contentRule.webJs = it.value "webJs" -> contentRule.webJs = it.value
"sourceRegex" -> contentRule.sourceRegex = it.value "sourceRegex" -> contentRule.sourceRegex = it.value
"replaceRegex" -> contentRule.replaceRegex = it.value "replaceRegex" -> contentRule.replaceRegex = it.value