Get funds from GP Exchange when unavailable from the archive page
This commit is contained in:
1 parent
5a5da0cace
commit
7edc58a6da
6 files changed
+63
-19
No files matched your search
@@ -669,7 +669,14 @@ object EhEngine {
|
||||
code = response.code
|
||||
headers = response.headers
|
||||
body = response.body.string()
|
||||
result = ArchiveParser.parse(body)!!
|
||||
result = ArchiveParser.parse(body!!)!!
|
||||
if (result.funds == null) {
|
||||
try {
|
||||
result.funds = getFunds()
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
ExceptionUtils.throwIfFatal(e)
|
||||
@@ -711,6 +718,7 @@ object EhEngine {
|
||||
val call = okHttpClient.newCall(request)
|
||||
var body: String? = null
|
||||
var headers: Headers? = null
|
||||
var result: String?
|
||||
var code = -1
|
||||
try {
|
||||
call.executeAsync().use { response ->
|
||||
@@ -718,15 +726,16 @@ object EhEngine {
|
||||
headers = response.headers
|
||||
body = response.body.string()
|
||||
transformException(code, headers, body, null)
|
||||
result = ArchiveParser.parseArchiveUrl(body!!)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
ExceptionUtils.throwIfFatal(e)
|
||||
transformException(code, headers, body, e)
|
||||
throw e
|
||||
}
|
||||
var result = ArchiveParser.parseArchiveUrl(body)
|
||||
if (!isHAtH) {
|
||||
if (result == null) {
|
||||
// Wait for the server to prepare archives
|
||||
delay(1000)
|
||||
try {
|
||||
call.clone().executeAsync().use { response ->
|
||||
@@ -734,13 +743,13 @@ object EhEngine {
|
||||
headers = response.headers
|
||||
body = response.body.string()
|
||||
transformException(code, headers, body, null)
|
||||
result = ArchiveParser.parseArchiveUrl(body!!)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
ExceptionUtils.throwIfFatal(e)
|
||||
transformException(code, headers, body, e)
|
||||
throw e
|
||||
}
|
||||
result = ArchiveParser.parseArchiveUrl(body)
|
||||
if (result == null) {
|
||||
throw EhException("Archive unavailable")
|
||||
}
|
||||
@@ -750,6 +759,29 @@ object EhEngine {
|
||||
return null
|
||||
}
|
||||
|
||||
@Throws(Throwable::class)
|
||||
suspend fun getFunds(): ArchiveParser.Funds? {
|
||||
val url = EhUrl.URL_FUNDS
|
||||
Log.d(TAG, url)
|
||||
val request = EhRequestBuilder(url, null).build()
|
||||
val call = okHttpClient.newCall(request)
|
||||
var body: String? = null
|
||||
var headers: Headers? = null
|
||||
var code = -1
|
||||
try {
|
||||
call.executeAsync().use { response ->
|
||||
code = response.code
|
||||
headers = response.headers
|
||||
body = response.body.string()
|
||||
return ArchiveParser.parseFunds(body!!)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
ExceptionUtils.throwIfFatal(e)
|
||||
transformException(code, headers, body, e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(Throwable::class)
|
||||
private suspend fun getProfileInternal(
|
||||
url: String, referer: String
|
||||
|
||||
@@ -44,6 +44,7 @@ object EhUrl {
|
||||
const val URL_SIGN_IN = "https://forums.e-hentai.org/index.php?act=Login"
|
||||
const val URL_REGISTER = "https://forums.e-hentai.org/index.php?act=Reg&CODE=00"
|
||||
const val URL_FORUMS = "https://forums.e-hentai.org/"
|
||||
const val URL_FUNDS = "https://e-hentai.org/exchange.php?t=gp"
|
||||
const val REFERER_EX = "https://$DOMAIN_EX"
|
||||
const val ORIGIN_EX = REFERER_EX
|
||||
const val REFERER_E = "https://$DOMAIN_E"
|
||||
|
||||
@@ -26,6 +26,8 @@ object ArchiveParser {
|
||||
Pattern.compile("<strong>(.*)</strong>.*<a href=\"([^\"]*)\">Click Here To Start Downloading</a>")
|
||||
private val PATTERN_CURRENT_FUNDS =
|
||||
Pattern.compile("<p>([\\d,]+) GP \\[[^]]*] ([\\d,]+) Credits \\[[^]]*]</p>")
|
||||
private val PATTERN_FUNDS =
|
||||
Pattern.compile("Available: ([\\d,]+) Credits.*Available: ([\\d,]+) kGP", Pattern.DOTALL)
|
||||
private val PATTERN_HATH_FORM =
|
||||
Pattern.compile("<form id=\"hathdl_form\" action=\"[^\"]*?or=([^=\"]*?)\" method=\"post\">")
|
||||
private val PATTERN_HATH_ARCHIVE =
|
||||
@@ -33,8 +35,7 @@ object ArchiveParser {
|
||||
private val PATTERN_NEED_HATH_CLIENT =
|
||||
Pattern.compile("You must have a H@H client assigned to your account to use this feature\\.")
|
||||
|
||||
fun parse(body: String?): Result? {
|
||||
body ?: return null
|
||||
fun parse(body: String): Result? {
|
||||
var m = PATTERN_HATH_FORM.matcher(body)
|
||||
if (!m.find()) {
|
||||
return null
|
||||
@@ -44,7 +45,7 @@ object ArchiveParser {
|
||||
val d = Jsoup.parse(body)
|
||||
val es = d.select("#db>div>div")
|
||||
for (e in es) {
|
||||
if (!e.attr("style").contains("color:#CCCCCC")) {
|
||||
if (e.childrenSize() > 0 && !e.attr("style").contains("color:#CCCCCC")) {
|
||||
try {
|
||||
val res = e.selectFirst("form>input")!!.attr("value")
|
||||
val name = e.selectFirst("form>div>input")!!.attr("value")
|
||||
@@ -77,8 +78,7 @@ object ArchiveParser {
|
||||
}
|
||||
|
||||
@Throws(NoHAtHClientException::class)
|
||||
fun parseArchiveUrl(body: String?): String? {
|
||||
body ?: return null
|
||||
fun parseArchiveUrl(body: String): String? {
|
||||
val m = PATTERN_NEED_HATH_CLIENT.matcher(body)
|
||||
if (m.find()) {
|
||||
throw NoHAtHClientException("No H@H client")
|
||||
@@ -92,6 +92,15 @@ object ArchiveParser {
|
||||
// TODO: Check more errors
|
||||
}
|
||||
|
||||
fun parseFunds(body: String): Funds? {
|
||||
val m = PATTERN_FUNDS.matcher(body)
|
||||
return if (m.find()) {
|
||||
val fundsC = ParserUtils.parseInt(m.group(1), 0)
|
||||
val fundsGP = ParserUtils.parseInt(m.group(2), 0) * 1000
|
||||
return Funds(fundsGP, fundsC)
|
||||
} else null
|
||||
}
|
||||
|
||||
class Archive(
|
||||
val res: String,
|
||||
val name: String,
|
||||
@@ -114,5 +123,5 @@ object ArchiveParser {
|
||||
|
||||
class Funds(var fundsGP: Int, var fundsC: Int)
|
||||
|
||||
class Result(val paramOr: String?, val archiveList: List<Archive>, val funds: Funds?)
|
||||
class Result(val paramOr: String?, val archiveList: List<Archive>, var funds: Funds?)
|
||||
}
|
||||
@@ -1466,13 +1466,12 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
mListView!!.adapter =
|
||||
ArrayAdapter(mDialog!!.context, R.layout.item_select_dialog, nameArray)
|
||||
if (funds != null) {
|
||||
mDialog!!.setTitle(
|
||||
getString(
|
||||
R.string.current_funds,
|
||||
funds.fundsGP,
|
||||
funds.fundsC
|
||||
)
|
||||
)
|
||||
var fundsGP = funds.fundsGP.toString()
|
||||
// Ex GP numbers are rounded down to the nearest thousand
|
||||
if (Settings.getGallerySite() == EhUrl.SITE_EX) {
|
||||
fundsGP += "+"
|
||||
}
|
||||
mDialog!!.setTitle(getString(R.string.current_funds, fundsGP, funds.fundsC))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1481,7 +1480,10 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
val context = context
|
||||
val activity = mainActivity
|
||||
if (null != context && null != activity && null != mArchiveList && position < mArchiveList!!.size) {
|
||||
if (mCurrentFunds != null) {
|
||||
if (mArchiveList!![position].name == "Insufficient Funds") {
|
||||
showTip(R.string.insufficient_funds, LENGTH_SHORT)
|
||||
return
|
||||
} else if (mCurrentFunds != null) {
|
||||
val cost = ParserUtils.parseInt(
|
||||
mArchiveList!![position].cost.removeSuffix("GP").removeSuffix("Credits"), 0
|
||||
)
|
||||
|
||||
@@ -531,7 +531,7 @@
|
||||
<string name="archive_original">原始档案</string>
|
||||
<string name="archive_resample">重采样档案</string>
|
||||
<string name="download_archive_failure_no_hath">下载压缩包需要 H@H 客户端</string>
|
||||
<string name="current_funds">资金:%d GP,%d Credits</string>
|
||||
<string name="current_funds">资金:%s GP,%d Credits</string>
|
||||
<string name="insufficient_funds">余额不足</string>
|
||||
<string name="settings_privacy">隐私</string>
|
||||
<string name="settings_privacy_secure">不允许屏幕抓取</string>
|
||||
|
||||
@@ -598,7 +598,7 @@
|
||||
<string name="archive_original">Original archive</string>
|
||||
<string name="archive_resample">Resample archive</string>
|
||||
<string name="download_archive_failure_no_hath">Need H@H client for archive download</string>
|
||||
<string name="current_funds">Funds: %d GP, %d Credits</string>
|
||||
<string name="current_funds">Funds: %s GP, %d Credits</string>
|
||||
<string name="insufficient_funds">Insufficient Funds</string>
|
||||
<string name="settings_privacy">Privacy</string>
|
||||
<string name="settings_privacy_secure">Prevent screenshots</string>
|
||||
|
||||
Reference in new issue
Block a user