|
|
@ -17,7 +17,12 @@ class WebBook(private val bookSource: BookSource) { |
|
|
|
val sourceUrl: String |
|
|
|
val sourceUrl: String |
|
|
|
get() = bookSource.bookSourceUrl |
|
|
|
get() = bookSource.bookSourceUrl |
|
|
|
|
|
|
|
|
|
|
|
fun searchBook(key: String, page: Int?, isSearch: Boolean = true, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<List<SearchBook>> { |
|
|
|
fun searchBook( |
|
|
|
|
|
|
|
key: String, |
|
|
|
|
|
|
|
page: Int? = 1, |
|
|
|
|
|
|
|
isSearch: Boolean = true, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT |
|
|
|
|
|
|
|
): Coroutine<List<SearchBook>> { |
|
|
|
return Coroutine.async(scope) { |
|
|
|
return Coroutine.async(scope) { |
|
|
|
bookSource.getSearchRule().searchUrl?.let { searchUrl -> |
|
|
|
bookSource.getSearchRule().searchUrl?.let { searchUrl -> |
|
|
|
val analyzeUrl = AnalyzeUrl(searchUrl, key, page, baseUrl = sourceUrl) |
|
|
|
val analyzeUrl = AnalyzeUrl(searchUrl, key, page, baseUrl = sourceUrl) |
|
|
@ -27,8 +32,8 @@ class WebBook(private val bookSource: BookSource) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getBookInfo(book: Book): Coroutine<Book> { |
|
|
|
fun getBookInfo(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<Book> { |
|
|
|
return Coroutine.async { |
|
|
|
return Coroutine.async(scope) { |
|
|
|
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.bookUrl, baseUrl = sourceUrl) |
|
|
|
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.bookUrl, baseUrl = sourceUrl) |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl) |
|
|
|
BookInfo.analyzeBookInfo(book, response.body(), bookSource, analyzeUrl) |
|
|
@ -36,16 +41,21 @@ class WebBook(private val bookSource: BookSource) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getChapterList(book: Book): Coroutine<List<BookChapter>> { |
|
|
|
fun getChapterList(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<List<BookChapter>> { |
|
|
|
return Coroutine.async { |
|
|
|
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) |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl) |
|
|
|
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getContent(book: Book, bookChapter: BookChapter, nextChapterUrl: String? = null): Coroutine<String> { |
|
|
|
fun getContent( |
|
|
|
return Coroutine.async { |
|
|
|
book: Book, |
|
|
|
|
|
|
|
bookChapter: BookChapter, |
|
|
|
|
|
|
|
nextChapterUrl: String? = null, |
|
|
|
|
|
|
|
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) |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
val response = analyzeUrl.getResponseAsync().await() |
|
|
|
BookContent.analyzeContent(this, response, book, bookChapter, bookSource, nextChapterUrl) |
|
|
|
BookContent.analyzeContent(this, response, book, bookChapter, bookSource, nextChapterUrl) |
|
|
|