Skip to content

Commit

Permalink
fix: disable sponsorblock on shorts (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
OxrxL committed Sep 21, 2022
1 parent 3fd6df8 commit 3797438
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public enum SettingsEnum {
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING);

public static boolean shorts_playing = false;
private final String path;
private final Object defaultValue;
private final SharedPrefHelper.SharedPrefNames sharedPref;
Expand Down Expand Up @@ -250,5 +251,4 @@ public ReturnType getReturnType() {
public boolean shouldRebootOnChange() {
return rebootApp;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public void run() {
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play
*/
public static void onCreate(final Object o) {
// "Plugin.printStackTrace();
if (SettingsEnum.shorts_playing) return;

// "Plugin.printStackTrace();

if (o == null) {
LogHelper.printException(PlayerController.class, "onCreate called with null object");
Expand Down Expand Up @@ -132,6 +134,8 @@ public static void executeDownloadSegments(String videoId) {
* Called when it's time to update the UI with new second, about once per second, only when playing, also in background
*/
public static void setCurrentVideoTime(long millis) {
if (SettingsEnum.shorts_playing) return;

LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis);
VideoInformation.lastKnownVideoTime = millis;
if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
Expand Down Expand Up @@ -216,6 +220,8 @@ private static void sendViewRequestAsync(final long millis, final SponsorSegment
* 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)
*/
public static void setCurrentVideoTimeHighPrecision(final long millis) {
if (SettingsEnum.shorts_playing) return;

if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) {
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
SponsorBlockUtils.showVoteButton();
Expand All @@ -239,12 +245,16 @@ public static long getLastKnownVideoTime() {
* Called before onDraw method on time bar object, sets video length in millis
*/
public static void setVideoLength(final long length) {
if (SettingsEnum.shorts_playing) return;

LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length);
currentVideoLength = length;
}


public static void setSponsorBarAbsoluteLeft(final Rect rect) {
if (SettingsEnum.shorts_playing) return;

setSponsorBarAbsoluteLeft(rect.left);
}

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

public static void setSponsorBarRect(final Object self) {
if (SettingsEnum.shorts_playing) return;

try {
Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect");
field.setAccessible(true);
Expand All @@ -269,6 +281,8 @@ public static void setSponsorBarRect(final Object self) {
}

public static void setSponsorBarAbsoluteRight(final Rect rect) {
if (SettingsEnum.shorts_playing) return;

setSponsorBarAbsoluteRight(rect.right);
}

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

public static void setSponsorBarThickness(final int thickness) {
if (SettingsEnum.shorts_playing) return;

setSponsorBarThickness((float) thickness);
}

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


public static void addSkipSponsorView15(final View view) {
if (SettingsEnum.shorts_playing) return;

playerActivity = new WeakReference<>((Activity) view.getContext());
LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString());

Expand All @@ -321,6 +339,8 @@ public static void addSkipSponsorView14(final View view) {
* Called when it's time to draw time bar
*/
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
if (SettingsEnum.shorts_playing) return;

if (sponsorBarThickness < 0.1) return;
if (sponsorSegmentsOfCurrentVideo == null) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ShieldButton {
static boolean isShowing;

public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;

try {
LogHelper.debug(ShieldButton.class, "initializing shield button");

Expand Down Expand Up @@ -62,10 +64,14 @@ public static void changeVisibilityImmediate(boolean visible) {
}

public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;

changeVisibility(!visible, true);
}

public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;

changeVisibility(visible, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ public static void notifyShareBtnVisibilityChanged(View v) {
}

public static String appendTimeWithoutSegments(String totalTime) {
if (SettingsEnum.shorts_playing) return totalTime;

if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
if (timeWithoutSegments.isEmpty()) {
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class VotingButton {
static boolean isShowing;

public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;

try {
LogHelper.debug(VotingButton.class, "initializing voting button");
_youtubeControlsLayout = (RelativeLayout) viewStub;
Expand Down Expand Up @@ -60,10 +62,14 @@ public static void changeVisibilityImmediate(boolean visible) {
}

public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;

changeVisibility(!visible, true);
}

public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;

changeVisibility(visible, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.lang.ref.WeakReference;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.sponsorblock.player.PlayerType;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
Expand All @@ -22,6 +23,8 @@ public class SponsorBlockView {
static boolean shouldShowOnPlayerType = true;

public static void initialize(Object viewGroup) {
if (SettingsEnum.shorts_playing) return;

try {
LogHelper.debug(SponsorBlockView.class, "initializing");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.integrations.videoplayer;

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

public class VideoInformation {
Expand All @@ -14,6 +15,8 @@ public class VideoInformation {

// Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) {
if (SettingsEnum.shorts_playing) return;

if (videoId == null) {
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
clearInformation(true);
Expand Down

3 comments on commit 3797438

@TheJeterLP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SettingsEnum class is definitely the wrong place for a globally used variable (which shouldnt be used anyways since the integrations are designed to use getter and setter methods)
Also static variables should be written in uppercase in java.

@oSumAtrIX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open a PR regarding this. @TheJeterLP

@TheJeterLP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I do not have time to contribute to ReVanced.

Please sign in to comment.