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 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.patches.VideoInformation;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.shared.PlayerType; import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
/** @noinspection unused*/ /** @noinspection unused*/
public class SpoofSignaturePatch { public class SpoofSignaturePatch {
@ -43,8 +49,7 @@ public class SpoofSignaturePatch {
*/ */
private static volatile String currentVideoId; private static volatile String currentVideoId;
@Nullable private static volatile Future<StoryboardRenderer> rendererFuture;
private static volatile StoryboardRenderer renderer;
/** /**
* Injection point. * Injection point.
@ -78,13 +83,27 @@ public class SpoofSignaturePatch {
String videoId = VideoInformation.getVideoId(); String videoId = VideoInformation.getVideoId();
if (!videoId.equals(currentVideoId)) { if (!videoId.equals(currentVideoId)) {
currentVideoId = videoId; currentVideoId = videoId;
renderer = fetchStoryboardRenderer(videoId); rendererFuture = ReVancedUtils.submitOnBackgroundThread(() -> fetchStoryboardRenderer(videoId));
LogHelper.printDebug(() -> "Fetched: " + renderer);
} }
return INCOGNITO_PARAMETERS; 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. * Injection point.
*/ */
@ -100,10 +119,10 @@ public class SpoofSignaturePatch {
public static String getStoryboardRendererSpec(String originalStoryboardRendererSpec) { public static String getStoryboardRendererSpec(String originalStoryboardRendererSpec) {
if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalStoryboardRendererSpec; if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalStoryboardRendererSpec;
StoryboardRenderer currentRenderer = renderer; StoryboardRenderer renderer = getRenderer();
if (currentRenderer == null) return originalStoryboardRendererSpec; if (renderer == null) return originalStoryboardRendererSpec;
return currentRenderer.getSpec(); return renderer.getSpec();
} }
/** /**
@ -112,10 +131,10 @@ public class SpoofSignaturePatch {
public static int getRecommendedLevel(int originalLevel) { public static int getRecommendedLevel(int originalLevel) {
if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalLevel; if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalLevel;
StoryboardRenderer currentRenderer = renderer; StoryboardRenderer renderer = getRenderer();
if (currentRenderer == null) return originalLevel; if (renderer == null) return originalLevel;
return currentRenderer.getRecommendedLevel(); return renderer.getRecommendedLevel();
} }
} }

View File

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