mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-23 18:37:14 +02:00
feat(YouTube/Hide feed components): add Hide related videos
setting
This commit is contained in:
parent
697dc74169
commit
389f414acc
@ -7,6 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.shared.litho.LithoFilterPatch
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.BreakingNewsFingerprint
|
||||
@ -19,32 +20,41 @@ import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabBuild
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabRendererFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserParentFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.EngagementPanelUpdateFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.FilterBarHeightFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.LatestVideosButtonFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.LinearLayoutManagerItemCountsFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.RelatedChipCloudFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.SearchResultsChipBarFingerprint
|
||||
import app.revanced.patches.youtube.feed.components.fingerprints.ShowMoreButtonFingerprint
|
||||
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||
import app.revanced.patches.youtube.utils.fingerprints.EngagementPanelBuilderFingerprint
|
||||
import app.revanced.patches.youtube.utils.fingerprints.ScrollTopParentFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.FEED_CLASS_DESCRIPTOR
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.FEED_PATH
|
||||
import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch
|
||||
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CaptionToggleContainer
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.util.alsoResolve
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.getWalkerMethod
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
|
||||
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
|
||||
import app.revanced.util.patch.BaseBytecodePatch
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
|
||||
@Suppress("unused")
|
||||
object FeedComponentsPatch : BaseBytecodePatch(
|
||||
@ -67,12 +77,14 @@ object FeedComponentsPatch : BaseBytecodePatch(
|
||||
ChannelListSubMenuTabletSyntheticFingerprint,
|
||||
ChannelTabRendererFingerprint,
|
||||
ElementParserParentFingerprint,
|
||||
EngagementPanelBuilderFingerprint,
|
||||
FilterBarHeightFingerprint,
|
||||
LatestVideosButtonFingerprint,
|
||||
LinearLayoutManagerItemCountsFingerprint,
|
||||
RelatedChipCloudFingerprint,
|
||||
ScrollTopParentFingerprint,
|
||||
SearchResultsChipBarFingerprint,
|
||||
ShowMoreButtonFingerprint
|
||||
ShowMoreButtonFingerprint,
|
||||
)
|
||||
) {
|
||||
private const val CAROUSEL_SHELF_FILTER_CLASS_DESCRIPTOR =
|
||||
@ -85,6 +97,8 @@ object FeedComponentsPatch : BaseBytecodePatch(
|
||||
"$COMPONENTS_PATH/FeedVideoViewsFilter;"
|
||||
private const val KEYWORD_FILTER_CLASS_DESCRIPTOR =
|
||||
"$COMPONENTS_PATH/KeywordContentFilter;"
|
||||
private const val RELATED_VIDEO_CLASS_DESCRIPTOR =
|
||||
"$FEED_PATH/RelatedVideoPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
@ -139,6 +153,58 @@ object FeedComponentsPatch : BaseBytecodePatch(
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for hide relative video
|
||||
|
||||
fun Method.indexOfEngagementPanelBuilderInstruction(targetMethod: MutableMethod) =
|
||||
indexOfFirstInstruction {
|
||||
opcode == Opcode.INVOKE_DIRECT &&
|
||||
MethodUtil.methodSignaturesMatch(targetMethod, getReference<MethodReference>()!!)
|
||||
}
|
||||
|
||||
EngagementPanelBuilderFingerprint.resultOrThrow().let {
|
||||
it.mutableClass.methods.filter { method ->
|
||||
method.indexOfEngagementPanelBuilderInstruction(it.mutableMethod) >= 0
|
||||
}.forEach { method ->
|
||||
method.apply {
|
||||
val index = indexOfEngagementPanelBuilderInstruction(it.mutableMethod)
|
||||
val register = getInstruction<OneRegisterInstruction>(index + 1).registerA
|
||||
|
||||
addInstruction(
|
||||
index + 2,
|
||||
"invoke-static {v$register}, " +
|
||||
"$RELATED_VIDEO_CLASS_DESCRIPTOR->showEngagementPanel(Ljava/lang/Object;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EngagementPanelUpdateFingerprint.alsoResolve(
|
||||
context, EngagementPanelBuilderFingerprint
|
||||
).mutableMethod.addInstruction(
|
||||
0,
|
||||
"invoke-static {}, $RELATED_VIDEO_CLASS_DESCRIPTOR->hideEngagementPanel()V"
|
||||
)
|
||||
|
||||
// BytecodeUtils.getWalkerMethod must be used here
|
||||
// Otherwise, MethodWalker finds the wrong class in YouTube 18.29.38:
|
||||
// https://github.com/ReVanced/revanced-patcher/issues/309
|
||||
LinearLayoutManagerItemCountsFingerprint.resultOrThrow().let {
|
||||
val methodWalker = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex)
|
||||
methodWalker.apply {
|
||||
val index = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT)
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
addInstructions(
|
||||
index + 1, """
|
||||
invoke-static {v$register}, $RELATED_VIDEO_CLASS_DESCRIPTOR->overrideItemCounts(I)I
|
||||
move-result v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for hide subscriptions channel section for tablet
|
||||
|
||||
arrayOf(
|
||||
|
@ -0,0 +1,21 @@
|
||||
package app.revanced.patches.youtube.feed.components.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
internal object EngagementPanelUpdateFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
parameters = listOf("L", "Z"),
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.indexOfFirstInstruction {
|
||||
opcode == Opcode.INVOKE_VIRTUAL &&
|
||||
getReference<MethodReference>().toString() == "Ljava/util/ArrayDeque;->pop()Ljava/lang/Object;"
|
||||
} >= 0
|
||||
}
|
||||
)
|
@ -0,0 +1,19 @@
|
||||
package app.revanced.patches.youtube.feed.components.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal object LinearLayoutManagerItemCountsFingerprint : MethodFingerprint(
|
||||
returnType = "I",
|
||||
accessFlags = AccessFlags.FINAL.value,
|
||||
parameters = listOf("L", "L", "L", "Z"),
|
||||
opcodes = listOf(
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.IF_LEZ,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
),
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass == "Landroid/support/v7/widget/LinearLayoutManager;"
|
||||
}
|
||||
)
|
@ -304,6 +304,13 @@ Note: Enabling this also hide Notify me button."</string>
|
||||
Limitations:
|
||||
• Shorts cannot be hidden.
|
||||
• Videos with 0 views are not filtered."</string>
|
||||
<string name="revanced_hide_related_videos_title">Hide related videos</string>
|
||||
<string name="revanced_hide_related_videos_summary_on">Related videos are hidden.</string>
|
||||
<string name="revanced_hide_related_videos_summary_off">Related videos are shown.</string>
|
||||
<string name="revanced_hide_related_videos_user_dialog_message">"This setting limits the maximum number of layouts that can be loaded on the player screen.
|
||||
|
||||
If the layout of the player screen changes due to server-side changes, unintended layouts may be hidden on the player screen."</string>
|
||||
|
||||
|
||||
<!-- PreferenceScreen: General -->
|
||||
<string name="revanced_preference_screen_general_title">General</string>
|
||||
|
@ -95,6 +95,9 @@
|
||||
<app.revanced.integrations.shared.settings.preference.ResettableEditTextPreference android:title="@string/revanced_hide_video_view_counts_multiplier_title" android:key="revanced_hide_video_view_counts_multiplier" android:summary="@string/revanced_hide_video_view_counts_multiplier_summary" android:inputType="textMultiLine" />
|
||||
<Preference android:title="@string/revanced_hide_video_by_view_counts_about_title" android:selectable="false" android:summary="@string/revanced_hide_video_by_view_counts_about_summary" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category">
|
||||
<SwitchPreference android:title="@string/revanced_hide_related_videos_title" android:key="revanced_hide_related_videos" android:summaryOn="@string/revanced_hide_related_videos_summary_on" android:summaryOff="@string/revanced_hide_related_videos_summary_off" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
<SwitchPreference android:title="@string/revanced_hide_album_card_title" android:key="revanced_hide_album_card" android:summaryOn="@string/revanced_hide_album_card_summary_on" android:summaryOff="@string/revanced_hide_album_card_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_carousel_shelf_title" android:key="revanced_hide_carousel_shelf" android:summary="@string/revanced_hide_carousel_shelf_summary" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user