fix(YouTube - ReturnYouTubeDislike): Fix RYD prefetching home feed Shorts (#508)

This commit is contained in:
LisoUseInAIKyrios 2023-10-24 23:34:13 +03:00 committed by GitHub
parent 959ae4f3be
commit 98c91af130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -404,11 +404,14 @@ public class ReturnYouTubeDislikePatch {
/**
* Injection point. Uses 'playback response' video id hook to preload RYD.
*/
public static void preloadVideoId(@NonNull String videoId) {
if (!SettingsEnum.RYD_ENABLED.getBoolean()) {
public static void preloadVideoId(@NonNull String videoId, boolean videoIsOpeningOrPlaying) {
// Shorts shelf in home and subscription feed causes player response hook to be called,
// and the 'is opening/playing' parameter will be false.
// This hook will be called again when the Short is actually opened.
if (!videoIsOpeningOrPlaying || !SettingsEnum.RYD_ENABLED.getBoolean()) {
return;
}
if (!SettingsEnum.RYD_SHORTS.getBoolean() && PlayerType.getCurrent().isNoneOrHidden()) {
if (!SettingsEnum.RYD_SHORTS.getBoolean() && PlayerType.getCurrent().isNoneHiddenOrSlidingMinimized()) {
return;
}
if (videoId.equals(lastPrefetchedVideoId)) {
@ -471,12 +474,13 @@ public class ReturnYouTubeDislikePatch {
if (videoIdIsSame(currentVideoData, videoId)) {
return;
}
currentVideoData = ReturnYouTubeDislike.getFetchForVideoId(videoId);
ReturnYouTubeDislike data = ReturnYouTubeDislike.getFetchForVideoId(videoId);
// Pre-emptively set the data to short status.
// Required to prevent Shorts data from being used on a minimized video in incognito mode.
if (isNoneHiddenOrSlidingMinimized) {
currentVideoData.setVideoIdIsShort(true);
data.setVideoIdIsShort(true);
}
currentVideoData = data;
}
LogHelper.printDebug(() -> "New video id: " + videoId + " playerType: " + currentPlayerType

View File

@ -69,7 +69,7 @@ public final class VideoInformation {
*
* @param videoId The id of the last video loaded.
*/
public static void setPlayerResponseVideoId(@NonNull String videoId) {
public static void setPlayerResponseVideoId(@NonNull String videoId, boolean videoIsOpeningOrPlaying) {
if (!playerResponseVideoId.equals(videoId)) {
LogHelper.printDebug(() -> "New player response video id: " + videoId);
playerResponseVideoId = videoId;

View File

@ -53,9 +53,9 @@ public final class ReturnYouTubeDislikeFilterPatch extends Filter {
/**
* Injection point.
*/
public static void newPlayerResponseVideoId(String videoId) {
public static void newPlayerResponseVideoId(String videoId, boolean videoIsOpeningOrPlaying) {
try {
if (!SettingsEnum.RYD_SHORTS.getBoolean()) {
if (!videoIsOpeningOrPlaying || !SettingsEnum.RYD_SHORTS.getBoolean()) {
return;
}
synchronized (lastVideoIds) {