Skip to content

Commit a70d819

Browse files
committed
fix bangumiPlayUrlHook for hk,tw
1 parent 0ab3190 commit a70d819

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

app/src/main/java/me/iacn/biliroaming/BiliBiliPackage.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,8 @@ class BiliBiliPackage constructor(private val mClassLoader: ClassLoader, mContex
165165
val playSpeedManager by Weak { mHookInfo.playSpeedManager from mClassLoader }
166166

167167
// for v8.17.0+
168-
val useNewMossFunc = instance.viewMossClass?.run {
169-
for (m in declaredMethods) {
170-
if (m.name == "executeRelatesFeed") {
171-
return@run true
172-
}
173-
}
174-
return@run false
168+
val useNewMossFunc = instance.viewMossClass?.declaredMethods?.any {
169+
it.name == "executeRelatesFeed"
175170
} ?: false
176171

177172
val ids: Map<String, Int> by lazy {

app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,24 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
313313
.on(mClassLoader).new()
314314
val supplementAny = response.callMethod("getSupplement")
315315
val typeUrl = supplementAny?.callMethodAs<String>("getTypeUrl")
316+
316317
// Only handle pgc video
317-
if (param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL)
318+
///////////////////
319+
// newPlayUnite:
320+
// request.vod.cid, response.play_arc.cid need skip
321+
val requestVod = request.callMethod("getVod")
322+
val reqCid = requestVod?.callMethodAs<Long>("getCid")
323+
324+
val responsePlayArc = response.callMethod("getPlayArc")
325+
val respCid = responsePlayArc?.callMethodAs<Long>("getCid")
326+
327+
val isThai = reqCid != 0.toLong() && reqCid != respCid
328+
if (
329+
param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL && !isThai
330+
) {
318331
return@hookAfterMethod
332+
}
333+
319334
val extraContent = request.callMethodAs<Map<String, String>>("getExtraContentMap")
320335
val seasonId = extraContent.getOrDefault("season_id", "0")
321336
val reqEpId = extraContent.getOrDefault("ep_id", "0").toLong()
@@ -324,7 +339,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
324339
val supplement = supplementAny?.callMethod("getValue")
325340
?.callMethodAs<ByteArray>("toByteArray")
326341
?.let { PlayViewReply.parseFrom(it) } ?: playViewReply {}
327-
if (needProxyUnite(response, supplement)) {
342+
if (needProxyUnite(response, supplement) || isThai) {
328343
try {
329344
val serializedRequest = request.callMethodAs<ByteArray>("toByteArray")
330345
val req = PlayViewUniteReq.parseFrom(serializedRequest)
@@ -350,7 +365,6 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
350365
param.result = purifyViewInfo(response, supplement)
351366
}
352367
}
353-
/*
354368
// 7.41.0+ use async
355369
hookBeforeMethod(
356370
"playViewUnite",
@@ -389,9 +403,24 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
389403
.on(mClassLoader).new()
390404
val supplementAny = response.callMethod("getSupplement")
391405
val typeUrl = supplementAny?.callMethodAs<String>("getTypeUrl")
406+
392407
// Only handle pgc video
393-
if (originalResp != null && typeUrl != PGC_ANY_MODEL_TYPE_URL)
408+
///////////////////
409+
// newPlayUnite:
410+
// request.vod.cid, response.play_arc.cid
411+
val requestVod = request.callMethod("getVod")
412+
val reqCid = requestVod?.callMethodAs<Long>("getCid")
413+
414+
val responsePlayArc = response.callMethod("getPlayArc")
415+
val respCid = responsePlayArc?.callMethodAs<Long>("getCid")
416+
417+
val isThai = reqCid != 0.toLong() && reqCid != respCid
418+
if (
419+
param.result != null && typeUrl != PGC_ANY_MODEL_TYPE_URL && !isThai
420+
) {
394421
return@mossResponseHandlerReplaceProxy null
422+
}
423+
395424
val extraContent =
396425
request.callMethodAs<Map<String, String>>("getExtraContentMap")
397426
val seasonId = extraContent.getOrDefault("season_id", "0")
@@ -401,7 +430,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
401430
val supplement = supplementAny?.callMethod("getValue")
402431
?.callMethodAs<ByteArray>("toByteArray")
403432
?.let { PlayViewReply.parseFrom(it) } ?: playViewReply {}
404-
val newResponse = if (needProxyUnite(response, supplement)) {
433+
val newResponse = if (needProxyUnite(response, supplement) || isThai) {
405434
try {
406435
val serializedRequest = request.callMethodAs<ByteArray>("toByteArray")
407436
val req = PlayViewUniteReq.parseFrom(serializedRequest)
@@ -428,7 +457,6 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
428457
newResponse
429458
}
430459
}
431-
*/
432460
}
433461
instance.playURLMossClass?.hookBeforeMethod(
434462
if (instance.useNewMossFunc) "executePlayView" else "playView",

0 commit comments

Comments
 (0)