Skip to content

Commit

Permalink
feat: remove "b23.tv" links for user profile page/live rooms (yujinch…
Browse files Browse the repository at this point in the history
  • Loading branch information
whitescent authored Nov 21, 2023
1 parent 697bdac commit 45259d0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions app/src/main/java/me/iacn/biliroaming/hook/ShareHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) {

private fun transformUrl(url: String, transformAv: Boolean): String {
val target = Uri.parse(url)
val bv = if (transformAv) target.path?.split("/")
?.firstOrNull { it.startsWith("BV") && it.length == 12 }
else null
val bv = if (transformAv) {
target.path?.split("/")?.firstOrNull { it.startsWith("BV") && it.length == 12 }
} else {
null
}
val av = bv?.let { "av${bv2av(bv)}" }
val newUrl = target.buildUpon()
if (av != null) {
Expand All @@ -42,9 +44,11 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) {
}.filter {
it.size == 2
}.mapNotNull {
if (it[0] == "p" || it[0] == "t") "${it[0]}=${it[1]}"
else if (it[0] == "start_progress") "start_progress=${it[1]}&t=${it[1].toLong() / 1000}"
else null
when {
it[0] == "p" || it[0] == "t" -> "${it[0]}=${it[1]}"
it[0] == "start_progress" -> "start_progress=${it[1]}&t=${it[1].toLong() / 1000}"
else -> null
}
}.joinToString("&", postfix = "&unique_k=114514")
newUrl.encodedQuery(query)
} else {
Expand Down Expand Up @@ -73,13 +77,9 @@ class ShareHook(classLoader: ClassLoader) : BaseHook(classLoader) {
content?.let {
contentUrlPattern.matchEntire(it)?.groups?.get(1)?.value
}?.let { contentUrl ->
(param.thisObject.getObjectField("link")?.let { it as String }
?: contentUrl).resolveB23URL().takeIf { it.contains("/video/") }
?.let { realUrl ->
param.result = content.replace(
contentUrl, transformUrl(realUrl, miniProgramEnabled)
)
}
val resolvedUrl = (param.thisObject.getObjectField("link")?.let { it as String } ?: contentUrl)
.resolveB23URL()
param.result = content.replace(contentUrl, transformUrl(resolvedUrl, miniProgramEnabled))
}
}
}
Expand Down

0 comments on commit 45259d0

Please sign in to comment.