Skip to content

Commit

Permalink
feat: PegasusHook support viewUnite (#1564)
Browse files Browse the repository at this point in the history
支持viewUnite的视频下方推荐过滤
  • Loading branch information
CodePwn2021 authored Nov 17, 2024
1 parent 18116c7 commit e45e4d5
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion app/src/main/java/me/iacn/biliroaming/hook/PegasusHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
else it < hideLowPlayCountLimit
}
}
private fun isLowCountVideoUnite(count: Long): Boolean {
if (hideLowPlayCountLimit == 0L) return false
return count < hideLowPlayCountLimit
}

// 屏蔽指定播放时长
private fun durationVideo(obj: Any): Boolean {
Expand All @@ -126,6 +130,13 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
return true
return hideShortDurationLimit != 0 && duration < hideShortDurationLimit
}
private fun durationVideoUnite(duration: Long): Boolean {
if (hideLongDurationLimit == 0 && hideShortDurationLimit == 0)
return false
if (hideLongDurationLimit != 0 && duration > hideLongDurationLimit)
return true
return hideShortDurationLimit != 0 && duration < hideShortDurationLimit
}

private fun isContainsBlockKwd(obj: Any): Boolean {
// 屏蔽标题关键词
Expand Down Expand Up @@ -196,6 +207,46 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
return false
}

private fun isContainsBlockKwdUnite(card: Any): Boolean {
if (card.callMethodAs("hasBasicInfo")) {
card.callMethodAs<Any>("getBasicInfo").let { basicInfo ->
// 屏蔽标题关键词
if (kwdFilterTitleList.isNotEmpty()) {
val title = basicInfo.callMethodAs<String>("getTitle")
if (kwdFilterTitleRegexMode && title.isNotEmpty()) {
if (kwdFilterTitleRegexes.any { title.contains(it) })
return true
} else if (title.isNotEmpty()) {
if (kwdFilterTitleList.any { title.contains(it) })
return true
}
}

basicInfo.callMethodAs<Any>("getAuthor").let { author ->
// 屏蔽UID
if (kwdFilterUidList.isNotEmpty()) {
val uid = author.callMethodAs<Long>("getMid")
if (uid != 0L && kwdFilterUidList.any { it == uid })
return true
}

// 屏蔽UP主
if (kwdFilterUpnameList.isNotEmpty()) {
val upName = author.callMethodAs<String>("getTitle")
if (kwdFilterUpnameRegexMode && upName.isNotEmpty()) {
if (kwdFilterUpnameRegexes.any { upName.contains(it) })
return true
} else if (upName.isNotEmpty()) {
if (kwdFilterUpnameList.any { upName.contains(it) })
return true
}
}
}
}
}
return false
}

private fun ArrayList<Any>.appendReasons() = forEach { item ->
val title = item.getObjectFieldAs<String?>("title").orEmpty()
val rcmdReason = item.runCatchingOrNull {
Expand Down Expand Up @@ -486,6 +537,7 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {

fun MutableList<Any>.filterUnite() = removeAll {
val allowTypeList = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
var shouldFiltered = false
allowTypeList.removeAll { digit ->
(removeRelateOnlyAv && digit != 1) || (removeRelatePromote && digit in listOf(
3, // Resource, like mall
Expand All @@ -494,7 +546,35 @@ class PegasusHook(classLoader: ClassLoader) : BaseHook(classLoader) {
10 // SPECIAL
))
}
removeRelateNothing || it.callMethodAs("getRelateCardTypeValue") !in allowTypeList
// av filter
if (applyToRelate) {
if (it.callMethodAs("hasAv")) {
it.callMethodAs<Any>("getAv").let { av ->
val duration = av.callMethodAs<Long>("getDuration")
if (durationVideoUnite(duration)) {
shouldFiltered = true
return@let
}
if (av.callMethodAs("hasStat")) {
av.callMethodAs<Any>("getStat").let { stat ->
if (stat.callMethodAs("hasVt")) {
stat.callMethodAs<Any>("getVt").let { vt ->
if (isLowCountVideoUnite(vt.callMethodAs<Long>("getValue"))) {
shouldFiltered = true
return@let
}
}
}
}
}
}
if (isContainsBlockKwdUnite(it)) {
shouldFiltered = true
}
}
// todo: support rcmd
}
removeRelateNothing || it.callMethodAs("getRelateCardTypeValue") !in allowTypeList || shouldFiltered
}
instance.viewMossClass?.hookAfterMethod("view", instance.viewReqClass) { param ->
param.result ?: return@hookAfterMethod
Expand Down

0 comments on commit e45e4d5

Please sign in to comment.