|
|
@ -11,6 +11,7 @@ import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Suppress("MemberVisibilityCanBePrivate") |
|
|
|
class WebBook(val bookSource: BookSource) { |
|
|
|
class WebBook(val bookSource: BookSource) { |
|
|
|
|
|
|
|
|
|
|
|
val sourceUrl: String |
|
|
|
val sourceUrl: String |
|
|
@ -26,11 +27,11 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
context: CoroutineContext = Dispatchers.IO, |
|
|
|
context: CoroutineContext = Dispatchers.IO, |
|
|
|
): Coroutine<ArrayList<SearchBook>> { |
|
|
|
): Coroutine<ArrayList<SearchBook>> { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
searchBookSuspend(scope, key, page) |
|
|
|
searchBookAwait(scope, key, page) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suspend fun searchBookSuspend( |
|
|
|
suspend fun searchBookAwait( |
|
|
|
scope: CoroutineScope, |
|
|
|
scope: CoroutineScope, |
|
|
|
key: String, |
|
|
|
key: String, |
|
|
|
page: Int? = 1, |
|
|
|
page: Int? = 1, |
|
|
@ -68,8 +69,17 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
context: CoroutineContext = Dispatchers.IO, |
|
|
|
context: CoroutineContext = Dispatchers.IO, |
|
|
|
): Coroutine<List<SearchBook>> { |
|
|
|
): Coroutine<List<SearchBook>> { |
|
|
|
val variableBook = SearchBook() |
|
|
|
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
|
|
|
exploreBookAwait(url, page, scope) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun exploreBookAwait( |
|
|
|
|
|
|
|
url: String, |
|
|
|
|
|
|
|
page: Int? = 1, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT |
|
|
|
|
|
|
|
): ArrayList<SearchBook> { |
|
|
|
|
|
|
|
val variableBook = SearchBook() |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
ruleUrl = url, |
|
|
|
ruleUrl = url, |
|
|
|
page = page, |
|
|
|
page = page, |
|
|
@ -78,7 +88,7 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
) |
|
|
|
) |
|
|
|
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl) |
|
|
|
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl) |
|
|
|
BookList.analyzeBookList( |
|
|
|
return BookList.analyzeBookList( |
|
|
|
scope, |
|
|
|
scope, |
|
|
|
res.body, |
|
|
|
res.body, |
|
|
|
bookSource, |
|
|
|
bookSource, |
|
|
@ -88,7 +98,6 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
false |
|
|
|
false |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 书籍信息 |
|
|
|
* 书籍信息 |
|
|
@ -100,10 +109,26 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
canReName: Boolean = true, |
|
|
|
canReName: Boolean = true, |
|
|
|
): Coroutine<Book> { |
|
|
|
): Coroutine<Book> { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
|
|
|
getBookInfoAwait(book, scope, canReName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun getBookInfoAwait( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT, |
|
|
|
|
|
|
|
canReName: Boolean = true, |
|
|
|
|
|
|
|
): Book { |
|
|
|
book.type = bookSource.bookSourceType |
|
|
|
book.type = bookSource.bookSourceType |
|
|
|
if (!book.infoHtml.isNullOrEmpty()) { |
|
|
|
if (!book.infoHtml.isNullOrEmpty()) { |
|
|
|
book.infoHtml |
|
|
|
book.infoHtml |
|
|
|
BookInfo.analyzeBookInfo(book, book.infoHtml, bookSource, book.bookUrl, canReName) |
|
|
|
BookInfo.analyzeBookInfo( |
|
|
|
|
|
|
|
scope, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
book.infoHtml, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
book.bookUrl, |
|
|
|
|
|
|
|
canReName |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val res = AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
ruleUrl = book.bookUrl, |
|
|
|
ruleUrl = book.bookUrl, |
|
|
@ -111,10 +136,9 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
headerMapF = bookSource.getHeaderMap(), |
|
|
|
headerMapF = bookSource.getHeaderMap(), |
|
|
|
book = book |
|
|
|
book = book |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
BookInfo.analyzeBookInfo(book, res.body, bookSource, book.bookUrl, canReName) |
|
|
|
BookInfo.analyzeBookInfo(scope, book, res.body, bookSource, book.bookUrl, canReName) |
|
|
|
} |
|
|
|
|
|
|
|
book |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return book |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -126,15 +150,17 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
): Coroutine<List<BookChapter>> { |
|
|
|
): Coroutine<List<BookChapter>> { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
|
|
|
getChapterListAwait(book, scope) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun getChapterListAwait( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
|
|
|
|
scope: CoroutineScope = Coroutine.DEFAULT |
|
|
|
|
|
|
|
): List<BookChapter> { |
|
|
|
book.type = bookSource.bookSourceType |
|
|
|
book.type = bookSource.bookSourceType |
|
|
|
if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { |
|
|
|
return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { |
|
|
|
BookChapterList.analyzeChapterList( |
|
|
|
BookChapterList.analyzeChapterList(scope, book, book.tocHtml, bookSource, book.tocUrl) |
|
|
|
this, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
book.tocHtml, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
book.tocUrl |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val res = AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
@ -142,15 +168,7 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
baseUrl = book.bookUrl, |
|
|
|
baseUrl = book.bookUrl, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
).getStrResponse(bookSource.bookSourceUrl) |
|
|
|
BookChapterList.analyzeChapterList( |
|
|
|
BookChapterList.analyzeChapterList(scope, book, res.body, bookSource, book.tocUrl) |
|
|
|
this, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
res.body, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
book.tocUrl |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -165,16 +183,11 @@ class WebBook(val bookSource: BookSource) { |
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
): Coroutine<String> { |
|
|
|
): Coroutine<String> { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
getContentSuspend( |
|
|
|
getContentAwait(book, bookChapter, nextChapterUrl, scope) |
|
|
|
book, bookChapter, nextChapterUrl, scope |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
suspend fun getContentAwait( |
|
|
|
* 章节内容 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
suspend fun getContentSuspend( |
|
|
|
|
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
bookChapter: BookChapter, |
|
|
|
bookChapter: BookChapter, |
|
|
|
nextChapterUrl: String? = null, |
|
|
|
nextChapterUrl: String? = null, |
|
|
|