|
|
@ -11,6 +11,8 @@ import io.legado.app.model.webbook.BookContent |
|
|
|
import io.legado.app.model.webbook.BookInfo |
|
|
|
import io.legado.app.model.webbook.BookInfo |
|
|
|
import io.legado.app.model.webbook.BookList |
|
|
|
import io.legado.app.model.webbook.BookList |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
class WebBook(val bookSource: BookSource) { |
|
|
|
class WebBook(val bookSource: BookSource) { |
|
|
|
|
|
|
|
|
|
|
@ -20,9 +22,13 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 搜索 |
|
|
|
* 搜索 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun searchBook(key: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT) |
|
|
|
fun searchBook( |
|
|
|
: Coroutine<List<SearchBook>> { |
|
|
|
key: String, |
|
|
|
return Coroutine.async(scope) { |
|
|
|
page: Int? = 1, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
|
|
|
): Coroutine<List<SearchBook>> { |
|
|
|
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
bookSource.searchUrl?.let { searchUrl -> |
|
|
|
bookSource.searchUrl?.let { searchUrl -> |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
ruleUrl = searchUrl, |
|
|
|
ruleUrl = searchUrl, |
|
|
@ -40,9 +46,13 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 发现 |
|
|
|
* 发现 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun exploreBook(url: String, page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT) |
|
|
|
fun exploreBook( |
|
|
|
: Coroutine<List<SearchBook>> { |
|
|
|
url: String, |
|
|
|
return Coroutine.async(scope) { |
|
|
|
page: Int? = 1, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
|
|
|
): Coroutine<List<SearchBook>> { |
|
|
|
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
ruleUrl = url, |
|
|
|
ruleUrl = url, |
|
|
|
page = page, |
|
|
|
page = page, |
|
|
@ -57,8 +67,12 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 书籍信息 |
|
|
|
* 书籍信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun getBookInfo(book: Book, scope: CoroutineScope = Coroutine.DEFAULT): Coroutine<Book> { |
|
|
|
fun getBookInfo( |
|
|
|
return Coroutine.async(scope) { |
|
|
|
book: Book, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
|
|
|
): Coroutine<Book> { |
|
|
|
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
ruleUrl = book.bookUrl, |
|
|
|
ruleUrl = book.bookUrl, |
|
|
@ -76,9 +90,10 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun getChapterList( |
|
|
|
fun getChapterList( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
): Coroutine<List<BookChapter>> { |
|
|
|
): Coroutine<List<BookChapter>> { |
|
|
|
return Coroutine.async(scope) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
ruleUrl = book.tocUrl, |
|
|
|
ruleUrl = book.tocUrl, |
|
|
@ -97,9 +112,10 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
bookChapter: BookChapter, |
|
|
|
bookChapter: BookChapter, |
|
|
|
nextChapterUrl: String? = null, |
|
|
|
nextChapterUrl: String? = null, |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
): Coroutine<String> { |
|
|
|
): Coroutine<String> { |
|
|
|
return Coroutine.async(scope) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
val analyzeUrl = |
|
|
|
val analyzeUrl = |
|
|
|
AnalyzeUrl( |
|
|
|
AnalyzeUrl( |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|