Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 3797438

Browse files
author
OxrxL
authored
fix: disable sponsorblock on shorts (#135)
1 parent 3fd6df8 commit 3797438

7 files changed

Lines changed: 42 additions & 2 deletions

File tree

app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public enum SettingsEnum {
108108
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
109109
SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING);
110110

111+
public static boolean shorts_playing = false;
111112
private final String path;
112113
private final Object defaultValue;
113114
private final SharedPrefHelper.SharedPrefNames sharedPref;
@@ -250,5 +251,4 @@ public ReturnType getReturnType() {
250251
public boolean shouldRebootOnChange() {
251252
return rebootApp;
252253
}
253-
254254
}

app/src/main/java/app/revanced/integrations/sponsorblock/PlayerController.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public void run() {
8787
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play
8888
*/
8989
public static void onCreate(final Object o) {
90-
// "Plugin.printStackTrace();
90+
if (SettingsEnum.shorts_playing) return;
91+
92+
// "Plugin.printStackTrace();
9193

9294
if (o == null) {
9395
LogHelper.printException(PlayerController.class, "onCreate called with null object");
@@ -132,6 +134,8 @@ public static void executeDownloadSegments(String videoId) {
132134
* Called when it's time to update the UI with new second, about once per second, only when playing, also in background
133135
*/
134136
public static void setCurrentVideoTime(long millis) {
137+
if (SettingsEnum.shorts_playing) return;
138+
135139
LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis);
136140
VideoInformation.lastKnownVideoTime = millis;
137141
if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
@@ -216,6 +220,8 @@ private static void sendViewRequestAsync(final long millis, final SponsorSegment
216220
* Called very high frequency (once every about 100ms), also in background. It sometimes triggers when a video is paused (couple times in the row with the same value)
217221
*/
218222
public static void setCurrentVideoTimeHighPrecision(final long millis) {
223+
if (SettingsEnum.shorts_playing) return;
224+
219225
if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) {
220226
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
221227
SponsorBlockUtils.showVoteButton();
@@ -239,12 +245,16 @@ public static long getLastKnownVideoTime() {
239245
* Called before onDraw method on time bar object, sets video length in millis
240246
*/
241247
public static void setVideoLength(final long length) {
248+
if (SettingsEnum.shorts_playing) return;
249+
242250
LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length);
243251
currentVideoLength = length;
244252
}
245253

246254

247255
public static void setSponsorBarAbsoluteLeft(final Rect rect) {
256+
if (SettingsEnum.shorts_playing) return;
257+
248258
setSponsorBarAbsoluteLeft(rect.left);
249259
}
250260

@@ -255,6 +265,8 @@ public static void setSponsorBarAbsoluteLeft(final float left) {
255265
}
256266

257267
public static void setSponsorBarRect(final Object self) {
268+
if (SettingsEnum.shorts_playing) return;
269+
258270
try {
259271
Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect");
260272
field.setAccessible(true);
@@ -269,6 +281,8 @@ public static void setSponsorBarRect(final Object self) {
269281
}
270282

271283
public static void setSponsorBarAbsoluteRight(final Rect rect) {
284+
if (SettingsEnum.shorts_playing) return;
285+
272286
setSponsorBarAbsoluteRight(rect.right);
273287
}
274288

@@ -279,6 +293,8 @@ public static void setSponsorBarAbsoluteRight(final float right) {
279293
}
280294

281295
public static void setSponsorBarThickness(final int thickness) {
296+
if (SettingsEnum.shorts_playing) return;
297+
282298
setSponsorBarThickness((float) thickness);
283299
}
284300

@@ -296,6 +312,8 @@ public static void onSkipSponsorClicked() {
296312

297313

298314
public static void addSkipSponsorView15(final View view) {
315+
if (SettingsEnum.shorts_playing) return;
316+
299317
playerActivity = new WeakReference<>((Activity) view.getContext());
300318
LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString());
301319

@@ -321,6 +339,8 @@ public static void addSkipSponsorView14(final View view) {
321339
* Called when it's time to draw time bar
322340
*/
323341
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
342+
if (SettingsEnum.shorts_playing) return;
343+
324344
if (sponsorBarThickness < 0.1) return;
325345
if (sponsorSegmentsOfCurrentVideo == null) return;
326346

app/src/main/java/app/revanced/integrations/sponsorblock/ShieldButton.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class ShieldButton {
2828
static boolean isShowing;
2929

3030
public static void initialize(Object viewStub) {
31+
if (SettingsEnum.shorts_playing) return;
32+
3133
try {
3234
LogHelper.debug(ShieldButton.class, "initializing shield button");
3335

@@ -62,10 +64,14 @@ public static void changeVisibilityImmediate(boolean visible) {
6264
}
6365

6466
public static void changeVisibilityNegatedImmediate(boolean visible) {
67+
if (SettingsEnum.shorts_playing) return;
68+
6569
changeVisibility(!visible, true);
6670
}
6771

6872
public static void changeVisibility(boolean visible) {
73+
if (SettingsEnum.shorts_playing) return;
74+
6975
changeVisibility(visible, false);
7076
}
7177

app/src/main/java/app/revanced/integrations/sponsorblock/SponsorBlockUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ public static void notifyShareBtnVisibilityChanged(View v) {
403403
}
404404

405405
public static String appendTimeWithoutSegments(String totalTime) {
406+
if (SettingsEnum.shorts_playing) return totalTime;
407+
406408
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
407409
if (timeWithoutSegments.isEmpty()) {
408410
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);

app/src/main/java/app/revanced/integrations/sponsorblock/VotingButton.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class VotingButton {
2727
static boolean isShowing;
2828

2929
public static void initialize(Object viewStub) {
30+
if (SettingsEnum.shorts_playing) return;
31+
3032
try {
3133
LogHelper.debug(VotingButton.class, "initializing voting button");
3234
_youtubeControlsLayout = (RelativeLayout) viewStub;
@@ -60,10 +62,14 @@ public static void changeVisibilityImmediate(boolean visible) {
6062
}
6163

6264
public static void changeVisibilityNegatedImmediate(boolean visible) {
65+
if (SettingsEnum.shorts_playing) return;
66+
6367
changeVisibility(!visible, true);
6468
}
6569

6670
public static void changeVisibility(boolean visible) {
71+
if (SettingsEnum.shorts_playing) return;
72+
6773
changeVisibility(visible, false);
6874
}
6975

app/src/main/java/app/revanced/integrations/sponsorblock/player/ui/SponsorBlockView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.lang.ref.WeakReference;
1010

11+
import app.revanced.integrations.settings.SettingsEnum;
1112
import app.revanced.integrations.sponsorblock.player.PlayerType;
1213
import app.revanced.integrations.utils.LogHelper;
1314
import app.revanced.integrations.utils.ReVancedUtils;
@@ -22,6 +23,8 @@ public class SponsorBlockView {
2223
static boolean shouldShowOnPlayerType = true;
2324

2425
public static void initialize(Object viewGroup) {
26+
if (SettingsEnum.shorts_playing) return;
27+
2528
try {
2629
LogHelper.debug(SponsorBlockView.class, "initializing");
2730

app/src/main/java/app/revanced/integrations/videoplayer/VideoInformation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package app.revanced.integrations.videoplayer;
22

3+
import app.revanced.integrations.settings.SettingsEnum;
34
import app.revanced.integrations.utils.LogHelper;
45

56
public class VideoInformation {
@@ -14,6 +15,8 @@ public class VideoInformation {
1415

1516
// Call hook in the YT code when the video changes
1617
public static void setCurrentVideoId(final String videoId) {
18+
if (SettingsEnum.shorts_playing) return;
19+
1720
if (videoId == null) {
1821
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
1922
clearInformation(true);

0 commit comments

Comments
 (0)