From 4dce73a6fbfeeffb8c2b1759b9c5a5eacb1e3d4b Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:02:48 +0400 Subject: [PATCH] feat(YouTube): Support version `19.12`, `19.13`, `19.14`, `19.15` and `19.16` (#643) --- .../patches/HideAutoplayButtonPatch.java | 10 +++- .../components/LayoutComponentsFilter.java | 51 ++++++++++--------- .../RestoreOldVideoQualityMenuPatch.java | 4 +- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java index 79a40d64e4..846905c238 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/HideAutoplayButtonPatch.java @@ -4,7 +4,13 @@ @SuppressWarnings("unused") public class HideAutoplayButtonPatch { - public static boolean isButtonShown() { - return !Settings.HIDE_AUTOPLAY_BUTTON.get(); + + private static final Boolean HIDE_AUTOPLAY_BUTTON_ENABLED = Settings.HIDE_AUTOPLAY_BUTTON.get(); + + /** + * Injection point. + */ + public static boolean hideAutoPlayButton() { + return HIDE_AUTOPLAY_BUTTON_ENABLED; } } diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java index 0e79950448..522658c524 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java @@ -21,17 +21,20 @@ public final class LayoutComponentsFilter extends Filter { private static final String VIDEO_ACTION_BAR_PATH_PREFIX = "video_action_bar.eml"; private static final String ANIMATED_VECTOR_TYPE_PATH = "AnimatedVectorType"; - private final StringTrieSearch exceptions = new StringTrieSearch(); - private static final StringTrieSearch mixPlaylistsExceptions = new StringTrieSearch(); + private static final StringTrieSearch mixPlaylistsExceptions = new StringTrieSearch( + "V.ED", // Playlist browse id. + "java.lang.ref.WeakReference" + ); private static final ByteArrayFilterGroup mixPlaylistsExceptions2 = new ByteArrayFilterGroup( null, "cell_description_body" ); - private static final ByteArrayFilterGroup mixPlaylists = new ByteArrayFilterGroup( Settings.HIDE_MIX_PLAYLISTS, "&list=" ); + + private final StringTrieSearch exceptions = new StringTrieSearch(); private final StringFilterGroup searchResultShelfHeader; private final StringFilterGroup inFeedSurvey; private final StringFilterGroup notifyMe; @@ -44,13 +47,6 @@ public final class LayoutComponentsFilter extends Filter { private final StringFilterGroup likeSubscribeGlow; private final StringFilterGroup horizontalShelves; - static { - mixPlaylistsExceptions.addPatterns( - "V.ED", // Playlist browse id. - "java.lang.ref.WeakReference" - ); - } - @RequiresApi(api = Build.VERSION_CODES.N) public LayoutComponentsFilter() { exceptions.addPatterns( @@ -353,24 +349,31 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff * Called from a different place then the other filters. */ public static boolean filterMixPlaylists(final Object conversionContext, @Nullable final byte[] bytes) { - if (bytes == null) { - Logger.printDebug(() -> "bytes is null"); - return false; - } + try { + if (bytes == null) { + Logger.printDebug(() -> "bytes is null"); + return false; + } - // Prevent playlist items being hidden, if a mix playlist is present in it. - if (mixPlaylistsExceptions.matches(conversionContext.toString())) - return false; + // Prevent playlist items being hidden, if a mix playlist is present in it. + if (mixPlaylistsExceptions.matches(conversionContext.toString())) { + return false; + } - if (!mixPlaylists.check(bytes).isFiltered()) - return false; + // Prevent hiding the description of some videos accidentally. + if (mixPlaylistsExceptions2.check(bytes).isFiltered()) { + return false; + } - // Prevent hiding the description of some videos accidentally. - if (mixPlaylistsExceptions2.check(bytes).isFiltered()) - return false; + if (mixPlaylists.check(bytes).isFiltered()) { + Logger.printDebug(() -> "Filtered mix playlist"); + return true; + } + } catch (Exception ex) { + Logger.printException(() -> "filterMixPlaylists failure", ex); + } - Logger.printDebug(() -> "Filtered mix playlist"); - return true; + return false; } /** diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/playback/quality/RestoreOldVideoQualityMenuPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/playback/quality/RestoreOldVideoQualityMenuPatch.java index 1cc6537156..42faeecf34 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/playback/quality/RestoreOldVideoQualityMenuPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/playback/quality/RestoreOldVideoQualityMenuPatch.java @@ -70,8 +70,8 @@ public static void onFlyoutMenuCreate(RecyclerView recyclerView) { * * Used to force the creation of the advanced menu item for the Shorts quality flyout. */ - public static boolean forceAdvancedVideoQualityMenuCreation() { - return Settings.RESTORE_OLD_VIDEO_QUALITY_MENU.get(); + public static boolean forceAdvancedVideoQualityMenuCreation(boolean original) { + return Settings.RESTORE_OLD_VIDEO_QUALITY_MENU.get() || original; } /**