Skip to content

Commit

Permalink
fix(youtube/return-youtube-dislike): do not fetch voting stats when w…
Browse files Browse the repository at this point in the history
…atching shorts (#302)

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX committed Jan 28, 2023
1 parent d8bd272 commit 7551f01
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
Expand Up @@ -2,8 +2,8 @@

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
Expand All @@ -24,7 +24,9 @@ public static void YouTubePlayerOverlaysLayout_updatePlayerTypeHookEX(@Nullable

// 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);
}
Expand Down
Expand Up @@ -2,7 +2,6 @@

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;
Expand All @@ -13,7 +12,6 @@
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;
Expand All @@ -31,6 +29,7 @@
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;
Expand Down Expand Up @@ -117,8 +116,12 @@ public static void newVideoLoaded(String videoId) {
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,
Expand Down Expand Up @@ -175,8 +178,7 @@ public static void onComponentCreated(Object conversionContext, AtomicReference<
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);
Expand All @@ -187,7 +189,13 @@ public static void sendVote(Vote vote) {
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;
}

Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -21,12 +20,12 @@

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");
Expand All @@ -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;
}
Expand All @@ -56,13 +53,19 @@ public static void setCurrentVideoId(final String videoId) {
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;

Expand Down Expand Up @@ -90,9 +93,7 @@ public static void initialize(Object _o) {
public static void executeDownloadSegments(String videoId) {
videoHasSegments = false;
timeWithoutSegments = "";
if (shorts_playing) {
return;
}

SponsorSegment[] segments = SBRequester.getSegments(videoId);
Arrays.sort(segments);

Expand Down

0 comments on commit 7551f01

Please sign in to comment.