|
1 | 1 | package app.revanced.integrations.patches; |
2 | 2 |
|
3 | | -import app.revanced.integrations.settings.SettingsEnum; |
4 | | -import app.revanced.integrations.utils.LogHelper; |
5 | | - |
6 | | -import java.nio.ByteBuffer; |
7 | | -import java.nio.charset.StandardCharsets; |
8 | 3 | import java.util.ArrayList; |
9 | 4 | import java.util.List; |
10 | 5 |
|
| 6 | +import app.revanced.integrations.settings.SettingsEnum; |
| 7 | +import app.revanced.integrations.utils.LogHelper; |
| 8 | + |
11 | 9 | public class GeneralBytecodeAdsPatch { |
12 | 10 |
|
13 | 11 | //Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch |
14 | | - public static boolean containsAd(String value, ByteBuffer buffer) { |
15 | | - return containsLithoAd(value, buffer); |
16 | | - } |
| 12 | + public static boolean isAdComponent(StringBuilder pathBuilder) { |
| 13 | + var path = pathBuilder.toString(); |
| 14 | + if (path.isEmpty()) return false; |
| 15 | + |
| 16 | + LogHelper.debug(GeneralBytecodeAdsPatch.class, "Searching for an ad in: " + path); |
| 17 | + |
| 18 | + List<String> blockList = new ArrayList<>(); |
| 19 | + |
| 20 | + if (SettingsEnum.ADREMOVER_AD_REMOVAL.getBoolean()) { |
| 21 | + blockList.add("video_display_full_buttoned_layout"); |
| 22 | + blockList.add("ad_"); |
| 23 | + blockList.add("ads_video_with_context"); |
| 24 | + blockList.add("cell_divider"); |
| 25 | + blockList.add("reels_player_overlay"); |
| 26 | + blockList.add("shelf_header"); |
| 27 | + blockList.add("watch_metadata_app_promo"); |
| 28 | + blockList.add("video_display_full_layout"); |
| 29 | + } |
| 30 | + |
| 31 | + if (SettingsEnum.ADREMOVER_MOVIE_REMOVAL.getBoolean()) { |
| 32 | + blockList.add("browsy_bar"); |
| 33 | + blockList.add("compact_movie"); |
| 34 | + blockList.add("horizontal_movie_shelf"); |
| 35 | + blockList.add("movie_and_show_upsell_card"); |
| 36 | + } |
17 | 37 |
|
18 | | - private static boolean containsLithoAd(String value, ByteBuffer buffer) { |
19 | | - boolean enabled = false; |
20 | | - for (SettingsEnum setting : SettingsEnum.getAdRemovalSettings()) { |
21 | | - if (setting.getBoolean()) { |
22 | | - enabled = true; |
23 | | - break; |
24 | | - } |
25 | | - } |
26 | | - |
27 | | - try { |
28 | | - if (value == null || value.isEmpty() || !enabled) return false; |
29 | | - LogHelper.debug(GeneralBytecodeAdsPatch.class, "Searching for AD: " + value); |
30 | | - |
31 | | - List<String> blockList = new ArrayList<>(); |
32 | | - List<String> bufferBlockList = new ArrayList<>(); |
33 | | - |
34 | | - if (SettingsEnum.ADREMOVER_AD_REMOVAL.getBoolean()) { |
35 | | - blockList.add("_ad"); |
36 | | - blockList.add("ad_badge"); |
37 | | - blockList.add("ads_video_with_context"); |
38 | | - blockList.add("cell_divider"); |
39 | | - blockList.add("reels_player_overlay"); |
40 | | - blockList.add("shelf_header"); |
41 | | - blockList.add("text_display_ad_with_themed_cta_banner_image"); |
42 | | - blockList.add("text_search_ad_with_description_first"); |
43 | | - blockList.add("watch_metadata_app_promo"); |
44 | | - blockList.add("video_display_full_layout"); |
45 | | - |
46 | | - bufferBlockList.add("ad_cpn"); |
47 | | - } |
48 | | - if (SettingsEnum.ADREMOVER_SUGGESTED_FOR_YOU_REMOVAL.getBoolean()) { |
49 | | - bufferBlockList.add("watch-vrecH"); |
50 | | - } |
51 | | - if (SettingsEnum.ADREMOVER_MOVIE_REMOVAL.getBoolean()) { |
52 | | - blockList.add("browsy_bar"); |
53 | | - blockList.add("compact_movie"); |
54 | | - blockList.add("horizontal_movie_shelf"); |
55 | | - blockList.add("movie_and_show_upsell_card"); |
56 | | - |
57 | | - bufferBlockList.add("YouTube Movies"); |
58 | | - } |
59 | | - if (containsAny(value, "home_video_with_context", "related_video_with_context") && |
60 | | - anyMatch(bufferBlockList, new String(buffer.array(), StandardCharsets.UTF_8)::contains) |
61 | | - ) return true; |
62 | | - |
63 | | - if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) { |
64 | | - blockList.add("comments_"); |
65 | | - } |
66 | | - if (SettingsEnum.ADREMOVER_COMMUNITY_GUIDELINES.getBoolean()) { |
67 | | - blockList.add("community_guidelines"); |
68 | | - } |
69 | | - if (SettingsEnum.ADREMOVER_COMPACT_BANNER_REMOVAL.getBoolean()) { |
70 | | - blockList.add("compact_banner"); |
71 | | - } |
72 | | - if (SettingsEnum.ADREMOVER_EMERGENCY_BOX_REMOVAL.getBoolean()) { |
73 | | - blockList.add("emergency_onebox"); |
74 | | - } |
75 | | - if (SettingsEnum.ADREMOVER_FEED_SURVEY_REMOVAL.getBoolean()) { |
76 | | - blockList.add("in_feed_survey"); |
77 | | - } |
78 | | - if (SettingsEnum.ADREMOVER_MEDICAL_PANEL_REMOVAL.getBoolean()) { |
79 | | - blockList.add("medical_panel"); |
80 | | - } |
81 | | - if (SettingsEnum.ADREMOVER_PAID_CONTECT_REMOVAL.getBoolean()) { |
82 | | - blockList.add("paid_content_overlay"); |
83 | | - } |
84 | | - if (SettingsEnum.ADREMOVER_COMMUNITY_POSTS_REMOVAL.getBoolean()) { |
85 | | - blockList.add("post_base_wrapper"); |
86 | | - } |
87 | | - if (SettingsEnum.ADREMOVER_MERCHANDISE_REMOVAL.getBoolean()) { |
88 | | - blockList.add("product_carousel"); |
89 | | - } |
90 | | - if (SettingsEnum.ADREMOVER_SHORTS_SHELF.getBoolean()) { |
91 | | - blockList.add("shorts_shelf"); |
92 | | - } |
93 | | - if (SettingsEnum.ADREMOVER_INFO_PANEL_REMOVAL.getBoolean()) { |
94 | | - blockList.add("publisher_transparency_panel"); |
95 | | - blockList.add("single_item_information_panel"); |
96 | | - } |
97 | | - if (SettingsEnum.ADREMOVER_HIDE_SUGGESTIONS.getBoolean()) { |
98 | | - blockList.add("horizontal_video_shelf"); |
99 | | - } |
100 | | - if (SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS.getBoolean()) { |
101 | | - blockList.add("post_shelf"); |
102 | | - } |
103 | | - if (SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES.getBoolean()) { |
104 | | - blockList.add("channel_guidelines_entry_banner"); |
105 | | - } |
106 | | - |
107 | | - if (containsAny(value, |
108 | | - "home_video_with_context", |
109 | | - "related_video_with_context", |
110 | | - "search_video_with_context", |
111 | | - "menu", |
112 | | - "root", |
113 | | - "-count", |
114 | | - "-space", |
115 | | - "-button" |
116 | | - )) return false; |
117 | | - |
118 | | - if (anyMatch(blockList, value::contains)) { |
119 | | - LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value); |
120 | | - return true; |
121 | | - } |
122 | | - |
123 | | - if (SettingsEnum.DEBUG.getBoolean()) { |
124 | | - if (value.contains("related_video_with_context")) { |
125 | | - LogHelper.debug(GeneralBytecodeAdsPatch.class, value + " | " + bytesToHex(buffer.array())); |
126 | | - return false; |
127 | | - } |
128 | | - LogHelper.debug(GeneralBytecodeAdsPatch.class, value + " returns false."); |
129 | | - } |
130 | | - return false; |
131 | | - } catch (Exception ex) { |
132 | | - LogHelper.printException(GeneralBytecodeAdsPatch.class, ex.getMessage(), ex); |
133 | | - return false; |
| 38 | + if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) { |
| 39 | + blockList.add("comments_"); |
| 40 | + } |
| 41 | + if (SettingsEnum.ADREMOVER_COMMUNITY_GUIDELINES.getBoolean()) { |
| 42 | + blockList.add("community_guidelines"); |
| 43 | + } |
| 44 | + if (SettingsEnum.ADREMOVER_COMPACT_BANNER_REMOVAL.getBoolean()) { |
| 45 | + blockList.add("compact_banner"); |
| 46 | + } |
| 47 | + if (SettingsEnum.ADREMOVER_EMERGENCY_BOX_REMOVAL.getBoolean()) { |
| 48 | + blockList.add("emergency_onebox"); |
| 49 | + } |
| 50 | + if (SettingsEnum.ADREMOVER_FEED_SURVEY_REMOVAL.getBoolean()) { |
| 51 | + blockList.add("in_feed_survey"); |
134 | 52 | } |
| 53 | + if (SettingsEnum.ADREMOVER_MEDICAL_PANEL_REMOVAL.getBoolean()) { |
| 54 | + blockList.add("medical_panel"); |
| 55 | + } |
| 56 | + if (SettingsEnum.ADREMOVER_PAID_CONTECT_REMOVAL.getBoolean()) { |
| 57 | + blockList.add("paid_content_overlay"); |
| 58 | + } |
| 59 | + if (SettingsEnum.ADREMOVER_COMMUNITY_POSTS_REMOVAL.getBoolean()) { |
| 60 | + blockList.add("post_base_wrapper"); |
| 61 | + } |
| 62 | + if (SettingsEnum.ADREMOVER_MERCHANDISE_REMOVAL.getBoolean()) { |
| 63 | + blockList.add("product_carousel"); |
| 64 | + } |
| 65 | + if (SettingsEnum.ADREMOVER_SHORTS_SHELF.getBoolean()) { |
| 66 | + blockList.add("shorts_shelf"); |
| 67 | + } |
| 68 | + if (SettingsEnum.ADREMOVER_INFO_PANEL_REMOVAL.getBoolean()) { |
| 69 | + blockList.add("publisher_transparency_panel"); |
| 70 | + blockList.add("single_item_information_panel"); |
| 71 | + } |
| 72 | + if (SettingsEnum.ADREMOVER_HIDE_SUGGESTIONS.getBoolean()) { |
| 73 | + blockList.add("horizontal_video_shelf"); |
| 74 | + } |
| 75 | + if (SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS.getBoolean()) { |
| 76 | + blockList.add("post_shelf"); |
| 77 | + } |
| 78 | + if (SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES.getBoolean()) { |
| 79 | + blockList.add("channel_guidelines_entry_banner"); |
| 80 | + } |
| 81 | + |
| 82 | + if (containsAny(path, |
| 83 | + "home_video_with_context", |
| 84 | + "related_video_with_context", |
| 85 | + "search_video_with_context", |
| 86 | + "menu", |
| 87 | + "root", |
| 88 | + "-count", |
| 89 | + "-space", |
| 90 | + "-button" |
| 91 | + )) return false; |
| 92 | + |
| 93 | + if (anyMatch(blockList, path::contains)) { |
| 94 | + LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + path); |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + return false; |
135 | 99 | } |
136 | 100 |
|
137 | 101 | private static boolean containsAny(String value, String... targets) { |
|
0 commit comments