Skip to content

Commit f8c2ae8

Browse files
committed
YouTube: Add Disable auto captions
1 parent c2aadc0 commit f8c2ae8

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Hide video action buttons
3939
- Disable resuming Shorts on startup
4040
- Disable video codecs
41+
- Disable auto captions
4142

4243
### Spotify (Moved to Dedicated Repository)
4344

app/src/main/java/io/github/chsbuffer/revancedxposed/youtube/YoutubeHook.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.github.chsbuffer.revancedxposed.youtube.ad.video.VideoAds
1212
import io.github.chsbuffer.revancedxposed.youtube.interaction.copyvideourl.CopyVideoUrl
1313
import io.github.chsbuffer.revancedxposed.youtube.interaction.downloads.Downloads
1414
import io.github.chsbuffer.revancedxposed.youtube.interaction.swipecontrols.SwipeControls
15+
import io.github.chsbuffer.revancedxposed.youtube.layout.autocaptions.AutoCaptionsPatch
1516
import io.github.chsbuffer.revancedxposed.youtube.layout.buttons.action.HideButtons
1617
import io.github.chsbuffer.revancedxposed.youtube.layout.buttons.navigation.NavigationButtons
1718
import io.github.chsbuffer.revancedxposed.youtube.layout.hide.general.HideLayoutComponents
@@ -62,6 +63,7 @@ val YouTubePatches = arrayOf(
6263
EnableDebugging,
6364
ForceOriginalAudio,
6465
DisableVideoCodecs,
66+
AutoCaptionsPatch,
6567
CheckRecycleBitmapMediaSession,
6668
// make sure settingsHook at end to build preferences
6769
SettingsHook
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.github.chsbuffer.revancedxposed.youtube.layout.autocaptions
2+
3+
import app.revanced.extension.youtube.patches.DisableAutoCaptionsPatch
4+
import io.github.chsbuffer.revancedxposed.patch
5+
import io.github.chsbuffer.revancedxposed.shared.misc.settings.preference.SwitchPreference
6+
import io.github.chsbuffer.revancedxposed.youtube.misc.settings.PreferenceScreen
7+
8+
val AutoCaptionsPatch = patch(
9+
name = "Disable auto captions",
10+
description = "Adds an option to disable captions from being automatically enabled.",
11+
) {
12+
PreferenceScreen.PLAYER.addPreferences(
13+
SwitchPreference("revanced_disable_auto_captions"),
14+
)
15+
16+
::subtitleTrackFingerprint.hookMethod {
17+
before {
18+
if (DisableAutoCaptionsPatch.disableAutoCaptions()) {
19+
it.result = true
20+
}
21+
}
22+
}
23+
24+
mapOf(
25+
::startVideoInformerFingerprint to 0,
26+
::storyboardRendererDecoderRecommendedLevelFingerprint to 1
27+
).forEach { (fingerprint, enabled) ->
28+
fingerprint.hookMethod {
29+
before {
30+
DisableAutoCaptionsPatch.setCaptionsButtonStatus(enabled != 0)
31+
}
32+
}
33+
}
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.github.chsbuffer.revancedxposed.youtube.layout.autocaptions
2+
3+
import io.github.chsbuffer.revancedxposed.AccessFlags
4+
import io.github.chsbuffer.revancedxposed.Opcode
5+
import io.github.chsbuffer.revancedxposed.fingerprint
6+
import org.luckypray.dexkit.query.enums.StringMatchType
7+
8+
internal val startVideoInformerFingerprint = fingerprint {
9+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
10+
returns("V")
11+
opcodes(
12+
Opcode.INVOKE_INTERFACE,
13+
Opcode.RETURN_VOID,
14+
)
15+
methodMatcher {
16+
addEqString("pc")
17+
}
18+
}
19+
20+
internal val storyboardRendererDecoderRecommendedLevelFingerprint = fingerprint {
21+
returns("V")
22+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
23+
parameters("L")
24+
strings("#-1#")
25+
}
26+
27+
internal val subtitleTrackFingerprint = fingerprint {
28+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
29+
returns("Z")
30+
parameters()
31+
opcodes(
32+
Opcode.CONST_STRING,
33+
Opcode.INVOKE_VIRTUAL,
34+
Opcode.MOVE_RESULT_OBJECT,
35+
Opcode.INVOKE_VIRTUAL,
36+
Opcode.MOVE_RESULT,
37+
Opcode.RETURN,
38+
)
39+
strings("DISABLE_CAPTIONS_OPTION")
40+
classMatcher { className(".SubtitleTrack", StringMatchType.EndsWith) }
41+
}

0 commit comments

Comments
 (0)