From ee4f543017430d04d2fb7fc3a297035543695d6c Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:20:40 +0900 Subject: [PATCH] feat(YouTube/Player components): add `Sanitize video subtitle` setting --- .../spans/SanitizeVideoSubtitleFilter.java | 36 +++++++++++++++++++ .../youtube/settings/Settings.java | 1 + 2 files changed, 37 insertions(+) create mode 100644 app/src/main/java/app/revanced/integrations/youtube/patches/spans/SanitizeVideoSubtitleFilter.java diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spans/SanitizeVideoSubtitleFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spans/SanitizeVideoSubtitleFilter.java new file mode 100644 index 0000000000..ea885e99e3 --- /dev/null +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spans/SanitizeVideoSubtitleFilter.java @@ -0,0 +1,36 @@ +package app.revanced.integrations.youtube.patches.spans; + +import android.text.SpannableString; + +import app.revanced.integrations.shared.patches.spans.Filter; +import app.revanced.integrations.shared.patches.spans.SpanType; +import app.revanced.integrations.shared.patches.spans.StringFilterGroup; +import app.revanced.integrations.youtube.settings.Settings; + +@SuppressWarnings({"unused", "ConstantValue", "FieldCanBeLocal"}) +public final class SanitizeVideoSubtitleFilter extends Filter { + + public SanitizeVideoSubtitleFilter() { + addCallbacks( + new StringFilterGroup( + Settings.SANITIZE_VIDEO_SUBTITLE, + "|video_subtitle.eml|" + ) + ); + } + + @Override + public boolean skip(String conversionContext, SpannableString spannableString, Object span, + int start, int end, int flags, boolean isWord, SpanType spanType, StringFilterGroup matchedGroup) { + if (isWord) { + if (spanType == SpanType.IMAGE) { + hideImageSpan(spannableString, start, end, flags); + return super.skip(conversionContext, spannableString, span, start, end, flags, isWord, spanType, matchedGroup); + } else if (spanType == SpanType.CUSTOM_CHARACTER_STYLE) { + hideSpan(spannableString, start, end, flags); + return super.skip(conversionContext, spannableString, span, start, end, flags, isWord, spanType, matchedGroup); + } + } + return false; + } +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index 13821905ae..134c32bb40 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -260,6 +260,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_hide_suggested_video_end_screen", TRUE, true); public static final BooleanSetting SKIP_AUTOPLAY_COUNTDOWN = new BooleanSetting("revanced_skip_autoplay_countdown", FALSE, true, parent(HIDE_SUGGESTED_VIDEO_END_SCREEN)); public static final BooleanSetting HIDE_ZOOM_OVERLAY = new BooleanSetting("revanced_hide_zoom_overlay", FALSE, true); + public static final BooleanSetting SANITIZE_VIDEO_SUBTITLE = new BooleanSetting("revanced_sanitize_video_subtitle", FALSE); // PreferenceScreen: Player - Action buttons