Skip to content

Commit

Permalink
Fix hidden bangumi
Browse files Browse the repository at this point in the history
e.g., season_id = 6423
  • Loading branch information
yujincheng08 committed Jan 13, 2024
1 parent 6d14523 commit a75eeb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")}")
Expand Down
52 changes: 4 additions & 48 deletions app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String?>(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")
Expand Down

0 comments on commit a75eeb3

Please sign in to comment.