fix: disable sponsorblock on shorts (#135)

This commit is contained in:
OxrxL 2022-09-21 03:03:37 +02:00 committed by GitHub
parent 3fd6df8277
commit 37974389ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 2 deletions

View File

@ -108,6 +108,7 @@ public enum SettingsEnum {
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), 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); 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 String path;
private final Object defaultValue; private final Object defaultValue;
private final SharedPrefHelper.SharedPrefNames sharedPref; private final SharedPrefHelper.SharedPrefNames sharedPref;
@ -250,5 +251,4 @@ public enum SettingsEnum {
public boolean shouldRebootOnChange() { public boolean shouldRebootOnChange() {
return rebootApp; return rebootApp;
} }
} }

View File

@ -87,7 +87,9 @@ public class PlayerController {
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play * 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) { public static void onCreate(final Object o) {
// "Plugin.printStackTrace(); if (SettingsEnum.shorts_playing) return;
// "Plugin.printStackTrace();
if (o == null) { if (o == null) {
LogHelper.printException(PlayerController.class, "onCreate called with null object"); LogHelper.printException(PlayerController.class, "onCreate called with null object");
@ -132,6 +134,8 @@ public class PlayerController {
* Called when it's time to update the UI with new second, about once per second, only when playing, also in background * 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) { public static void setCurrentVideoTime(long millis) {
if (SettingsEnum.shorts_playing) return;
LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis); LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis);
VideoInformation.lastKnownVideoTime = millis; VideoInformation.lastKnownVideoTime = millis;
if (!SettingsEnum.SB_ENABLED.getBoolean()) return; if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
@ -216,6 +220,8 @@ public class PlayerController {
* 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) * 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) { public static void setCurrentVideoTimeHighPrecision(final long millis) {
if (SettingsEnum.shorts_playing) return;
if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) { if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) {
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
SponsorBlockUtils.showVoteButton(); SponsorBlockUtils.showVoteButton();
@ -239,12 +245,16 @@ public class PlayerController {
* Called before onDraw method on time bar object, sets video length in millis * Called before onDraw method on time bar object, sets video length in millis
*/ */
public static void setVideoLength(final long length) { public static void setVideoLength(final long length) {
if (SettingsEnum.shorts_playing) return;
LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length); LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length);
currentVideoLength = length; currentVideoLength = length;
} }
public static void setSponsorBarAbsoluteLeft(final Rect rect) { public static void setSponsorBarAbsoluteLeft(final Rect rect) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarAbsoluteLeft(rect.left); setSponsorBarAbsoluteLeft(rect.left);
} }
@ -255,6 +265,8 @@ public class PlayerController {
} }
public static void setSponsorBarRect(final Object self) { public static void setSponsorBarRect(final Object self) {
if (SettingsEnum.shorts_playing) return;
try { try {
Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect"); Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect");
field.setAccessible(true); field.setAccessible(true);
@ -269,6 +281,8 @@ public class PlayerController {
} }
public static void setSponsorBarAbsoluteRight(final Rect rect) { public static void setSponsorBarAbsoluteRight(final Rect rect) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarAbsoluteRight(rect.right); setSponsorBarAbsoluteRight(rect.right);
} }
@ -279,6 +293,8 @@ public class PlayerController {
} }
public static void setSponsorBarThickness(final int thickness) { public static void setSponsorBarThickness(final int thickness) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarThickness((float) thickness); setSponsorBarThickness((float) thickness);
} }
@ -296,6 +312,8 @@ public class PlayerController {
public static void addSkipSponsorView15(final View view) { public static void addSkipSponsorView15(final View view) {
if (SettingsEnum.shorts_playing) return;
playerActivity = new WeakReference<>((Activity) view.getContext()); playerActivity = new WeakReference<>((Activity) view.getContext());
LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString()); LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString());
@ -321,6 +339,8 @@ public class PlayerController {
* Called when it's time to draw time bar * Called when it's time to draw time bar
*/ */
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) { public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
if (SettingsEnum.shorts_playing) return;
if (sponsorBarThickness < 0.1) return; if (sponsorBarThickness < 0.1) return;
if (sponsorSegmentsOfCurrentVideo == null) return; if (sponsorSegmentsOfCurrentVideo == null) return;

View File

@ -28,6 +28,8 @@ public class ShieldButton {
static boolean isShowing; static boolean isShowing;
public static void initialize(Object viewStub) { public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(ShieldButton.class, "initializing shield button"); LogHelper.debug(ShieldButton.class, "initializing shield button");
@ -62,10 +64,14 @@ public class ShieldButton {
} }
public static void changeVisibilityNegatedImmediate(boolean visible) { public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(!visible, true); changeVisibility(!visible, true);
} }
public static void changeVisibility(boolean visible) { public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(visible, false); changeVisibility(visible, false);
} }

View File

@ -403,6 +403,8 @@ public abstract class SponsorBlockUtils {
} }
public static String appendTimeWithoutSegments(String totalTime) { 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 (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
if (timeWithoutSegments.isEmpty()) { if (timeWithoutSegments.isEmpty()) {
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo); timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);

View File

@ -27,6 +27,8 @@ public class VotingButton {
static boolean isShowing; static boolean isShowing;
public static void initialize(Object viewStub) { public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(VotingButton.class, "initializing voting button"); LogHelper.debug(VotingButton.class, "initializing voting button");
_youtubeControlsLayout = (RelativeLayout) viewStub; _youtubeControlsLayout = (RelativeLayout) viewStub;
@ -60,10 +62,14 @@ public class VotingButton {
} }
public static void changeVisibilityNegatedImmediate(boolean visible) { public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(!visible, true); changeVisibility(!visible, true);
} }
public static void changeVisibility(boolean visible) { public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(visible, false); changeVisibility(visible, false);
} }

View File

@ -8,6 +8,7 @@ import android.widget.RelativeLayout;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.sponsorblock.player.PlayerType; import app.revanced.integrations.sponsorblock.player.PlayerType;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils; import app.revanced.integrations.utils.ReVancedUtils;
@ -22,6 +23,8 @@ public class SponsorBlockView {
static boolean shouldShowOnPlayerType = true; static boolean shouldShowOnPlayerType = true;
public static void initialize(Object viewGroup) { public static void initialize(Object viewGroup) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(SponsorBlockView.class, "initializing"); LogHelper.debug(SponsorBlockView.class, "initializing");

View File

@ -1,5 +1,6 @@
package app.revanced.integrations.videoplayer; package app.revanced.integrations.videoplayer;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
public class VideoInformation { public class VideoInformation {
@ -14,6 +15,8 @@ public class VideoInformation {
// Call hook in the YT code when the video changes // Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) { public static void setCurrentVideoId(final String videoId) {
if (SettingsEnum.shorts_playing) return;
if (videoId == null) { if (videoId == null) {
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId); LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
clearInformation(true); clearInformation(true);