fix(YouTube - Client spoof): fix storyboard fetched out of order (#481)

This commit is contained in:
LisoUseInAIKyrios 2023-09-26 05:09:01 +04:00 committed by GitHub
parent a591c62543
commit 83987747e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 15 deletions

View File

@ -5,10 +5,16 @@ import static app.revanced.integrations.utils.ReVancedUtils.containsAny;
import androidx.annotation.Nullable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import app.revanced.integrations.patches.VideoInformation;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
/** @noinspection unused*/
public class SpoofSignaturePatch {
@ -43,8 +49,7 @@ public class SpoofSignaturePatch {
*/
private static volatile String currentVideoId;
@Nullable
private static volatile StoryboardRenderer renderer;
private static volatile Future<StoryboardRenderer> rendererFuture;
/**
* Injection point.
@ -78,13 +83,27 @@ public class SpoofSignaturePatch {
String videoId = VideoInformation.getVideoId();
if (!videoId.equals(currentVideoId)) {
currentVideoId = videoId;
renderer = fetchStoryboardRenderer(videoId);
LogHelper.printDebug(() -> "Fetched: " + renderer);
rendererFuture = ReVancedUtils.submitOnBackgroundThread(() -> fetchStoryboardRenderer(videoId));
}
return INCOGNITO_PARAMETERS;
}
@Nullable
private static StoryboardRenderer getRenderer() {
if (rendererFuture != null) {
try {
return rendererFuture.get(5000, TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
LogHelper.printDebug(() -> "Could not get renderer (get timed out)");
} catch (ExecutionException | InterruptedException ex) {
// Should never happen.
LogHelper.printException(() -> "Could not get renderer", ex);
}
}
return null;
}
/**
* Injection point.
*/
@ -100,10 +119,10 @@ public class SpoofSignaturePatch {
public static String getStoryboardRendererSpec(String originalStoryboardRendererSpec) {
if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalStoryboardRendererSpec;
StoryboardRenderer currentRenderer = renderer;
if (currentRenderer == null) return originalStoryboardRendererSpec;
StoryboardRenderer renderer = getRenderer();
if (renderer == null) return originalStoryboardRendererSpec;
return currentRenderer.getSpec();
return renderer.getSpec();
}
/**
@ -112,10 +131,10 @@ public class SpoofSignaturePatch {
public static int getRecommendedLevel(int originalLevel) {
if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalLevel;
StoryboardRenderer currentRenderer = renderer;
if (currentRenderer == null) return originalLevel;
StoryboardRenderer renderer = getRenderer();
if (renderer == null) return originalLevel;
return currentRenderer.getRecommendedLevel();
return renderer.getRecommendedLevel();
}
}

View File

@ -53,12 +53,13 @@ public class StoryBoardRendererRequester {
? "playerLiveStoryboardSpecRenderer"
: "playerStoryboardSpecRenderer";
final var renderer = storyboards.getJSONObject(storyboardsRendererTag);
return new StoryboardRenderer(
renderer.getString("spec"),
renderer.getInt("recommendedLevel")
final var rendererElement = storyboards.getJSONObject(storyboardsRendererTag);
StoryboardRenderer renderer = new StoryboardRenderer(
rendererElement.getString("spec"),
rendererElement.getInt("recommendedLevel")
);
LogHelper.printDebug(() -> "Fetched: " + renderer);
return renderer;
} else {
LogHelper.printException(() -> "API not available: " + responseCode);
connection.disconnect();