pull/1274/head
gedoor 3 years ago
parent 612d11a3ef
commit 02648dd8b8
  1. 62
      app/src/main/java/io/legado/app/model/rss/Rss.kt

@ -12,6 +12,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@Suppress("MemberVisibilityCanBePrivate")
object Rss { object Rss {
fun getArticles( fun getArticles(
@ -23,18 +24,27 @@ object Rss {
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<RssResult> { ): Coroutine<RssResult> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val ruleData = RuleData() getArticlesAwait(sortName, sortUrl, rssSource, page)
val analyzeUrl = AnalyzeUrl(
sortUrl,
page = page,
ruleData = ruleData,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssSource.sourceUrl).body
RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData)
} }
} }
suspend fun getArticlesAwait(
sortName: String,
sortUrl: String,
rssSource: RssSource,
page: Int,
): RssResult {
val ruleData = RuleData()
val analyzeUrl = AnalyzeUrl(
sortUrl,
page = page,
ruleData = ruleData,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssSource.sourceUrl).body
return RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData)
}
fun getContent( fun getContent(
scope: CoroutineScope, scope: CoroutineScope,
rssArticle: RssArticle, rssArticle: RssArticle,
@ -43,19 +53,27 @@ object Rss {
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<String> { ): Coroutine<String> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl( getContentAwait(rssArticle, ruleContent, rssSource)
rssArticle.link,
baseUrl = rssArticle.origin,
ruleData = rssArticle,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssArticle.origin).body
Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}")
Debug.log(rssSource.sourceUrl, body, state = 20)
val analyzeRule = AnalyzeRule(rssArticle, rssSource)
analyzeRule.setContent(body)
.setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))
analyzeRule.getString(ruleContent)
} }
} }
suspend fun getContentAwait(
rssArticle: RssArticle,
ruleContent: String,
rssSource: RssSource,
): String {
val analyzeUrl = AnalyzeUrl(
rssArticle.link,
baseUrl = rssArticle.origin,
ruleData = rssArticle,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssArticle.origin).body
Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}")
Debug.log(rssSource.sourceUrl, body, state = 20)
val analyzeRule = AnalyzeRule(rssArticle, rssSource)
analyzeRule.setContent(body)
.setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))
return analyzeRule.getString(ruleContent)
}
} }
Loading…
Cancel
Save