添加书籍地址优先匹配启用的规则

pull/1705/head
kunfei 3 years ago
parent 10bdb9962c
commit 4c47e4a24a
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 2
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -74,7 +74,7 @@ interface BookSourceDao {
@Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'")
fun getEnabledByGroup(group: String): List<BookSource> fun getEnabledByGroup(group: String): List<BookSource>
@get:Query("select * from book_sources where trim(bookUrlPattern) <> ''") @get:Query("select * from book_sources where trim(bookUrlPattern) <> '' order by enabled desc, customOrder")
val hasBookUrlPattern: List<BookSource> val hasBookUrlPattern: List<BookSource>
@get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''")

@ -117,7 +117,7 @@ object RssParserByRule {
Debug.log(sourceUrl, "┌获取文章链接", log) Debug.log(sourceUrl, "┌获取文章链接", log)
rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink)) rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink))
Debug.log(sourceUrl, "${rssArticle.link}", log) Debug.log(sourceUrl, "${rssArticle.link}", log)
rssArticle.variable = GSON.toJson(analyzeRule.ruleData.variableMap) rssArticle.variable = analyzeRule.ruleData?.variableMap?.let { GSON.toJson(it) }
if (rssArticle.title.isBlank()) { if (rssArticle.title.isBlank()) {
return null return null
} }

@ -24,7 +24,9 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun addBookByUrl(bookUrls: String) { fun addBookByUrl(bookUrls: String) {
var successCount = 0 var successCount = 0
execute { execute {
var hasBookUrlPattern: List<BookSource>? = null val hasBookUrlPattern: List<BookSource> by lazy {
appDb.bookSourceDao.hasBookUrlPattern
}
val urls = bookUrls.split("\n") val urls = bookUrls.split("\n")
for (url in urls) { for (url in urls) {
val bookUrl = url.trim() val bookUrl = url.trim()
@ -33,9 +35,6 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue
var source = appDb.bookSourceDao.getBookSource(baseUrl) var source = appDb.bookSourceDao.getBookSource(baseUrl)
if (source == null) { if (source == null) {
if (hasBookUrlPattern == null) {
hasBookUrlPattern = appDb.bookSourceDao.hasBookUrlPattern
}
hasBookUrlPattern.forEach { bookSource -> hasBookUrlPattern.forEach { bookSource ->
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) { if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
source = bookSource source = bookSource

Loading…
Cancel
Save