|
|
|
@ -12,6 +12,7 @@ import kotlinx.coroutines.CoroutineScope |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
@Suppress("MemberVisibilityCanBePrivate") |
|
|
|
|
object Rss { |
|
|
|
|
|
|
|
|
|
fun getArticles( |
|
|
|
@ -23,6 +24,16 @@ object Rss { |
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
): Coroutine<RssResult> { |
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
getArticlesAwait(sortName, sortUrl, rssSource, page) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
suspend fun getArticlesAwait( |
|
|
|
|
sortName: String, |
|
|
|
|
sortUrl: String, |
|
|
|
|
rssSource: RssSource, |
|
|
|
|
page: Int, |
|
|
|
|
): RssResult { |
|
|
|
|
val ruleData = RuleData() |
|
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
|
sortUrl, |
|
|
|
@ -31,8 +42,7 @@ object Rss { |
|
|
|
|
headerMapF = rssSource.getHeaderMap() |
|
|
|
|
) |
|
|
|
|
val body = analyzeUrl.getStrResponse(rssSource.sourceUrl).body |
|
|
|
|
RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData) |
|
|
|
|
} |
|
|
|
|
return RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getContent( |
|
|
|
@ -43,6 +53,15 @@ object Rss { |
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
): Coroutine<String> { |
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
getContentAwait(rssArticle, ruleContent, rssSource) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
suspend fun getContentAwait( |
|
|
|
|
rssArticle: RssArticle, |
|
|
|
|
ruleContent: String, |
|
|
|
|
rssSource: RssSource, |
|
|
|
|
): String { |
|
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
|
rssArticle.link, |
|
|
|
|
baseUrl = rssArticle.origin, |
|
|
|
@ -55,7 +74,6 @@ object Rss { |
|
|
|
|
val analyzeRule = AnalyzeRule(rssArticle, rssSource) |
|
|
|
|
analyzeRule.setContent(body) |
|
|
|
|
.setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link)) |
|
|
|
|
analyzeRule.getString(ruleContent) |
|
|
|
|
} |
|
|
|
|
return analyzeRule.getString(ruleContent) |
|
|
|
|
} |
|
|
|
|
} |