From 02648dd8b868f8d70cdad664caa20dd0d2ee7027 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 26 Aug 2021 09:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/rss/Rss.kt | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index 22f0a6c02..51539ee0a 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlin.coroutines.CoroutineContext +@Suppress("MemberVisibilityCanBePrivate") object Rss { fun getArticles( @@ -23,18 +24,27 @@ object Rss { context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - val ruleData = RuleData() - 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) + getArticlesAwait(sortName, sortUrl, rssSource, page) } } + 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( scope: CoroutineScope, rssArticle: RssArticle, @@ -43,19 +53,27 @@ object Rss { context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - 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)) - analyzeRule.getString(ruleContent) + getContentAwait(rssArticle, ruleContent, rssSource) } } + + 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) + } } \ No newline at end of file