From fc832e2459a7c6ad96365a1e4485ed12205bec6e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:39:22 +0900 Subject: [PATCH] feat(YouTube/Player components): add `Disable switch mix playlists` setting --- .../player/components/PlayerComponentsPatch.kt | 8 ++++++++ .../video/information/VideoInformationPatch.kt | 2 +- .../playerresponse/PlayerResponseMethodHookPatch.kt | 11 ++++++++--- .../youtube/settings/host/values/strings.xml | 7 +++++++ .../resources/youtube/settings/xml/revanced_prefs.xml | 1 + 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt index 8b3bca28e..c5ecd85d5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt @@ -46,6 +46,7 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Scrim import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SeekUndoEduOverlayStub import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TapBloomView import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.getTargetIndexOrThrow import app.revanced.util.getTargetIndexReversedOrThrow @@ -73,6 +74,7 @@ object PlayerComponentsPatch : BaseBytecodePatch( SharedResourceIdPatch::class, SpeedOverlayPatch::class, SuggestedVideoEndScreenPatch::class, + VideoInformationPatch::class ), compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( @@ -172,6 +174,12 @@ object PlayerComponentsPatch : BaseBytecodePatch( // endregion + // region patch for disable auto switch mix playlists + + VideoInformationPatch.hook("$PLAYER_CLASS_DESCRIPTOR->disableAutoSwitchMixPlaylists(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JZ)V") + + // endregion + // region patch for hide channel watermark WatermarkFingerprint.resolve( diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index df1eaa5c1..95dee191b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -361,7 +361,7 @@ object VideoInformationPatch : BytecodePatch( // Call before any other video id hooks, // so they can use VideoInformation and check if the video id is for a Short. PlayerResponseMethodHookPatch += PlayerResponseMethodHookPatch.Hook.PlayerParameterBeforeVideoId( - "$INTEGRATIONS_CLASS_DESCRIPTOR->newPlayerResponseParameter(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;" + "$INTEGRATIONS_CLASS_DESCRIPTOR->newPlayerResponseParameter(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;" ) /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt index f003075cc..68beae36b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt @@ -18,12 +18,14 @@ object PlayerResponseMethodHookPatch : // Parameter numbers of the patched method. private var PARAMETER_VIDEO_ID = 1 private var PARAMETER_PLAYER_PARAMETER = 3 + private var PARAMETER_PLAYLIST_ID = 4 private var PARAMETER_IS_SHORT_AND_OPENING_OR_PLAYING by Delegates.notNull() // Registers used to pass the parameters to integrations. private var playerResponseMethodCopyRegisters = false private lateinit var REGISTER_VIDEO_ID: String private lateinit var REGISTER_PLAYER_PARAMETER: String + private lateinit var REGISTER_PLAYLIST_ID: String private lateinit var REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING: String private lateinit var playerResponseMethod: MutableMethod @@ -46,10 +48,12 @@ object PlayerResponseMethodHookPatch : if (playerResponseMethodCopyRegisters) { REGISTER_VIDEO_ID = "v0" REGISTER_PLAYER_PARAMETER = "v1" - REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING = "v2" + REGISTER_PLAYLIST_ID = "v2" + REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING = "v3" } else { REGISTER_VIDEO_ID = "p$PARAMETER_VIDEO_ID" REGISTER_PLAYER_PARAMETER = "p$PARAMETER_PLAYER_PARAMETER" + REGISTER_PLAYLIST_ID = "p$PARAMETER_PLAYLIST_ID" REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING = "p$PARAMETER_IS_SHORT_AND_OPENING_OR_PLAYING" } } @@ -66,7 +70,7 @@ object PlayerResponseMethodHookPatch : fun hookPlayerParameter(hook: Hook) { playerResponseMethod.addInstructions( 0, """ - invoke-static {$REGISTER_VIDEO_ID, $REGISTER_PLAYER_PARAMETER, $REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING}, $hook + invoke-static {$REGISTER_VIDEO_ID, $REGISTER_PLAYER_PARAMETER, $REGISTER_PLAYLIST_ID, $REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING}, $hook move-result-object $REGISTER_PLAYER_PARAMETER """ ) @@ -90,11 +94,12 @@ object PlayerResponseMethodHookPatch : """ move-object/from16 $REGISTER_VIDEO_ID, p$PARAMETER_VIDEO_ID move-object/from16 $REGISTER_PLAYER_PARAMETER, p$PARAMETER_PLAYER_PARAMETER + move-object/from16 $REGISTER_PLAYLIST_ID, p$PARAMETER_PLAYLIST_ID move/from16 $REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING, p$PARAMETER_IS_SHORT_AND_OPENING_OR_PLAYING """, ) - numberOfInstructionsAdded += 3 + numberOfInstructionsAdded += 4 // Move the modified register back. addInstruction( diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 0e5036244..a84f2f8c4 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -543,6 +543,13 @@ Tap and hold to open RVX settings." Disable player popup panels Auto player popup panels are disabled. Auto player popup panels are enabled. + Disable switch mix playlists + Auto switch mix playlists is disabled. + "Auto switch mix playlists is enabled when autoplay is turned on. + +Autoplay can be changed in YouTube settings: +Settings → Autoplay → Autoplay next video" + Enabling this feature will disable automatic switching to YouTube Mix when playing music while autoplay is turned on. Disable speed overlay "Disable '2x>>' while holding down. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index e3c21747f..c01b4b4db 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -445,6 +445,7 @@