From a75eeb35c017b5b7c3277340ed13fa29d0a86347 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sat, 13 Jan 2024 22:10:20 +0800 Subject: [PATCH] Fix hidden bangumi e.g., season_id = 6423 --- .../biliroaming/hook/BangumiSeasonHook.kt | 3 +- .../biliroaming/network/BiliRoamingApi.kt | 52 ++----------------- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt index 31565b6e60..9e9504513c 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt @@ -23,7 +23,6 @@ import me.iacn.biliroaming.network.BiliRoamingApi.getAreaSearchBangumi import me.iacn.biliroaming.network.BiliRoamingApi.getContent import me.iacn.biliroaming.network.BiliRoamingApi.getSeason import me.iacn.biliroaming.network.BiliRoamingApi.getSpace -import me.iacn.biliroaming.network.BiliRoamingApi.getThaiSeason import me.iacn.biliroaming.utils.* import org.json.JSONObject import java.io.InputStream @@ -1335,7 +1334,7 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { lastSeasonInfo["season_id"] = it } ?: "0" - val seasonInfo = getThaiSeason(reqSeasonId, reqEpId)?.let { + val seasonInfo = getSeason(mapOf("season_id" to reqSeasonId, "ep_id" to reqEpId), null)?.toJSONObject()?.let { val eCode = it.optLong("code") if (eCode != 0L) { Log.e("Invalid thai season info reply, code $eCode, message ${it.optString("message")}") diff --git a/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt b/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt index a5d8e19ead..cbcba07de5 100644 --- a/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt +++ b/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt @@ -85,13 +85,11 @@ object BiliRoamingApi { val content = getContent(Uri.Builder().scheme("https").encodedAuthority(BILI_SEASON_URL).encodedQuery(signQuery(query)).toString()) content?.toJSONObject()?.optJSONObject("data") } ?: run { - val content = getContent(Uri.Builder().scheme("https").encodedAuthority("${BILI_MEDIA_URL}${seasonId}").toString()) - if (content != null) { -// fixHiddenSeason(it) -// fixSection(it) -// getExtraInfo(it, instance.accessKey) + val content = getContent(Uri.Builder().scheme("https").encodedAuthority("${BILI_MEDIA_URL}${seasonId}").toString()) ?: return@run null + val json = Regex("""[\w\W]*window\.__INITIAL_STATE__=(.*);\(function\(\)[\w\W]*""").matchEntire(content)?.groupValues?.get(1)?.toJSONObject() ?: return@run null + json.optJSONObject("mediaInfo")?.also { + it.put("modules", JSONArray().put(JSONObject().put("data", JSONObject().put("seasons", it.optJSONObject("seasons"))))) } - null } seasonJson = seasonJson?.let { @@ -131,48 +129,6 @@ object BiliRoamingApi { } } - @JvmStatic - fun getThaiSeason(seasonId: String, epId: String): JSONObject? { - val seasonIdStr = seasonId.toInt() - val cache = seasonCache.get() - val cacheTuple = if (seasonIdStr != 0) { - if (cache?.first == seasonIdStr) { - cache.third.await() - return cache.second.get()?.toJSONObject() - } else { - Triple(seasonIdStr, AtomicReference(null), CountDownLatch(1)).also { - seasonCache.compareAndSet(cache, it) - } - } - } else null - val thUrl = sPrefs.getString("th_server", null) ?: return null - val mobiApp = sPrefs.getString("th_server_platform", platform)!! - val fullUrl = Uri.Builder() - .scheme("https") - .encodedAuthority(thUrl + THAILAND_PATH_SEASON) - .appendQueryParameter("season_id", seasonId) - .appendQueryParameter("ep_id", epId) - .appendQueryParameter("s_locale", "zh_SG") - .appendQueryParameter("access_key", instance.getCustomizeAccessKey("th_server")) - .appendQueryParameter("mobi_app", "bstar_a") - .appendQueryParameter("build", "1080003") - .toString() - val seasonJson = getContent(fullUrl, mobiApp)?.toJSONObject()?.also { - it.optJSONObject("result")?.let { result -> - fixThailandSeason(result) - } - checkErrorToast(it, true) - } ?: run { - cacheTuple?.third?.countDown() - return null - } - return seasonJson.also { - if (seasonJson.optInt("code", -1) == 0) - cacheTuple?.second?.set(it.toString()) - cacheTuple?.third?.countDown() - } - } - @JvmStatic private fun fixSection(result: JSONObject) { val seasonId = result.optString("season_id")