pull/37/head
kunfei 5 years ago
parent 0feab3459e
commit 4d8b482999
  1. 5
      app/src/main/java/io/legado/app/model/rss/RssParser.kt
  2. 25
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt

@ -84,8 +84,6 @@ object RssParser {
} }
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_TIME, true) -> xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_TIME, true) ->
if (insideItem) currentArticle.pubDate = xmlPullParser.nextText() if (insideItem) currentArticle.pubDate = xmlPullParser.nextText()
xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_GUID, true) ->
if (insideItem) currentArticle.guid = xmlPullParser.nextText().trim()
} }
} else if (eventType == XmlPullParser.END_TAG } else if (eventType == XmlPullParser.END_TAG
&& xmlPullParser.name.equals("item", true) && xmlPullParser.name.equals("item", true)
@ -99,6 +97,9 @@ object RssParser {
} }
eventType = xmlPullParser.next() eventType = xmlPullParser.next()
} }
for ((index: Int, item: RssArticle) in articleList.withIndex()) {
item.order = System.currentTimeMillis() + index
}
return articleList return articleList
} }

@ -11,7 +11,6 @@ object RssParserByRule {
@Throws(Exception::class) @Throws(Exception::class)
fun parseXML(response: Response<String>, rssSource: RssSource): MutableList<RssArticle> { fun parseXML(response: Response<String>, rssSource: RssSource): MutableList<RssArticle> {
val articleList = mutableListOf<RssArticle>()
val xml = response.body() val xml = response.body()
if (xml.isNullOrBlank()) { if (xml.isNullOrBlank()) {
@ -22,12 +21,19 @@ object RssParserByRule {
) )
) )
} }
var ruleArticles = rssSource.ruleArticles
rssSource.ruleArticles?.let { ruleArticles -> if (ruleArticles.isNullOrBlank()) {
return RssParser.parseXML(xml, rssSource.sourceUrl)
} else {
val articleList = mutableListOf<RssArticle>()
val analyzeRule = AnalyzeRule() val analyzeRule = AnalyzeRule()
analyzeRule.setContent(xml) analyzeRule.setContent(xml)
var reverse = false
if (ruleArticles.startsWith("-")) {
reverse = true
ruleArticles = ruleArticles.substring(1)
}
val collections = analyzeRule.getElements(ruleArticles) val collections = analyzeRule.getElements(ruleArticles)
val ruleGuid = analyzeRule.splitSourceRule(rssSource.ruleGuid ?: "")
val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "")
val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "")
val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "")
@ -41,7 +47,6 @@ object RssParserByRule {
item, item,
analyzeRule, analyzeRule,
index == 0, index == 0,
ruleGuid,
ruleTitle, ruleTitle,
ruleAuthor, ruleAuthor,
rulePubDate, rulePubDate,
@ -55,17 +60,20 @@ object RssParserByRule {
articleList.add(it) articleList.add(it)
} }
} }
} ?: let { if (reverse) {
return RssParser.parseXML(xml, rssSource.sourceUrl) articleList.reverse()
}
for ((index: Int, item: RssArticle) in articleList.withIndex()) {
item.order = System.currentTimeMillis() + index
} }
return articleList return articleList
} }
}
private fun getItem( private fun getItem(
item: Any, item: Any,
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,
printLog: Boolean, printLog: Boolean,
ruleGuid: List<AnalyzeRule.SourceRule>,
ruleTitle: List<AnalyzeRule.SourceRule>, ruleTitle: List<AnalyzeRule.SourceRule>,
ruleAuthor: List<AnalyzeRule.SourceRule>, ruleAuthor: List<AnalyzeRule.SourceRule>,
rulePubDate: List<AnalyzeRule.SourceRule>, rulePubDate: List<AnalyzeRule.SourceRule>,
@ -77,7 +85,6 @@ object RssParserByRule {
): RssArticle? { ): RssArticle? {
val rssArticle = RssArticle() val rssArticle = RssArticle()
analyzeRule.setContent(item) analyzeRule.setContent(item)
rssArticle.guid = analyzeRule.getString(ruleGuid)
rssArticle.title = analyzeRule.getString(ruleTitle) rssArticle.title = analyzeRule.getString(ruleTitle)
rssArticle.author = analyzeRule.getString(ruleAuthor) rssArticle.author = analyzeRule.getString(ruleAuthor)
rssArticle.pubDate = analyzeRule.getString(rulePubDate) rssArticle.pubDate = analyzeRule.getString(rulePubDate)

Loading…
Cancel
Save