fix(youtube/return-youtube-dislike): do not fetch voting stats when watching shorts (#302)

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
LisoUseInAIKyrios 2023-01-28 11:28:42 +04:00 committed by GitHub
parent d8bd27251c
commit 7551f0104c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 17 deletions

View File

@ -2,8 +2,8 @@ package app.revanced.integrations.patches;
import androidx.annotation.Nullable;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.utils.LogHelper;
/**
* Hook receiver class for 'player-type-hook' patch
@ -24,7 +24,9 @@ public class PlayerTypeHookPatch {
// update current player type
final PlayerType newType = PlayerType.safeParseFromString(type.toString());
if (newType != null) {
if (newType == null) {
LogHelper.printException(() -> "Unknown PlayerType encountered: " + type);
} else {
PlayerType.setCurrent(newType);
LogHelper.printDebug(() -> "YouTubePlayerOverlaysLayout player type was updated to " + newType);
}

View File

@ -2,7 +2,6 @@ package app.revanced.integrations.returnyoutubedislike;
import static app.revanced.integrations.sponsorblock.StringRef.str;
import android.content.Context;
import android.icu.text.CompactDecimalFormat;
import android.os.Build;
import android.text.Spannable;
@ -13,7 +12,6 @@ import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.ScaleXSpan;
import android.util.DisplayMetrics;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
@ -31,6 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
import app.revanced.integrations.returnyoutubedislike.requests.RYDVoteData;
import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
@ -117,8 +116,12 @@ public class ReturnYouTubeDislike {
if (!isEnabled) return;
try {
Objects.requireNonNull(videoId);
LogHelper.printDebug(() -> "New video loaded: " + videoId);
PlayerType currentPlayerType = PlayerType.getCurrent();
if (currentPlayerType == PlayerType.INLINE_MINIMAL) {
LogHelper.printDebug(() -> "Ignoring inline playback of video: "+ videoId);
return;
}
LogHelper.printDebug(() -> " new video loaded: " + videoId + " playerType: " + currentPlayerType);
synchronized (videoIdLockObject) {
currentVideoId = videoId;
// no need to wrap the call in a try/catch,
@ -175,8 +178,7 @@ public class ReturnYouTubeDislike {
if (updateDislike(textRef, isSegmentedButton, votingData)) {
LogHelper.printDebug(() -> "Updated dislike span to: " + textRef.get());
} else {
LogHelper.printDebug(() -> "Ignoring dislike span: " + textRef.get()
+ " that appears to already show voting data: " + votingData);
LogHelper.printDebug(() -> "Ignoring already updated dislike span: " + textRef.get());
}
} catch (Exception ex) {
LogHelper.printException(() -> "Error while trying to update dislikes", ex);
@ -187,7 +189,13 @@ public class ReturnYouTubeDislike {
if (!isEnabled) return;
try {
Objects.requireNonNull(vote);
if (PlayerType.getCurrent() == PlayerType.NONE) { // should occur if shorts is playing
LogHelper.printDebug(() -> "Ignoring vote during Shorts playback");
return;
}
if (SharedPrefHelper.getBoolean(SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true)) {
LogHelper.printDebug(() -> "User is logged out, ignoring voting");
return;
}

View File

@ -7,7 +7,7 @@ import app.revanced.integrations.utils.Event
*/
@Suppress("unused")
enum class PlayerType {
NONE,
NONE, // this also includes when shorts are playing
HIDDEN,
WATCH_WHILE_MINIMIZED,
WATCH_WHILE_MAXIMIZED,

View File

@ -3,7 +3,6 @@ package app.revanced.integrations.sponsorblock;
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.timeWithoutSegments;
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.videoHasSegments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
@ -21,12 +20,12 @@ import java.util.TimerTask;
import app.revanced.integrations.patches.VideoInformation;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
import app.revanced.integrations.sponsorblock.requests.SBRequester;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
@SuppressLint({"LongLogTag"})
public class PlayerController {
private static final Timer sponsorTimer = new Timer("sponsor-skip-timer");
@ -43,8 +42,6 @@ public class PlayerController {
private static float sponsorBarThickness = 2f;
private static TimerTask skipSponsorTask = null;
public static boolean shorts_playing = false;
public static String getCurrentVideoId() {
return currentVideoId;
}
@ -56,13 +53,19 @@ public class PlayerController {
return;
}
// currently this runs every time a video is loaded (regardless if sponsorblock is turned on or off)
// FIXME: change this so if sponsorblock is disabled, then run this method exactly once and once only
SponsorBlockSettings.update(null);
if (!SettingsEnum.SB_ENABLED.getBoolean()) {
currentVideoId = null;
return;
}
if (PlayerType.getCurrent() == PlayerType.NONE) {
LogHelper.printDebug(() -> "ignoring shorts video");
currentVideoId = null;
return;
}
if (videoId.equals(currentVideoId))
return;
@ -90,9 +93,7 @@ public class PlayerController {
public static void executeDownloadSegments(String videoId) {
videoHasSegments = false;
timeWithoutSegments = "";
if (shorts_playing) {
return;
}
SponsorSegment[] segments = SBRequester.getSegments(videoId);
Arrays.sort(segments);