|
|
@ -10,7 +10,7 @@ import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.model.Debug |
|
|
|
import io.legado.app.model.Debug |
|
|
|
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.HtmlFormat |
|
|
|
import io.legado.app.utils.HtmlFormatter |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
@ -26,6 +26,7 @@ object BookContent { |
|
|
|
bookChapter: BookChapter, |
|
|
|
bookChapter: BookChapter, |
|
|
|
bookSource: BookSource, |
|
|
|
bookSource: BookSource, |
|
|
|
baseUrl: String, |
|
|
|
baseUrl: String, |
|
|
|
|
|
|
|
redirectUrl: String, |
|
|
|
nextChapterUrl: String? = null |
|
|
|
nextChapterUrl: String? = null |
|
|
|
): String { |
|
|
|
): String { |
|
|
|
body ?: throw Exception( |
|
|
|
body ?: throw Exception( |
|
|
@ -44,7 +45,7 @@ object BookContent { |
|
|
|
analyzeRule.setRedirectUrl(baseUrl) |
|
|
|
analyzeRule.setRedirectUrl(baseUrl) |
|
|
|
analyzeRule.nextChapterUrl = mNextChapterUrl |
|
|
|
analyzeRule.nextChapterUrl = mNextChapterUrl |
|
|
|
var contentData = analyzeContent( |
|
|
|
var contentData = analyzeContent( |
|
|
|
book, baseUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl |
|
|
|
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl |
|
|
|
) |
|
|
|
) |
|
|
|
content.append(contentData.content).append("\n") |
|
|
|
content.append(contentData.content).append("\n") |
|
|
|
|
|
|
|
|
|
|
@ -56,20 +57,15 @@ object BookContent { |
|
|
|
== NetworkUtils.getAbsoluteURL(baseUrl, mNextChapterUrl) |
|
|
|
== NetworkUtils.getAbsoluteURL(baseUrl, mNextChapterUrl) |
|
|
|
) break |
|
|
|
) break |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
ruleUrl = nextUrl, |
|
|
|
ruleUrl = nextUrl, |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody -> |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
|
|
|
|
res.body?.let { nextBody -> |
|
|
|
contentData = analyzeContent( |
|
|
|
contentData = analyzeContent( |
|
|
|
book, |
|
|
|
book, nextUrl, res.url, nextBody, contentRule, |
|
|
|
nextUrl, |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
nextBody, |
|
|
|
|
|
|
|
contentRule, |
|
|
|
|
|
|
|
bookChapter, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
mNextChapterUrl, |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
nextUrl = |
|
|
|
nextUrl = |
|
|
|
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" |
|
|
|
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" |
|
|
@ -85,20 +81,15 @@ object BookContent { |
|
|
|
} |
|
|
|
} |
|
|
|
for (item in contentDataList) { |
|
|
|
for (item in contentDataList) { |
|
|
|
withContext(scope.coroutineContext) { |
|
|
|
withContext(scope.coroutineContext) { |
|
|
|
AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getStrResponse(bookSource.bookSourceUrl).body?.let { |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
|
|
|
|
res.body?.let { nextBody -> |
|
|
|
contentData = analyzeContent( |
|
|
|
contentData = analyzeContent( |
|
|
|
book, |
|
|
|
book, item.nextUrl, res.url, nextBody, contentRule, |
|
|
|
item.nextUrl, |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
it, |
|
|
|
|
|
|
|
contentRule, |
|
|
|
|
|
|
|
bookChapter, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
mNextChapterUrl, |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
item.content = contentData.content |
|
|
|
item.content = contentData.content |
|
|
|
} |
|
|
|
} |
|
|
@ -109,7 +100,7 @@ object BookContent { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
content.deleteCharAt(content.length - 1) |
|
|
|
content.deleteCharAt(content.length - 1) |
|
|
|
var contentStr = HtmlFormat.formatKeepImg(content.toString()) |
|
|
|
var contentStr = content.toString() |
|
|
|
val replaceRegex = contentRule.replaceRegex |
|
|
|
val replaceRegex = contentRule.replaceRegex |
|
|
|
if (!replaceRegex.isNullOrEmpty()) { |
|
|
|
if (!replaceRegex.isNullOrEmpty()) { |
|
|
|
contentStr = analyzeRule.getString(replaceRegex, value = contentStr) |
|
|
|
contentStr = analyzeRule.getString(replaceRegex, value = contentStr) |
|
|
@ -128,6 +119,7 @@ object BookContent { |
|
|
|
private fun analyzeContent( |
|
|
|
private fun analyzeContent( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
baseUrl: String, |
|
|
|
baseUrl: String, |
|
|
|
|
|
|
|
redirectUrl: String, |
|
|
|
body: String, |
|
|
|
body: String, |
|
|
|
contentRule: ContentRule, |
|
|
|
contentRule: ContentRule, |
|
|
|
chapter: BookChapter, |
|
|
|
chapter: BookChapter, |
|
|
@ -136,13 +128,14 @@ object BookContent { |
|
|
|
printLog: Boolean = true |
|
|
|
printLog: Boolean = true |
|
|
|
): ContentData<List<String>> { |
|
|
|
): ContentData<List<String>> { |
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
analyzeRule.setContent(body).setBaseUrl(baseUrl) |
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
analyzeRule.setRedirectUrl(baseUrl) |
|
|
|
val rUrl = analyzeRule.setRedirectUrl(redirectUrl) |
|
|
|
analyzeRule.nextChapterUrl = nextChapterUrl |
|
|
|
analyzeRule.nextChapterUrl = nextChapterUrl |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
analyzeRule.chapter = chapter |
|
|
|
analyzeRule.chapter = chapter |
|
|
|
//获取正文 |
|
|
|
//获取正文 |
|
|
|
val content = analyzeRule.getString(contentRule.content) |
|
|
|
var content = analyzeRule.getString(contentRule.content) |
|
|
|
|
|
|
|
content = HtmlFormatter.formatKeepImg(content, rUrl) |
|
|
|
//获取下一页链接 |
|
|
|
//获取下一页链接 |
|
|
|
val nextUrlRule = contentRule.nextContentUrl |
|
|
|
val nextUrlRule = contentRule.nextContentUrl |
|
|
|
if (!nextUrlRule.isNullOrEmpty()) { |
|
|
|
if (!nextUrlRule.isNullOrEmpty()) { |
|
|
|