Skip to content

Commit 5ecbe82

Browse files
fix(YouTube - Disable auto captions): Correctly hide captions with YT 20.12
1 parent 409f98c commit 5ecbe82

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package app.revanced.extension.youtube.patches;
22

33
import app.revanced.extension.youtube.settings.Settings;
4-
import app.revanced.extension.youtube.shared.ShortsPlayerState;
54

65
@SuppressWarnings("unused")
76
public class DisableAutoCaptionsPatch {
87

8+
private static volatile boolean captionsButtonStatus;
9+
910
/**
10-
* Used by injected code. Do not delete.
11+
* Injection point.
1112
*/
12-
public static boolean captionsButtonDisabled;
13-
14-
public static boolean autoCaptionsEnabled() {
15-
return Settings.AUTO_CAPTIONS.get()
16-
// Do not use auto captions for Shorts.
17-
&& ShortsPlayerState.isOpen();
13+
public static boolean disableAutoCaptions() {
14+
return Settings.DISABLE_AUTO_CAPTIONS.get() && !captionsButtonStatus;
1815
}
1916

17+
/**
18+
* Injection point.
19+
*/
20+
public static void setCaptionsButtonStatus(boolean status) {
21+
captionsButtonStatus = status;
22+
}
2023
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public class Settings extends BaseSettings {
124124
// Player
125125
public static final BooleanSetting COPY_VIDEO_URL = new BooleanSetting("revanced_copy_video_url", FALSE);
126126
public static final BooleanSetting COPY_VIDEO_URL_TIMESTAMP = new BooleanSetting("revanced_copy_video_url_timestamp", TRUE);
127+
public static final BooleanSetting DISABLE_AUTO_CAPTIONS = new BooleanSetting("revanced_disable_auto_captions", FALSE, true);
127128
public static final BooleanSetting DISABLE_FULLSCREEN_AMBIENT_MODE = new BooleanSetting("revanced_disable_fullscreen_ambient_mode", TRUE, true);
128129
public static final BooleanSetting DISABLE_ROLLING_NUMBER_ANIMATIONS = new BooleanSetting("revanced_disable_rolling_number_animations", FALSE);
129130
public static final EnumSetting<FullscreenMode> EXIT_FULLSCREEN = new EnumSetting<>("revanced_exit_fullscreen", FullscreenMode.DISABLED);
@@ -294,7 +295,6 @@ public class Settings extends BaseSettings {
294295
// Misc
295296
public static final BooleanSetting ANNOUNCEMENTS = new BooleanSetting("revanced_announcements", TRUE);
296297
public static final IntegerSetting ANNOUNCEMENT_LAST_ID = new IntegerSetting("revanced_announcement_last_id", -1, false, false);
297-
public static final BooleanSetting AUTO_CAPTIONS = new BooleanSetting("revanced_auto_captions", FALSE);
298298
public static final BooleanSetting AUTO_REPEAT = new BooleanSetting("revanced_auto_repeat", FALSE);
299299
public static final BooleanSetting BYPASS_URL_REDIRECTS = new BooleanSetting("revanced_bypass_url_redirects", TRUE);
300300
public static final BooleanSetting CHECK_WATCH_HISTORY_DOMAIN_NAME = new BooleanSetting("revanced_check_watch_history_domain_name", TRUE, false, false);
@@ -403,6 +403,7 @@ public class Settings extends BaseSettings {
403403
private static final StringSetting DEPRECATED_SEEKBAR_CUSTOM_COLOR_PRIMARY = new StringSetting("revanced_seekbar_custom_color_value", "#FF0033");
404404
private static final BooleanSetting DEPRECATED_DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE);
405405
private static final BooleanSetting DEPRECATED_RESTORE_OLD_VIDEO_QUALITY_MENU = new BooleanSetting("revanced_restore_old_video_quality_menu", TRUE);
406+
private static final BooleanSetting DEPRECATED_AUTO_CAPTIONS = new BooleanSetting("revanced_auto_captions", FALSE);
406407

407408
static {
408409
// region Migration
@@ -456,6 +457,11 @@ public class Settings extends BaseSettings {
456457
SPOOF_APP_VERSION_TARGET.resetToDefault();
457458
}
458459

460+
if (!DEPRECATED_AUTO_CAPTIONS.isSetToDefault()) {
461+
DISABLE_AUTO_CAPTIONS.save(true);
462+
DEPRECATED_AUTO_CAPTIONS.resetToDefault();
463+
}
464+
459465
// endregion
460466

461467
// region SB import/export callbacks

patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
88
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
99
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
1010
import app.revanced.patches.youtube.misc.settings.settingsPatch
11-
import app.revanced.patches.youtube.shared.subtitleButtonControllerFingerprint
11+
12+
private const val EXTENSION_CLASS_DESCRIPTOR =
13+
"Lapp/revanced/extension/youtube/patches/DisableAutoCaptionsPatch;"
1214

1315
val autoCaptionsPatch = bytecodePatch(
1416
name = "Disable auto captions",
@@ -36,35 +38,33 @@ val autoCaptionsPatch = bytecodePatch(
3638
addResources("youtube", "layout.autocaptions.autoCaptionsPatch")
3739

3840
PreferenceScreen.PLAYER.addPreferences(
39-
SwitchPreference("revanced_auto_captions"),
41+
SwitchPreference("revanced_disable_auto_captions"),
4042
)
4143

42-
mapOf(
43-
startVideoInformerFingerprint to 0,
44-
subtitleButtonControllerFingerprint to 1,
45-
).forEach { (fingerprint, enabled) ->
46-
fingerprint.method.addInstructions(
47-
0,
48-
"""
49-
const/4 v0, 0x$enabled
50-
sput-boolean v0, Lapp/revanced/extension/youtube/patches/DisableAutoCaptionsPatch;->captionsButtonDisabled:Z
51-
""",
52-
)
53-
}
54-
5544
subtitleTrackFingerprint.method.addInstructions(
5645
0,
5746
"""
58-
invoke-static {}, Lapp/revanced/extension/youtube/patches/DisableAutoCaptionsPatch;->autoCaptionsEnabled()Z
47+
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->disableAutoCaptions()Z
5948
move-result v0
6049
if-eqz v0, :auto_captions_enabled
61-
sget-boolean v0, Lapp/revanced/extension/youtube/patches/DisableAutoCaptionsPatch;->captionsButtonDisabled:Z
62-
if-nez v0, :auto_captions_enabled
6350
const/4 v0, 0x1
6451
return v0
6552
:auto_captions_enabled
6653
nop
67-
""",
54+
"""
6855
)
56+
57+
mapOf(
58+
startVideoInformerFingerprint to 0,
59+
storyboardRendererDecoderRecommendedLevelFingerprint to 1
60+
).forEach { (fingerprint, enabled) ->
61+
fingerprint.method.addInstructions(
62+
0,
63+
"""
64+
const/4 v0, 0x$enabled
65+
invoke-static { v0 }, $EXTENSION_CLASS_DESCRIPTOR->setCaptionsButtonStatus(Z)V
66+
"""
67+
)
68+
}
6969
}
7070
}

patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/Fingerprints.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ internal val startVideoInformerFingerprint = fingerprint {
1414
strings("pc")
1515
}
1616

17+
internal val storyboardRendererDecoderRecommendedLevelFingerprint = fingerprint {
18+
returns("V")
19+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
20+
parameters("L")
21+
strings("#-1#")
22+
}
23+
1724
internal val subtitleTrackFingerprint = fingerprint {
1825
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
1926
returns("Z")
@@ -28,6 +35,6 @@ internal val subtitleTrackFingerprint = fingerprint {
2835
)
2936
strings("DISABLE_CAPTIONS_OPTION")
3037
custom { _, classDef ->
31-
classDef.endsWith("SubtitleTrack;")
38+
classDef.endsWith("/SubtitleTrack;")
3239
}
3340
}

patches/src/main/resources/addresources/values/strings.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ Adjust volume by swiping vertically on the right side of the screen"</string>
540540
<string name="revanced_swipe_change_video_summary_off">Swiping in fullscreen mode will not change to the next/previous video</string>
541541
</patch>
542542
<patch id="layout.autocaptions.autoCaptionsPatch">
543-
<string name="revanced_auto_captions_title">Disable auto captions</string>
544-
<string name="revanced_auto_captions_summary_on">Auto captions are disabled</string>
545-
<string name="revanced_auto_captions_summary_off">Auto captions are enabled</string>
543+
<string name="revanced_disable_auto_captions_title">Disable auto captions</string>
544+
<string name="revanced_disable_auto_captions_summary_on">Auto captions are disabled</string>
545+
<string name="revanced_disable_auto_captions_summary_off">Auto captions are enabled</string>
546546
</patch>
547547
<patch id="layout.buttons.action.hideButtonsPatch">
548548
<string name="revanced_hide_buttons_screen_title">Action buttons</string>

0 commit comments

Comments
 (0)