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) ->
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
&& xmlPullParser.name.equals("item", true)
@ -99,6 +97,9 @@ object RssParser {
}
eventType = xmlPullParser.next()
}
for ((index: Int, item: RssArticle) in articleList.withIndex()) {
item.order = System.currentTimeMillis() + index
}
return articleList
}

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

Loading…
Cancel
Save