Skip to content

Commit

Permalink
Fix compatibility of search with play ver
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Jan 3, 2021
1 parent 06a0a3b commit 0a47879
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) {
url.startsWith("https://appintl.biliapi.net/intl/gateway/app/view")) &&
body.getIntField("code") == FAIL_CODE) {
fixView(body, url)
} else if (url != null && url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type")) {
} else if (url != null && url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type") && !url.contains("type=$TH_TYPE")) {
fixPlaySearchType(body, url)
} else if (instance.generalResponseClass?.isInstance(body) == true) {
val data = body.getObjectField("data") ?: return@hookBeforeAllConstructors
if (data.javaClass == searchAllResultClass) {
addThailandTag(data)
}
if (url != null && data.javaClass == bangumiSearchPageClass && url.startsWith("https://app.bilibili.com/x/v2/search/type") && url.contains("type=$TH_TYPE")) {
if (url != null && data.javaClass == bangumiSearchPageClass &&
(url.startsWith("https://app.bilibili.com/x/v2/search/type") ||
url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type"))
&& url.contains("type=$TH_TYPE")) {
body.setObjectField("data", retrieveThailandSearch(data, url))
}
}
Expand Down Expand Up @@ -156,7 +159,7 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) {

if (sPrefs.getBoolean("hidden", false) && sPrefs.getBoolean("search_th", false)) {
"com.bilibili.bangumi.ui.page.search.BangumiSearchResultFragment".findClassOrNull(mClassLoader)?.run {
hookBeforeMethod("loadFirstPage") { param ->
hookBeforeMethod("setUserVisibleCompat", Boolean::class.javaPrimitiveType) { param ->
param.thisObject.callMethodAs<Bundle>("getArguments").run {
if (getString("from") == "th") {
declaredFields.filter {
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ object BiliRoamingApi {
"build" to "1001310",
"mobi_app" to "bstar_a",
"platform" to "android",
"s_locale" to "zh_SG"
"s_locale" to "zh_SG",
"c_locale" to "zh_SG"
)))
.toString()
return getContent(uri)?.replace("bstar://bangumi/season/", "https://bangumi.bilibili.com/anime/")
Expand Down Expand Up @@ -388,7 +389,7 @@ object BiliRoamingApi {

@SuppressLint("SetJavaScriptEnabled")
fun getContent(urlString: String): String? {
val timeout = 5000
val timeout = 10000
return try {
// Work around for android 7
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N &&
Expand All @@ -415,7 +416,10 @@ object BiliRoamingApi {
view?.loadUrl("javascript:listener.callback(document.documentElement.innerText)")
}
}
webView.loadUrl(urlString)
webView.loadUrl(urlString, mapOf(
"x-from-biliroaming" to BuildConfig.VERSION_NAME,
"Build" to BuildConfig.VERSION_CODE.toString()
))
}
try {
if (!listener.latch.await((timeout * 2).toLong(), TimeUnit.MILLISECONDS)) {
Expand Down

0 comments on commit 0a47879

Please sign in to comment.