mirror of
https://github.com/revanced/revanced-patches
synced 2025-02-22 03:51:20 +01:00
feat(youtube/hide-ads): hide mix playlists
This commit is contained in:
parent
b8c5e7833c
commit
ca48e8dd58
@ -1,7 +1,9 @@
|
|||||||
package app.revanced.integrations.patches.components;
|
package app.revanced.integrations.patches.components;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
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.ReVancedUtils;
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
@ -12,6 +14,13 @@ public final class AdsFilter extends Filter {
|
|||||||
|
|
||||||
private final CustomFilterGroup custom;
|
private final CustomFilterGroup custom;
|
||||||
|
|
||||||
|
// region Mix playlists
|
||||||
|
private final ByteArrayAsStringFilterGroup mixPlaylists;
|
||||||
|
private final ByteArrayAsStringFilterGroup imageHosting;
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
public AdsFilter() {
|
public AdsFilter() {
|
||||||
exceptions = new String[]{
|
exceptions = new String[]{
|
||||||
"home_video_with_context",
|
"home_video_with_context",
|
||||||
@ -183,6 +192,21 @@ public final class AdsFilter extends Filter {
|
|||||||
"offer_module_root"
|
"offer_module_root"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// region Mix playlists
|
||||||
|
|
||||||
|
mixPlaylists = new ByteArrayAsStringFilterGroup(
|
||||||
|
SettingsEnum.HIDE_MIX_PLAYLISTS,
|
||||||
|
"&list=",
|
||||||
|
"YouTube Music"
|
||||||
|
);
|
||||||
|
|
||||||
|
imageHosting = new ByteArrayAsStringFilterGroup(
|
||||||
|
SettingsEnum.HIDE_MIX_PLAYLISTS, // Unused
|
||||||
|
"ggpht.com"
|
||||||
|
);
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
this.pathFilterGroups.addAll(
|
this.pathFilterGroups.addAll(
|
||||||
generalAds,
|
generalAds,
|
||||||
buttonedAd,
|
buttonedAd,
|
||||||
@ -222,6 +246,18 @@ public final class AdsFilter extends Filter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isMixPlaylistFiltered(final byte[] _protobufBufferArray) {
|
||||||
|
if (!mixPlaylists.isEnabled()) return false;
|
||||||
|
|
||||||
|
// Two checks are required to prevent false positives.
|
||||||
|
|
||||||
|
// First check if the current buffer potentially contains a mix playlist.
|
||||||
|
if (!mixPlaylists.check(_protobufBufferArray).isFiltered()) return false;
|
||||||
|
|
||||||
|
// Ensure that the buffer actually contains a mix playlist.
|
||||||
|
return imageHosting.check(_protobufBufferArray).isFiltered();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) {
|
public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) {
|
||||||
FilterResult result;
|
FilterResult result;
|
||||||
@ -230,10 +266,14 @@ public final class AdsFilter extends Filter {
|
|||||||
result = FilterResult.CUSTOM;
|
result = FilterResult.CUSTOM;
|
||||||
else if (ReVancedUtils.containsAny(path, exceptions))
|
else if (ReVancedUtils.containsAny(path, exceptions))
|
||||||
result = FilterResult.EXCEPTION;
|
result = FilterResult.EXCEPTION;
|
||||||
else if (pathFilterGroups.contains(path) || identifierFilterGroups.contains(identifier))
|
else {
|
||||||
result = FilterResult.FILTERED;
|
var filtered =
|
||||||
else
|
pathFilterGroups.contains(path) || // Check if the path is filtered.
|
||||||
result = FilterResult.UNFILTERED;
|
identifierFilterGroups.contains(identifier) || // Check if the identifier is filtered.
|
||||||
|
isMixPlaylistFiltered(_protobufBufferArray); // Check if the buffer contains a mix playlist.
|
||||||
|
|
||||||
|
result = filtered ? FilterResult.FILTERED : FilterResult.UNFILTERED;
|
||||||
|
}
|
||||||
|
|
||||||
LogHelper.printDebug(() -> String.format("%s (ID: %s): %s", result.message, identifier, path));
|
LogHelper.printDebug(() -> String.format("%s (ID: %s): %s", result.message, identifier, path));
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ public enum SettingsEnum {
|
|||||||
HIDE_WEB_SEARCH_RESULTS("revanced_hide_web_search_results", BOOLEAN, TRUE),
|
HIDE_WEB_SEARCH_RESULTS("revanced_hide_web_search_results", BOOLEAN, TRUE),
|
||||||
HIDE_QUICK_ACTIONS("revanced_hide_quick_actions", BOOLEAN, FALSE),
|
HIDE_QUICK_ACTIONS("revanced_hide_quick_actions", BOOLEAN, FALSE),
|
||||||
HIDE_RELATED_VIDEOS("revanced_hide_related_videos", BOOLEAN, FALSE),
|
HIDE_RELATED_VIDEOS("revanced_hide_related_videos", BOOLEAN, FALSE),
|
||||||
|
HIDE_MIX_PLAYLISTS("revanced_hide_mix_playlists", BOOLEAN, TRUE),
|
||||||
|
|
||||||
// Action buttons
|
// Action buttons
|
||||||
HIDE_LIKE_DISLIKE_BUTTON("revanced_hide_like_dislike_button", BOOLEAN, FALSE),
|
HIDE_LIKE_DISLIKE_BUTTON("revanced_hide_like_dislike_button", BOOLEAN, FALSE),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user