Skip to content

Commit

Permalink
Partial fix for epid of playurl
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Feb 28, 2023
1 parent 25cdd47 commit f2309d9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
28 changes: 21 additions & 7 deletions app/src/main/java/me/iacn/biliroaming/hook/BangumiPlayUrlHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
|| needForceProxy(response)
) {
try {
val content = getPlayUrl(reconstructQuery(request))
val content = getPlayUrl(reconstructQuery(request, response))
countDownLatch?.countDown()
content?.let {
Log.toast("已从代理服务器获取播放地址\n如加载缓慢或黑屏,可去漫游设置中测速并设置 UPOS")
Expand Down Expand Up @@ -240,7 +240,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
).new()
if (needProxy(response)) {
try {
val content = getPlayUrl(reconstructQuery(request))
val content = getPlayUrl(reconstructQuery(request, response))
countDownLatch?.countDown()
content?.let {
Log.toast("已从代理服务器获取播放地址\n如加载缓慢或黑屏,可去漫游设置中测速并设置 UPOS")
Expand Down Expand Up @@ -396,13 +396,20 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
return PlayViewReply.parseFrom(serializedRequest).business.isPreview
}

private fun reconstructQuery(request: Any): String? {
private fun reconstructQuery(request: Any, response: Any): String? {
val serializedRequest = request.callMethodAs<ByteArray>("toByteArray")
val req = PlayViewReq.parseFrom(serializedRequest)
val episodeInfo by lazy {
response.callMethodOrNull("getBusiness")?.callMethodOrNull("getEpisodeInfo")
}
// CANNOT use reflection for compatibility with Xpatch
return Uri.Builder().run {
appendQueryParameter("ep_id", req.epId.toString())
appendQueryParameter("cid", req.cid.toString())
appendQueryParameter("ep_id", req.epId.let {
if (it != 0L) it else episodeInfo?.callMethodOrNullAs<Int>("getEpId") ?: 0
}.toString())
appendQueryParameter("cid", req.cid.let {
if (it != 0L) it else episodeInfo?.callMethodOrNullAs<Long>("getCid") ?: 0
}.toString())
appendQueryParameter("qn", req.qn.toString())
appendQueryParameter("fnver", req.fnver.toString())
appendQueryParameter("fnval", req.fnval.toString())
Expand All @@ -424,7 +431,7 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
}
val videoCodeCid = jsonContent.optInt("video_codecid")
val serializedResponse = playViewReply {
val serializedResponse = PlayViewReply.parseFrom(response.callMethodAs<ByteArray>("toByteArray")).copy {
playConf = playAbilityConf {
dislikeDisable = true
likeDisable = true
Expand Down Expand Up @@ -531,8 +538,15 @@ class BangumiPlayUrlHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}
}

business = businessInfo {
business = business.copy {
isPreview = jsonContent.optInt("is_preview", 0) == 1
episodeInfo = episodeInfo.copy {
seasonInfo = seasonInfo.copy {
rights = seasonRights {
canWatch = 1
}
}
}
}

viewInfo = viewInfo {
Expand Down
76 changes: 73 additions & 3 deletions app/src/main/proto/me/iacn/biliroaming/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,74 @@ message PlayViewReq {
optional bool is_preview = 0xd;
}

message ContinuePlayInfo {

}

message ClipInfo {

}

message QualityExtInfo {

}

message RecordInfo {

}

message UserStatus {
}

message SeasonRights {
optional int32 can_watch = 0x1;
}

message SeasonInfo {
optional int32 season_id = 0x1;
optional int32 season_type = 0x2;
optional int32 season_status = 0x3;
optional string cover = 0x4;
optional string title = 0x5;
optional SeasonRights rights = 0x6;
}

message EpisodeInfo {
optional int32 ep_id = 0x1;
optional int64 cid = 0x2;
optional int64 aid = 0x3;
optional int64 ep_status = 0x4;
optional SeasonInfo season_info = 0x5;
optional string cover = 0x6;
optional string title = 0x7;
optional Interaction interaction = 0x8;
}

message EpisodeAdvertisementInfo {

}

message BusinessInfo {
optional bool is_preview = 1;
optional bool bp = 2;
optional string marlin_token = 3;
optional bool is_preview = 0x1;
optional bool bp = 0x2;
optional string marlin_token = 0x3;
optional string playback_speed_color = 0x4;
optional ContinuePlayInfo continue_play_info = 0x5;
repeated ClipInfo clip_info = 0x6;
optional int32 inline_type = 0x7;
optional int32 ep_whole_duration = 0x8;
optional PlayViewDimension dimension = 0x9;
repeated QualityExtInfo quality_ext_map = 0xa;
map<string, int32> ext_map = 0xb;
optional bool drm_tech_type = 0xc;
optional int32 limit_action_type = 0xd;
optional bool is_drm = 0xe;
optional RecordInfo record_info = 0xf;
optional int32 vip_status = 0x10;
optional bool is_live_pre = 0x11;
optional EpisodeInfo episode_info = 0x12;
optional EpisodeAdvertisementInfo episode_advertisement_info = 0x13;
optional UserStatus user_status = 0x14;
}

message PlayAbilityConf {
Expand Down Expand Up @@ -276,6 +340,12 @@ message Dimension {
optional int64 rotate = 0x3;
}

message PlayViewDimension {
optional int32 width = 0x1;
optional int32 height = 0x2;
optional int32 rotate = 0x3;
}

message StaffInfo {}

message Arc {
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ android.enableAppCompileTimeRClass=true
android.enableR8.fullMode=true
android.experimental.enableNewResourceShrinker=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true
org.gradle.unsafe.configuration-cache=true

appVerName=1.6.9

0 comments on commit f2309d9

Please sign in to comment.