pull/32/head
kunfei 5 years ago
parent aaad5da071
commit 10364430f7
  1. 80
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -14,19 +14,19 @@ object BookList {
@Throws(Exception::class) @Throws(Exception::class)
fun analyzeBookList( fun analyzeBookList(
response: Response<String>, response: Response<String>,
bookSource: BookSource, bookSource: BookSource,
analyzeUrl: AnalyzeUrl, analyzeUrl: AnalyzeUrl,
isSearch: Boolean = true isSearch: Boolean = true
): ArrayList<SearchBook> { ): ArrayList<SearchBook> {
val bookList = ArrayList<SearchBook>() val bookList = ArrayList<SearchBook>()
val baseUrl: String = NetworkUtils.getUrl(response) val baseUrl: String = NetworkUtils.getUrl(response)
val body: String? = response.body() val body: String? = response.body()
body ?: throw Exception( body ?: throw Exception(
App.INSTANCE.getString( App.INSTANCE.getString(
R.string.error_get_web_content, R.string.error_get_web_content,
baseUrl baseUrl
) )
) )
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl")
val analyzeRule = AnalyzeRule(null) val analyzeRule = AnalyzeRule(null)
@ -72,19 +72,19 @@ object BookList {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表数为${collections.size}") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "列表数为${collections.size}")
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
getSearchItem( getSearchItem(
item, item,
analyzeRule, analyzeRule,
bookSource, bookSource,
baseUrl, baseUrl,
index == 0, index == 0,
ruleName = ruleName, ruleName = ruleName,
ruleBookUrl = ruleBookUrl, ruleBookUrl = ruleBookUrl,
ruleAuthor = ruleAuthor, ruleAuthor = ruleAuthor,
ruleCoverUrl = ruleCoverUrl, ruleCoverUrl = ruleCoverUrl,
ruleIntro = ruleIntro, ruleIntro = ruleIntro,
ruleKind = ruleKind, ruleKind = ruleKind,
ruleLastChapter = ruleLastChapter, ruleLastChapter = ruleLastChapter,
ruleWordCount = ruleWordCount ruleWordCount = ruleWordCount
)?.let { searchBook -> )?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) { if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body searchBook.bookInfoHtml = body
@ -125,7 +125,8 @@ object BookList {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介")
searchBook.intro = analyzeRule.getString(intro ?: "") searchBook.intro = analyzeRule.getString(intro ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro ?: "", isHtml = true) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro
?: "", isHtml = true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数")
searchBook.wordCount = analyzeRule.getString(wordCount ?: "") searchBook.wordCount = analyzeRule.getString(wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "")
@ -134,7 +135,8 @@ object BookList {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节") SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "") searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle ?: "") SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle
?: "")
return searchBook return searchBook
} }
} }
@ -142,19 +144,19 @@ object BookList {
} }
private fun getSearchItem( private fun getSearchItem(
item: Any, item: Any,
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String, baseUrl: String,
printLog: Boolean, printLog: Boolean,
ruleName: List<AnalyzeRule.SourceRule>, ruleName: List<AnalyzeRule.SourceRule>,
ruleBookUrl: List<AnalyzeRule.SourceRule>, ruleBookUrl: List<AnalyzeRule.SourceRule>,
ruleAuthor: List<AnalyzeRule.SourceRule>, ruleAuthor: List<AnalyzeRule.SourceRule>,
ruleKind: List<AnalyzeRule.SourceRule>, ruleKind: List<AnalyzeRule.SourceRule>,
ruleCoverUrl: List<AnalyzeRule.SourceRule>, ruleCoverUrl: List<AnalyzeRule.SourceRule>,
ruleWordCount: List<AnalyzeRule.SourceRule>, ruleWordCount: List<AnalyzeRule.SourceRule>,
ruleIntro: List<AnalyzeRule.SourceRule>, ruleIntro: List<AnalyzeRule.SourceRule>,
ruleLastChapter: List<AnalyzeRule.SourceRule> ruleLastChapter: List<AnalyzeRule.SourceRule>
): SearchBook? { ): SearchBook? {
val searchBook = SearchBook() val searchBook = SearchBook()
searchBook.origin = bookSource.bookSourceUrl searchBook.origin = bookSource.bookSourceUrl
@ -177,7 +179,8 @@ object BookList {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.kind ?: "", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取简介", printLog)
searchBook.intro = analyzeRule.getString(ruleIntro) searchBook.intro = analyzeRule.getString(ruleIntro)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro ?: "", printLog, true) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.intro
?: "", printLog, true)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取字数", printLog)
searchBook.wordCount = analyzeRule.getString(ruleWordCount) searchBook.wordCount = analyzeRule.getString(ruleWordCount)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.wordCount ?: "", printLog)
@ -186,7 +189,8 @@ object BookList {
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.coverUrl ?: "", printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取最新章节", printLog)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle ?: "", printLog) SourceDebug.printLog(bookSource.bookSourceUrl, 1, searchBook.latestChapterTitle
?: "", printLog)
return searchBook return searchBook
} }
return null return null

Loading…
Cancel
Save