|
|
@ -8,7 +8,6 @@ import io.legado.app.data.entities.rule.BookListRule |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeRule |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeRule |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import org.mozilla.javascript.NativeObject |
|
|
|
|
|
|
|
import retrofit2.Response |
|
|
|
import retrofit2.Response |
|
|
|
|
|
|
|
|
|
|
|
object BookList { |
|
|
|
object BookList { |
|
|
@ -42,36 +41,18 @@ object BookList { |
|
|
|
} |
|
|
|
} |
|
|
|
val collections: List<Any> |
|
|
|
val collections: List<Any> |
|
|
|
var reverse = false |
|
|
|
var reverse = false |
|
|
|
var allInOne = false |
|
|
|
|
|
|
|
val bookListRule = if (isSearch) bookSource.getSearchRule() else bookSource.getExploreRule() |
|
|
|
val bookListRule = if (isSearch) bookSource.getSearchRule() else bookSource.getExploreRule() |
|
|
|
var ruleList = bookListRule.bookList ?: "" |
|
|
|
var ruleList = bookListRule.bookList ?: "" |
|
|
|
if (ruleList.startsWith("-")) { |
|
|
|
if (ruleList.startsWith("-")) { |
|
|
|
reverse = true |
|
|
|
reverse = true |
|
|
|
ruleList = ruleList.substring(1) |
|
|
|
ruleList = ruleList.substring(1) |
|
|
|
} |
|
|
|
} |
|
|
|
if (ruleList.startsWith(":")) { |
|
|
|
|
|
|
|
ruleList = ruleList.substring(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ruleList.startsWith("+")) { |
|
|
|
|
|
|
|
allInOne = true |
|
|
|
|
|
|
|
ruleList = ruleList.substring(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
collections = analyzer.getElements(ruleList) |
|
|
|
collections = analyzer.getElements(ruleList) |
|
|
|
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { |
|
|
|
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { |
|
|
|
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> |
|
|
|
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> |
|
|
|
searchBook.bookInfoHtml = body |
|
|
|
searchBook.bookInfoHtml = body |
|
|
|
bookList.add(searchBook) |
|
|
|
bookList.add(searchBook) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
if (allInOne) { |
|
|
|
|
|
|
|
for (item in collections) { |
|
|
|
|
|
|
|
getAllInOneItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook -> |
|
|
|
|
|
|
|
if (baseUrl == searchBook.bookUrl) { |
|
|
|
|
|
|
|
searchBook.bookInfoHtml = body |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bookList.add(searchBook) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (item in collections) { |
|
|
|
for (item in collections) { |
|
|
|
getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook -> |
|
|
|
getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook -> |
|
|
@ -81,7 +62,6 @@ object BookList { |
|
|
|
bookList.add(searchBook) |
|
|
|
bookList.add(searchBook) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (reverse) { |
|
|
|
if (reverse) { |
|
|
|
bookList.reverse() |
|
|
|
bookList.reverse() |
|
|
|
} |
|
|
|
} |
|
|
@ -114,29 +94,6 @@ object BookList { |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getAllInOneItem( |
|
|
|
|
|
|
|
item: Any, |
|
|
|
|
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
|
|
|
|
bookListRule: BookListRule, |
|
|
|
|
|
|
|
bookSource: BookSource, |
|
|
|
|
|
|
|
baseUrl: String |
|
|
|
|
|
|
|
): SearchBook? { |
|
|
|
|
|
|
|
val searchBook = SearchBook() |
|
|
|
|
|
|
|
searchBook.origin = bookSource.bookSourceUrl |
|
|
|
|
|
|
|
searchBook.originName = bookSource.bookSourceName |
|
|
|
|
|
|
|
val nativeObject = item as NativeObject |
|
|
|
|
|
|
|
searchBook.name = nativeObject[bookListRule.name]?.toString() |
|
|
|
|
|
|
|
searchBook.name?.let { |
|
|
|
|
|
|
|
searchBook.author = nativeObject[bookListRule.author]?.toString() |
|
|
|
|
|
|
|
searchBook.coverUrl = nativeObject[bookListRule.coverUrl]?.toString() |
|
|
|
|
|
|
|
searchBook.intro = nativeObject[bookListRule.intro]?.toString() |
|
|
|
|
|
|
|
searchBook.kind = nativeObject[bookListRule.kind]?.toString() |
|
|
|
|
|
|
|
searchBook.wordCount = nativeObject[bookListRule.wordCount]?.toString() |
|
|
|
|
|
|
|
return searchBook |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getSearchItem( |
|
|
|
private fun getSearchItem( |
|
|
|
item: Any, |
|
|
|
item: Any, |
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|