pull/46/head
kunfei 5 years ago
parent dddd3caba0
commit 50c8da23d7
  1. 9
      app/src/main/java/io/legado/app/model/Rss.kt
  2. 11
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt

@ -17,8 +17,13 @@ object Rss {
context: CoroutineContext = Dispatchers.IO
): Coroutine<MutableList<RssArticle>> {
return Coroutine.async(scope, context) {
val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAwait()
RssParserByRule.parseXML(response, rssSource)
val analyzeUrl = AnalyzeUrl(rssSource.sourceUrl)
val body = if (analyzeUrl.useWebView()) {
analyzeUrl.getResultByWebView(rssSource.sourceUrl)
} else {
analyzeUrl.getResponseAwait().body()
}
RssParserByRule.parseXML(body, rssSource)
}
}
}

@ -5,15 +5,12 @@ import io.legado.app.R
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.analyzeRule.AnalyzeRule
import retrofit2.Response
object RssParserByRule {
@Throws(Exception::class)
fun parseXML(response: Response<String>, rssSource: RssSource): MutableList<RssArticle> {
val xml = response.body()
if (xml.isNullOrBlank()) {
fun parseXML(body: String?, rssSource: RssSource): MutableList<RssArticle> {
if (body.isNullOrBlank()) {
throw Exception(
App.INSTANCE.getString(
R.string.error_get_web_content,
@ -23,11 +20,11 @@ object RssParserByRule {
}
var ruleArticles = rssSource.ruleArticles
if (ruleArticles.isNullOrBlank()) {
return RssParser.parseXML(xml, rssSource.sourceUrl)
return RssParser.parseXML(body, rssSource.sourceUrl)
} else {
val articleList = mutableListOf<RssArticle>()
val analyzeRule = AnalyzeRule()
analyzeRule.setContent(xml, rssSource.sourceUrl)
analyzeRule.setContent(body, rssSource.sourceUrl)
var reverse = true
if (ruleArticles.startsWith("-")) {
reverse = false

Loading…
Cancel
Save