Cleanup EhEngine
This commit is contained in:
1 parent
f2641adfd2
commit
2ce2f0ee9b
2 files changed
+10
-20
No files matched your search
@@ -16,6 +16,7 @@
|
||||
package com.hippo.ehviewer.client
|
||||
|
||||
import android.util.Log
|
||||
import arrow.fx.coroutines.parZip
|
||||
import com.hippo.ehviewer.AppConfig
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.GetText
|
||||
@@ -48,8 +49,6 @@ import com.hippo.ehviewer.client.parser.VoteTagParser
|
||||
import com.hippo.ehviewer.dailycheck.showEventNotification
|
||||
import com.hippo.ehviewer.dailycheck.today
|
||||
import com.hippo.network.StatusCodeException
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import moe.tarsin.coroutines.runSuspendCatching
|
||||
import okhttp3.Headers
|
||||
@@ -409,9 +408,8 @@ object EhEngine {
|
||||
gid: Long,
|
||||
token: String?,
|
||||
): ArchiveParser.Result {
|
||||
val referer = EhUrl.getGalleryDetailUrl(gid, token)
|
||||
return ehRequest(url, referer).executeAndParsingWith(ArchiveParser::parse)!!
|
||||
.apply { funds = funds ?: getFunds() }
|
||||
return ehRequest(url, EhUrl.getGalleryDetailUrl(gid, token)).executeAndParsingWith(ArchiveParser::parse)
|
||||
.apply { funds = funds ?: ehRequest(EhUrl.URL_FUNDS).executeAndParsingWith(HomeParser::parseFunds) }
|
||||
}
|
||||
|
||||
suspend fun downloadArchive(
|
||||
@@ -458,19 +456,11 @@ object EhEngine {
|
||||
return null
|
||||
}
|
||||
|
||||
private suspend fun getFunds(): HomeParser.Funds {
|
||||
return ehRequest(EhUrl.URL_FUNDS).executeAndParsingWith(HomeParser::parseFunds)
|
||||
}
|
||||
|
||||
private suspend fun getImageLimitsInternal(): HomeParser.Limits {
|
||||
return ehRequest(EhUrl.URL_HOME).executeAndParsingWith(HomeParser::parse)
|
||||
}
|
||||
|
||||
suspend fun getImageLimits(): HomeParser.Result = coroutineScope {
|
||||
val limitsDeferred = async { getImageLimitsInternal() }
|
||||
val fundsDeferred = async { getFunds() }
|
||||
HomeParser.Result(limitsDeferred.await(), fundsDeferred.await())
|
||||
}
|
||||
suspend fun getImageLimits() = parZip(
|
||||
{ ehRequest(EhUrl.URL_HOME).executeAndParsingWith(HomeParser::parse) },
|
||||
{ ehRequest(EhUrl.URL_FUNDS).executeAndParsingWith(HomeParser::parseFunds) },
|
||||
{ limits, funds -> HomeParser.Result(limits, funds) },
|
||||
)
|
||||
|
||||
suspend fun resetImageLimits(): HomeParser.Limits? {
|
||||
return ehRequest(EhUrl.URL_HOME) {
|
||||
|
||||
@@ -30,8 +30,8 @@ object ArchiveParser {
|
||||
private val PATTERN_NEED_HATH_CLIENT =
|
||||
Regex("You must have a H@H client assigned to your account to use this feature\\.")
|
||||
|
||||
fun parse(body: String): Result? {
|
||||
val m = PATTERN_HATH_FORM.find(body) ?: return null
|
||||
fun parse(body: String): Result {
|
||||
val m = PATTERN_HATH_FORM.find(body)!!
|
||||
val paramOr = m.groupValues[1]
|
||||
val archiveList = ArrayList<Archive>()
|
||||
Jsoup.parse(body).select("#db>div>div").forEach { element ->
|
||||
|
||||
Reference in new issue
Block a user