This commit is contained in:
kunfei
2022-01-31 11:31:05 +08:00
parent 1192654d43
commit 42fe73ac35
2 changed files with 11 additions and 5 deletions
@@ -11,6 +11,7 @@ import io.legado.app.model.NoStackTraceException
import io.legado.app.model.TocEmptyException import io.legado.app.model.TocEmptyException
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.isTrue
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async import kotlinx.coroutines.async
@@ -23,8 +24,6 @@ import splitties.init.appCtx
*/ */
object BookChapterList { object BookChapterList {
private val falseRegex = "\\s*(?i)(null|false|0)\\s*".toRegex()
suspend fun analyzeChapterList( suspend fun analyzeChapterList(
scope: CoroutineScope, scope: CoroutineScope,
bookSource: BookSource, bookSource: BookSource,
@@ -188,7 +187,7 @@ object BookChapterList {
bookChapter.tag = analyzeRule.getString(upTimeRule) bookChapter.tag = analyzeRule.getString(upTimeRule)
val isVolume = analyzeRule.getString(isVolumeRule) val isVolume = analyzeRule.getString(isVolumeRule)
bookChapter.isVolume = false bookChapter.isVolume = false
if (isVolume.isNotEmpty() && !isVolume.matches(falseRegex)) { if (isVolume.isTrue()) {
bookChapter.isVolume = true bookChapter.isVolume = true
} }
if (bookChapter.url.isEmpty()) { if (bookChapter.url.isEmpty()) {
@@ -203,10 +202,10 @@ object BookChapterList {
if (bookChapter.title.isNotEmpty()) { if (bookChapter.title.isNotEmpty()) {
val isVip = analyzeRule.getString(vipRule) val isVip = analyzeRule.getString(vipRule)
val isPay = analyzeRule.getString(payRule) val isPay = analyzeRule.getString(payRule)
if (isVip.isNotEmpty() && !isVip.matches(falseRegex)) { if (isVip.isTrue()) {
bookChapter.isVip = true bookChapter.isVip = true
} }
if (isPay.isNotEmpty() && !isPay.matches(falseRegex)) { if (isPay.isTrue()) {
bookChapter.isPay = true bookChapter.isPay = true
} }
chapterList.add(bookChapter) chapterList.add(bookChapter)
@@ -53,6 +53,13 @@ fun String?.isXml(): Boolean =
str.startsWith("<") && str.endsWith(">") str.startsWith("<") && str.endsWith(">")
} ?: false } ?: false
fun String?.isTrue(nullIsTrue: Boolean = false): Boolean {
if (this.isNullOrBlank() || this == "null") {
return nullIsTrue
}
return this.matches("\\s*(?i)(true|ok|yes|1)\\s*".toRegex())
}
fun String.splitNotBlank(vararg delimiter: String): Array<String> = run { fun String.splitNotBlank(vararg delimiter: String): Array<String> = run {
this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()
} }