Skip to content

Commit

Permalink
fix(YouTube - Hide layout components): Reduce false positives when hi…
Browse files Browse the repository at this point in the history
…ding mix playlists

Implementation references taken from github.com/inotia00/revanced-integrations/commit/cfaf3d6356f316623ad32b10719b1b5ef0ba25b9
  • Loading branch information
oSumAtrIX committed Nov 12, 2023
1 parent b1ce7a7 commit 5f30100
Showing 1 changed file with 24 additions and 7 deletions.
Expand Up @@ -2,17 +2,18 @@


import android.os.Build;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.StringTrieSearch;

@RequiresApi(api = Build.VERSION_CODES.N)
public final class LayoutComponentsFilter extends Filter {
private final StringTrieSearch exceptions = new StringTrieSearch();
private static final StringTrieSearch mixPlaylistsExceptions = new StringTrieSearch();
private static ByteArrayAsStringFilterGroup mixPlaylistsExceptions2;

private final CustomFilterGroup custom;

private static final ByteArrayAsStringFilterGroup mixPlaylists = new ByteArrayAsStringFilterGroup(
Expand All @@ -34,6 +35,16 @@ public LayoutComponentsFilter() {
"library_recent_shelf"
);

mixPlaylistsExceptions.addPatterns(
"V.ED", // Playlist browse id.
"java.lang.ref.WeakReference"
);

mixPlaylistsExceptions2 = new ByteArrayAsStringFilterGroup(
null,
"cell_description_body"
);

custom = new CustomFilterGroup(
SettingsEnum.CUSTOM_FILTER,
SettingsEnum.CUSTOM_FILTER_STRINGS
Expand Down Expand Up @@ -243,13 +254,19 @@ public boolean isFiltered(@Nullable String identifier, String path, byte[] proto
* Injection point.
* Called from a different place then the other filters.
*/
public static boolean filterMixPlaylists(final byte[] bytes) {
final boolean isMixPlaylistFiltered = mixPlaylists.check(bytes).isFiltered();
public static boolean filterMixPlaylists(final Object conversionContext, final byte[] bytes) {
// 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;

if (isMixPlaylistFiltered)
LogHelper.printDebug(() -> "Filtered mix playlist");
LogHelper.printDebug(() -> "Filtered mix playlist");
return true;

return isMixPlaylistFiltered;
}

public static boolean showWatermark() {
Expand Down

0 comments on commit 5f30100

Please sign in to comment.