Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from yujincheng08:master #189

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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