pull/49/head
kunfei 5 years ago
parent 9351c7b6db
commit f9b228538d
  1. 4
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 9
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 38
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  4. 5
      app/src/main/java/io/legado/app/model/rss/RssParser.kt
  5. 9
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt

@ -30,11 +30,11 @@ data class BookSource(
@PrimaryKey
var bookSourceUrl: String = "", // 地址,包括 http/https
var bookSourceType: Int = 0, // 类型,0 文本,1 音频
var bookUrlPattern: String? = null,
var bookUrlPattern: String? = null, //详情页url正则
var customOrder: Int = 0, // 手动排序编号
var enabled: Boolean = true, // 是否启用
var enabledExplore: Boolean = true, //启用发现
var header: String? = null, // header
var header: String? = null,
var loginUrl: String? = null, // 登录地址
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重

@ -1,7 +1,6 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.Ignore
@Entity(
@ -17,12 +16,6 @@ data class RssArticle(
var description: String? = null,
var content: String? = null,
var image: String? = null,
var categories: String? = null,
var read: Boolean = false,
var star: Boolean = false
) {
@Ignore
var categoryList: MutableList<String> = mutableListOf()
}
)

@ -4,7 +4,15 @@ import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.help.JsExtensions
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString
import kotlinx.android.parcel.Parcelize
import java.util.*
import javax.script.SimpleBindings
@Parcelize
@Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
@ -25,11 +33,41 @@ data class RssSource(
var ruleImage: String? = null,
var ruleLink: String? = null,
var ruleContent: String? = null,
var header: String? = null,
var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false,
var customOrder: Int = 0
) : Parcelable {
@Throws(Exception::class)
fun getHeaderMap(): Map<String, String> {
val headerMap = HashMap<String, String>()
headerMap[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: AppConst.userAgent
header?.let {
val header1 = when {
it.startsWith("@js:", true) ->
evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) ->
evalJS(it.substring(4, it.lastIndexOf("<"))).toString()
else -> it
}
GSON.fromJsonObject<Map<String, String>>(header1)?.let { map ->
headerMap.putAll(map)
}
}
return headerMap
}
/**
* 执行JS
*/
@Throws(Exception::class)
private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings()
bindings["java"] = JsExtensions
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
}
fun equal(source: RssSource): Boolean {
return equal(sourceUrl, source.sourceUrl)
&& equal(sourceIcon, source.sourceIcon)

@ -40,8 +40,6 @@ object RssParser {
if (insideItem) currentArticle.title = xmlPullParser.nextText().trim()
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_LINK, true) ->
if (insideItem) currentArticle.link = xmlPullParser.nextText().trim()
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_CATEGORY, true) ->
if (insideItem) currentArticle.categoryList.add(xmlPullParser.nextText().trim())
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_THUMBNAIL, true) ->
if (insideItem) currentArticle.image =
xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL)
@ -89,7 +87,6 @@ object RssParser {
) {
// The item is correctly parsed
insideItem = false
currentArticle.categories = currentArticle.categoryList.joinToString(",")
currentArticle.origin = sourceUrl
articleList.add(currentArticle)
currentArticle = RssArticle()
@ -104,8 +101,6 @@ object RssParser {
Debug.log(sourceUrl, "${item.title}")
Debug.log(sourceUrl, "┌获取时间")
Debug.log(sourceUrl, "${item.pubDate}")
Debug.log(sourceUrl, "┌获取类别")
Debug.log(sourceUrl, "${item.categories}")
Debug.log(sourceUrl, "┌获取描述")
Debug.log(sourceUrl, "${item.description}")
Debug.log(sourceUrl, "┌获取图片url")

@ -39,14 +39,13 @@ object RssParserByRule {
Debug.log(sourceUrl, "└列表大小:${collections.size}")
val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle)
val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate)
val ruleCategories = analyzeRule.splitSourceRule(rssSource.ruleCategories)
val ruleDescription = analyzeRule.splitSourceRule(rssSource.ruleDescription)
val ruleImage = analyzeRule.splitSourceRule(rssSource.ruleImage)
val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink)
for ((index, item) in collections.withIndex()) {
getItem(
sourceUrl, item, analyzeRule, index == 0, ruleTitle,
rulePubDate, ruleCategories, ruleDescription, ruleImage, ruleLink
sourceUrl, item, analyzeRule, index == 0,
ruleTitle, rulePubDate, ruleDescription, ruleImage, ruleLink
)?.let {
it.origin = rssSource.sourceUrl
articleList.add(it)
@ -69,7 +68,6 @@ object RssParserByRule {
log: Boolean,
ruleTitle: List<AnalyzeRule.SourceRule>,
rulePubDate: List<AnalyzeRule.SourceRule>,
ruleCategories: List<AnalyzeRule.SourceRule>,
ruleDescription: List<AnalyzeRule.SourceRule>,
ruleImage: List<AnalyzeRule.SourceRule>,
ruleLink: List<AnalyzeRule.SourceRule>
@ -82,9 +80,6 @@ object RssParserByRule {
Debug.log(sourceUrl, "┌获取时间", log)
rssArticle.pubDate = analyzeRule.getString(rulePubDate)
Debug.log(sourceUrl, "${rssArticle.pubDate}", log)
Debug.log(sourceUrl, "┌获取类别", log)
rssArticle.categories = analyzeRule.getString(ruleCategories)
Debug.log(sourceUrl, "${rssArticle.categories}", log)
Debug.log(sourceUrl, "┌获取描述", log)
rssArticle.description = analyzeRule.getString(ruleDescription)
Debug.log(sourceUrl, "${rssArticle.description}", log)

Loading…
Cancel
Save