pull/32/head
kunfei 5 years ago
parent 15804a4cf5
commit cfbc72cbd3
  1. 44
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 41
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  3. 15
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt

@ -25,7 +25,13 @@ class WebBook(private val bookSource: BookSource) {
): Coroutine<List<SearchBook>> {
return Coroutine.async(scope) {
bookSource.getSearchRule().searchUrl?.let { searchUrl ->
val analyzeUrl = AnalyzeUrl(searchUrl, key, page, baseUrl = sourceUrl)
val analyzeUrl = AnalyzeUrl(
ruleUrl = searchUrl,
key = key,
page = page,
baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookList.analyzeBookList(response, bookSource, analyzeUrl, isSearch)
} ?: arrayListOf()
@ -34,16 +40,29 @@ class WebBook(private val bookSource: BookSource) {
fun getBookInfo(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<Book> {
return Coroutine.async(scope) {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.bookUrl, baseUrl = sourceUrl)
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.bookUrl,
baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl)
book
}
}
fun getChapterList(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<List<BookChapter>> {
fun getChapterList(
book: Book,
scope: CoroutineScope = Coroutine.DEFAULT
): Coroutine<List<BookChapter>> {
return Coroutine.async(scope) {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl, baseUrl = book.bookUrl)
val analyzeUrl = AnalyzeUrl(
book = book,
ruleUrl = book.tocUrl,
baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl)
}
@ -56,9 +75,22 @@ class WebBook(private val bookSource: BookSource) {
scope: CoroutineScope = Coroutine.DEFAULT
): Coroutine<String> {
return Coroutine.async(scope) {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = bookChapter.url, baseUrl = book.tocUrl)
val analyzeUrl =
AnalyzeUrl(
book = book,
ruleUrl = bookChapter.url,
baseUrl = book.tocUrl,
headerMapF = bookSource.getHeaderMap()
)
val response = analyzeUrl.getResponseAsync().await()
BookContent.analyzeContent(this, response, book, bookChapter, bookSource, nextChapterUrl)
BookContent.analyzeContent(
this,
response,
book,
bookChapter,
bookSource,
nextChapterUrl
)
}
}
}

@ -44,7 +44,8 @@ object BookChapterList {
if (listRule.startsWith("+")) {
listRule = listRule.substring(1)
}
var chapterData = analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true)
var chapterData =
analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true)
chapterData.chapterList?.let {
chapterList.addAll(it)
}
@ -52,10 +53,22 @@ object BookChapterList {
var nextUrl = chapterData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponseAsync().await()
AnalyzeUrl(
ruleUrl = nextUrl,
book = book,
headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await()
.body()?.let { nextBody ->
chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, listRule, book, bookSource)
nextUrl = if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else ""
chapterData = analyzeChapterList(
nextBody,
nextUrl,
tocRule,
listRule,
book,
bookSource
)
nextUrl =
if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else ""
chapterData.chapterList?.let {
chapterList.addAll(it)
}
@ -69,7 +82,11 @@ object BookChapterList {
}
for (item in chapterDataList) {
withContext(coroutineScope.coroutineContext) {
val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await()
val nextResponse = AnalyzeUrl(
ruleUrl = item.nextUrl,
book = book,
headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await()
val nextChapterData = analyzeChapterList(
nextResponse.body() ?: "",
item.nextUrl,
@ -126,7 +143,12 @@ object BookChapterList {
}
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, TextUtils.join(",", nextUrlList), printLog)
SourceDebug.printLog(
bookSource.bookSourceUrl,
1,
TextUtils.join(",", nextUrlList),
printLog
)
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog)
val elements = analyzeRule.getElements(listRule)
@ -146,7 +168,12 @@ object BookChapterList {
chapterList.add(bookChapter)
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "${chapterList[0].title}${chapterList[0].url}", printLog)
SourceDebug.printLog(
bookSource.bookSourceUrl,
1,
"${chapterList[0].title}${chapterList[0].url}",
printLog
)
}
return ChapterData(chapterList, nextUrlList)
}

@ -51,10 +51,15 @@ object BookContent {
== NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl)
) break
nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponseAsync().await()
AnalyzeUrl(
ruleUrl = nextUrl,
book = book,
headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await()
.body()?.let { nextBody ->
contentData = analyzeContent(nextBody, contentRule, book, baseUrl)
nextUrl = if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
content.append(contentData.content)
}
}
@ -66,7 +71,11 @@ object BookContent {
}
for (item in contentDataList) {
withContext(coroutineScope.coroutineContext) {
val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await()
val nextResponse = AnalyzeUrl(
ruleUrl = item.nextUrl,
book = book,
headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await()
val nextContentData = analyzeContent(
nextResponse.body() ?: "",
contentRule,

Loading…
Cancel
Save