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