fix(YouTube - Hide layout components): Reduce false positives when hiding mix playlists

Implementation references taken from github.com/inotia00/revanced-integrations/commit/cfaf3d6356f316623ad32b10719b1b5ef0ba25b9
This commit is contained in:
oSumAtrIX 2023-11-12 16:23:56 +01:00
parent b1ce7a75eb
commit 5f30100fd5
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -2,10 +2,8 @@ package app.revanced.integrations.patches.components;
import android.os.Build; import android.os.Build;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.StringTrieSearch; import app.revanced.integrations.utils.StringTrieSearch;
@ -13,6 +11,9 @@ import app.revanced.integrations.utils.StringTrieSearch;
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
public final class LayoutComponentsFilter extends Filter { public final class LayoutComponentsFilter extends Filter {
private final StringTrieSearch exceptions = new StringTrieSearch(); private final StringTrieSearch exceptions = new StringTrieSearch();
private static final StringTrieSearch mixPlaylistsExceptions = new StringTrieSearch();
private static ByteArrayAsStringFilterGroup mixPlaylistsExceptions2;
private final CustomFilterGroup custom; private final CustomFilterGroup custom;
private static final ByteArrayAsStringFilterGroup mixPlaylists = new ByteArrayAsStringFilterGroup( private static final ByteArrayAsStringFilterGroup mixPlaylists = new ByteArrayAsStringFilterGroup(
@ -34,6 +35,16 @@ public final class LayoutComponentsFilter extends Filter {
"library_recent_shelf" "library_recent_shelf"
); );
mixPlaylistsExceptions.addPatterns(
"V.ED", // Playlist browse id.
"java.lang.ref.WeakReference"
);
mixPlaylistsExceptions2 = new ByteArrayAsStringFilterGroup(
null,
"cell_description_body"
);
custom = new CustomFilterGroup( custom = new CustomFilterGroup(
SettingsEnum.CUSTOM_FILTER, SettingsEnum.CUSTOM_FILTER,
SettingsEnum.CUSTOM_FILTER_STRINGS SettingsEnum.CUSTOM_FILTER_STRINGS
@ -243,13 +254,19 @@ public final class LayoutComponentsFilter extends Filter {
* Injection point. * Injection point.
* Called from a different place then the other filters. * Called from a different place then the other filters.
*/ */
public static boolean filterMixPlaylists(final byte[] bytes) { public static boolean filterMixPlaylists(final Object conversionContext, final byte[] bytes) {
final boolean isMixPlaylistFiltered = mixPlaylists.check(bytes).isFiltered(); // Prevent playlist items being hidden, if a mix playlist is present in it.
if (mixPlaylistsExceptions.matches(conversionContext.toString()))
return false;
if (isMixPlaylistFiltered) if (!mixPlaylists.check(bytes).isFiltered()) return false;
LogHelper.printDebug(() -> "Filtered mix playlist");
// Prevent hiding the description of some videos accidentally.
if (mixPlaylistsExceptions2.check(bytes).isFiltered()) return false;
LogHelper.printDebug(() -> "Filtered mix playlist");
return true;
return isMixPlaylistFiltered;
} }
public static boolean showWatermark() { public static boolean showWatermark() {