pull/1352/head
gedoor 3 years ago
parent da947511d4
commit 9e1ed46a22
  1. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 13
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 4
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  4. 4
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  5. 4
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  6. 12
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  7. 4
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -654,7 +654,7 @@ class AnalyzeRule(
override fun ajax(urlStr: String): String? { override fun ajax(urlStr: String): String? {
return runBlocking { return runBlocking {
kotlin.runCatching { kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source) val analyzeUrl = AnalyzeUrl(urlStr, source = source, ruleData = book)
analyzeUrl.getStrResponse().body analyzeUrl.getStrResponse().body
}.onFailure { }.onFailure {
log("ajax(${urlStr}) error\n${it.stackTraceToString()}") log("ajax(${urlStr}) error\n${it.stackTraceToString()}")

@ -7,8 +7,8 @@ import com.bumptech.glide.load.model.LazyHeaders
import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.AppConst.UA_NAME import io.legado.app.constant.AppConst.UA_NAME
import io.legado.app.constant.AppPattern.JS_PATTERN import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BaseSource
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
@ -36,10 +36,9 @@ class AnalyzeUrl(
val speakText: String? = null, val speakText: String? = null,
val speakSpeed: Int? = null, val speakSpeed: Int? = null,
var baseUrl: String = "", var baseUrl: String = "",
val book: BaseBook? = null,
val chapter: BookChapter? = null,
private val ruleData: RuleDataInterface? = null,
private val source: BaseSource? = null, private val source: BaseSource? = null,
private val ruleData: RuleDataInterface? = null,
private val chapter: BookChapter? = null,
headerMapF: Map<String, String>? = null, headerMapF: Map<String, String>? = null,
) : JsExtensions { ) : JsExtensions {
companion object { companion object {
@ -239,7 +238,7 @@ class AnalyzeUrl(
bindings["key"] = key bindings["key"] = key
bindings["speakText"] = speakText bindings["speakText"] = speakText
bindings["speakSpeed"] = speakSpeed bindings["speakSpeed"] = speakSpeed
bindings["book"] = book bindings["book"] = ruleData as? Book
bindings["source"] = source bindings["source"] = source
bindings["result"] = result bindings["result"] = result
return SCRIPT_ENGINE.eval(jsStr, bindings) return SCRIPT_ENGINE.eval(jsStr, bindings)
@ -247,14 +246,13 @@ class AnalyzeUrl(
fun put(key: String, value: String): String { fun put(key: String, value: String): String {
chapter?.putVariable(key, value) chapter?.putVariable(key, value)
?: book?.putVariable(key, value)
?: ruleData?.putVariable(key, value) ?: ruleData?.putVariable(key, value)
return value return value
} }
fun get(key: String): String { fun get(key: String): String {
when (key) { when (key) {
"bookName" -> book?.let { "bookName" -> (ruleData as? Book)?.let {
return it.name return it.name
} }
"title" -> chapter?.let { "title" -> chapter?.let {
@ -262,7 +260,6 @@ class AnalyzeUrl(
} }
} }
return chapter?.variableMap?.get(key) return chapter?.variableMap?.get(key)
?: book?.variableMap?.get(key)
?: ruleData?.variableMap?.get(key) ?: ruleData?.variableMap?.get(key)
?: "" ?: ""
} }

@ -38,8 +38,8 @@ object Rss {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
sortUrl, sortUrl,
page = page, page = page,
ruleData = ruleData,
source = rssSource, source = rssSource,
ruleData = ruleData,
headerMapF = rssSource.getHeaderMap() headerMapF = rssSource.getHeaderMap()
) )
val body = analyzeUrl.getStrResponse().body val body = analyzeUrl.getStrResponse().body
@ -66,8 +66,8 @@ object Rss {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
rssArticle.link, rssArticle.link,
baseUrl = rssArticle.origin, baseUrl = rssArticle.origin,
ruleData = rssArticle,
source = rssSource, source = rssSource,
ruleData = rssArticle,
headerMapF = rssSource.getHeaderMap() headerMapF = rssSource.getHeaderMap()
) )
val body = analyzeUrl.getStrResponse().body val body = analyzeUrl.getStrResponse().body

@ -64,8 +64,8 @@ object BookChapterList {
nextUrlList.add(nextUrl) nextUrlList.add(nextUrl)
AnalyzeUrl( AnalyzeUrl(
ruleUrl = nextUrl, ruleUrl = nextUrl,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getStrResponse().body?.let { nextBody -> ).getStrResponse().body?.let { nextBody ->
chapterData = analyzeChapterList( chapterData = analyzeChapterList(
@ -86,8 +86,8 @@ object BookChapterList {
val urlStr = chapterData.second[it] val urlStr = chapterData.second[it]
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = urlStr, ruleUrl = urlStr,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val res = analyzeUrl.getStrResponse() val res = analyzeUrl.getStrResponse()

@ -69,8 +69,8 @@ object BookContent {
scope.ensureActive() scope.ensureActive()
val res = AnalyzeUrl( val res = AnalyzeUrl(
ruleUrl = nextUrl, ruleUrl = nextUrl,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getStrResponse() ).getStrResponse()
res.body?.let { nextBody -> res.body?.let { nextBody ->
@ -92,8 +92,8 @@ object BookContent {
val urlStr = contentData.second[it] val urlStr = contentData.second[it]
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = urlStr, ruleUrl = urlStr,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val res = analyzeUrl.getStrResponse() val res = analyzeUrl.getStrResponse()

@ -71,8 +71,8 @@ object WebBook {
page = page, page = page,
baseUrl = bookSource.bookSourceUrl, baseUrl = bookSource.bookSourceUrl,
headerMapF = bookSource.getHeaderMap(true), headerMapF = bookSource.getHeaderMap(true),
book = variableBook, source = bookSource,
source = bookSource ruleData = variableBook,
) )
var res = analyzeUrl.getStrResponse() var res = analyzeUrl.getStrResponse()
//检测书源是否已登录 //检测书源是否已登录
@ -120,8 +120,8 @@ object WebBook {
ruleUrl = url, ruleUrl = url,
page = page, page = page,
baseUrl = bookSource.bookSourceUrl, baseUrl = bookSource.bookSourceUrl,
book = variableBook,
source = bookSource, source = bookSource,
ruleData = variableBook,
headerMapF = bookSource.getHeaderMap(true) headerMapF = bookSource.getHeaderMap(true)
) )
var res = analyzeUrl.getStrResponse() var res = analyzeUrl.getStrResponse()
@ -178,8 +178,8 @@ object WebBook {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = book.bookUrl, ruleUrl = book.bookUrl,
baseUrl = bookSource.bookSourceUrl, baseUrl = bookSource.bookSourceUrl,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap(true) headerMapF = bookSource.getHeaderMap(true)
) )
var res = analyzeUrl.getStrResponse() var res = analyzeUrl.getStrResponse()
@ -235,8 +235,8 @@ object WebBook {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = book.tocUrl, ruleUrl = book.tocUrl,
baseUrl = book.bookUrl, baseUrl = book.bookUrl,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
headerMapF = bookSource.getHeaderMap(true) headerMapF = bookSource.getHeaderMap(true)
) )
var res = analyzeUrl.getStrResponse() var res = analyzeUrl.getStrResponse()
@ -299,8 +299,8 @@ object WebBook {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
ruleUrl = bookChapter.getAbsoluteURL(), ruleUrl = bookChapter.getAbsoluteURL(),
baseUrl = book.tocUrl, baseUrl = book.tocUrl,
book = book,
source = bookSource, source = bookSource,
ruleData = book,
chapter = bookChapter, chapter = bookChapter,
headerMapF = bookSource.getHeaderMap(true) headerMapF = bookSource.getHeaderMap(true)
) )

@ -130,8 +130,10 @@ class AudioPlayService : BaseService(),
upPlayProgressJob?.cancel() upPlayProgressJob?.cancel()
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
url, url,
source = AudioPlay.bookSource,
ruleData = AudioPlay.book,
chapter = AudioPlay.durChapter,
headerMapF = AudioPlay.headers(true), headerMapF = AudioPlay.headers(true),
source = AudioPlay.bookSource
) )
val uri = Uri.parse(analyzeUrl.url) val uri = Uri.parse(analyzeUrl.url)
val mediaSource = ExoPlayerHelper val mediaSource = ExoPlayerHelper

Loading…
Cancel
Save