add redirectUrl

pull/871/head^2
gedoor 4 years ago
parent 7e450c5078
commit f3645ac25f
  1. 18
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 1
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 34
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  4. 1
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  5. 4
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  6. 1
      app/src/main/java/io/legado/app/model/webBook/BookList.kt
  7. 29
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@ -30,7 +30,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
var nextChapterUrl: String? = null
private var content: Any? = null
private var baseUrl: String? = null
private var baseURL: URL? = null
private var redirectUrl: URL? = null
private var isJSON: Boolean = false
private var isRegex: Boolean = false
@ -63,11 +63,13 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
fun setBaseUrl(baseUrl: String?): AnalyzeRule {
baseUrl?.let {
this.baseUrl = baseUrl
kotlin.runCatching {
baseURL = URL(baseUrl.substringBefore(","))
}.onFailure {
it.printStackTrace()
}
}
return this
}
fun setRedirectUrl(url: String): AnalyzeRule {
kotlin.runCatching {
redirectUrl = URL(url.split(AnalyzeUrl.splitUrlRegex, 1)[0])
}
return this
}
@ -170,7 +172,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
val urlList = ArrayList<String>()
if (result is List<*>) {
for (url in result as List<*>) {
val absoluteURL = NetworkUtils.getAbsoluteURL(baseURL, url.toString())
val absoluteURL = NetworkUtils.getAbsoluteURL(redirectUrl, url.toString())
if (absoluteURL.isNotEmpty() && !urlList.contains(absoluteURL)) {
urlList.add(absoluteURL)
}
@ -239,7 +241,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
return if (str.isBlank()) {
baseUrl ?: ""
} else {
NetworkUtils.getAbsoluteURL(baseURL, str)
NetworkUtils.getAbsoluteURL(redirectUrl, str)
}
}
return str

@ -39,6 +39,7 @@ object RssParserByRule {
val articleList = mutableListOf<RssArticle>()
val analyzeRule = AnalyzeRule(ruleData)
analyzeRule.setContent(body).setBaseUrl(sortUrl)
analyzeRule.setRedirectUrl(sortUrl)
var reverse = false
if (ruleArticles.startsWith("-")) {
reverse = true

@ -24,7 +24,8 @@ object BookChapterList {
book: Book,
body: String?,
bookSource: BookSource,
baseUrl: String
baseUrl: String,
redirectUrl: String
): List<BookChapter> = suspendCancellableCoroutine { block ->
kotlin.runCatching {
val chapterList = ArrayList<BookChapter>()
@ -46,7 +47,15 @@ object BookChapterList {
}
var chapterData =
analyzeChapterList(
scope, book, baseUrl, body, tocRule, listRule, bookSource, log = true
scope,
book,
baseUrl,
redirectUrl,
body,
tocRule,
listRule,
bookSource,
log = true
)
chapterData.chapterList?.let {
chapterList.addAll(it)
@ -66,7 +75,14 @@ object BookChapterList {
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody ->
chapterData = analyzeChapterList(
this, book, nextUrl, nextBody, tocRule, listRule, bookSource
this,
book,
nextUrl,
nextUrl,
nextBody,
tocRule,
listRule,
bookSource
)
nextUrl = chapterData.nextUrl.firstOrNull() ?: ""
chapterData.chapterList?.let {
@ -128,7 +144,15 @@ object BookChapterList {
).getStrResponse(bookSource.bookSourceUrl).body
?: throw Exception("${chapterData.nextUrl}, 下载失败")
val nextChapterData = analyzeChapterList(
this, book, chapterData.nextUrl, nextBody, tocRule, listRule, bookSource, false
this,
book,
chapterData.nextUrl,
chapterData.nextUrl,
nextBody,
tocRule,
listRule,
bookSource,
false
)
synchronized(chapterDataList) {
val isFinished = addChapterListIsFinish(
@ -195,6 +219,7 @@ object BookChapterList {
scope: CoroutineScope,
book: Book,
baseUrl: String,
redirectUrl: String,
body: String,
tocRule: TocRule,
listRule: String,
@ -204,6 +229,7 @@ object BookChapterList {
): ChapterData<List<String>> {
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.setRedirectUrl(redirectUrl)
//获取目录列表
val chapterList = arrayListOf<BookChapter>()
Debug.log(bookSource.bookSourceUrl, "┌获取目录列表", log)

@ -41,6 +41,7 @@ object BookContent {
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
val analyzeRule = AnalyzeRule(book).setContent(body, baseUrl)
analyzeRule.setRedirectUrl(baseUrl)
analyzeRule.nextChapterUrl = mNextChapterUrl
var contentData = analyzeContent(
book, baseUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl

@ -22,6 +22,7 @@ object BookInfo {
body: String?,
bookSource: BookSource,
baseUrl: String,
redirectUrl: String,
canReName: Boolean,
) {
body ?: throw Exception(
@ -31,6 +32,7 @@ object BookInfo {
val infoRule = bookSource.getBookInfoRule()
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.setRedirectUrl(redirectUrl)
infoRule.init?.let {
if (it.isNotBlank()) {
scope.ensureActive()
@ -84,7 +86,7 @@ object BookInfo {
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it)
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it)
}
Debug.log(bookSource.bookSourceUrl, "${book.coverUrl}")
scope.ensureActive()

@ -37,6 +37,7 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
val analyzeRule = AnalyzeRule(variableBook)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.setRedirectUrl(baseUrl)
bookSource.bookUrlPattern?.let {
scope.ensureActive()
if (baseUrl.matches(it.toRegex())) {

@ -127,6 +127,7 @@ class WebBook(val bookSource: BookSource) {
book.infoHtml,
bookSource,
book.bookUrl,
book.bookUrl,
canReName
)
} else {
@ -136,7 +137,15 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap(),
book = book
).getStrResponse(bookSource.bookSourceUrl)
BookInfo.analyzeBookInfo(scope, book, res.body, bookSource, book.bookUrl, canReName)
BookInfo.analyzeBookInfo(
scope,
book,
res.body,
bookSource,
book.bookUrl,
res.url,
canReName
)
}
return book
}
@ -160,7 +169,14 @@ class WebBook(val bookSource: BookSource) {
): List<BookChapter> {
book.type = bookSource.bookSourceType
return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList(scope, book, book.tocHtml, bookSource, book.tocUrl)
BookChapterList.analyzeChapterList(
scope,
book,
book.tocHtml,
bookSource,
book.tocUrl,
book.tocUrl
)
} else {
val res = AnalyzeUrl(
book = book,
@ -168,7 +184,14 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl)
BookChapterList.analyzeChapterList(scope, book, res.body, bookSource, book.tocUrl)
BookChapterList.analyzeChapterList(
scope,
book,
res.body,
bookSource,
book.tocUrl,
res.url
)
}
}

Loading…
Cancel
Save