From 27f49dfd1e8fbfd3e28270da91ad437df8a54761 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:12:14 +0400 Subject: [PATCH] fix(YouTube - Client spoof): Fix toast shown for live streams (#489) --- .../patches/spoof/SpoofSignaturePatch.java | 23 +++++++++++-------- .../patches/spoof/StoryboardRenderer.java | 13 ++++++++--- .../requests/StoryboardRendererRequester.java | 6 +++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofSignaturePatch.java b/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofSignaturePatch.java index 42392480ad..16a284d049 100644 --- a/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofSignaturePatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofSignaturePatch.java @@ -128,23 +128,26 @@ public static boolean getSeekbarThumbnailOverrideValue() { */ @Nullable public static String getStoryboardRendererSpec(String originalStoryboardRendererSpec) { - if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalStoryboardRendererSpec; - - StoryboardRenderer renderer = getRenderer(); - if (renderer == null) return originalStoryboardRendererSpec; + if (SettingsEnum.SPOOF_SIGNATURE.getBoolean()) { + StoryboardRenderer renderer = getRenderer(); + if (renderer != null) return renderer.getSpec(); + } - return renderer.getSpec(); + return originalStoryboardRendererSpec; } /** * Injection point. */ public static int getRecommendedLevel(int originalLevel) { - if (!SettingsEnum.SPOOF_SIGNATURE.getBoolean()) return originalLevel; - - StoryboardRenderer renderer = getRenderer(); - if (renderer == null) return originalLevel; + if (SettingsEnum.SPOOF_SIGNATURE.getBoolean()) { + StoryboardRenderer renderer = getRenderer(); + if (renderer != null) { + Integer recommendedLevel = renderer.getRecommendedLevel(); + if (recommendedLevel != null) return recommendedLevel; + } + } - return renderer.getRecommendedLevel(); + return originalLevel; } } diff --git a/app/src/main/java/app/revanced/integrations/patches/spoof/StoryboardRenderer.java b/app/src/main/java/app/revanced/integrations/patches/spoof/StoryboardRenderer.java index c7ce43e57d..d0e70988bf 100644 --- a/app/src/main/java/app/revanced/integrations/patches/spoof/StoryboardRenderer.java +++ b/app/src/main/java/app/revanced/integrations/patches/spoof/StoryboardRenderer.java @@ -1,13 +1,16 @@ package app.revanced.integrations.patches.spoof; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.jetbrains.annotations.NotNull; public final class StoryboardRenderer { private final String spec; - private final int recommendedLevel; + @Nullable + private final Integer recommendedLevel; - public StoryboardRenderer(String spec, int recommendedLevel) { + public StoryboardRenderer(String spec, @Nullable Integer recommendedLevel) { this.spec = spec; this.recommendedLevel = recommendedLevel; } @@ -17,7 +20,11 @@ public String getSpec() { return spec; } - public int getRecommendedLevel() { + /** + * @return Recommended image quality level, or NULL if no recommendation exists. + */ + @Nullable + public Integer getRecommendedLevel() { return recommendedLevel; } diff --git a/app/src/main/java/app/revanced/integrations/patches/spoof/requests/StoryboardRendererRequester.java b/app/src/main/java/app/revanced/integrations/patches/spoof/requests/StoryboardRendererRequester.java index 3138630570..61828a04bb 100644 --- a/app/src/main/java/app/revanced/integrations/patches/spoof/requests/StoryboardRendererRequester.java +++ b/app/src/main/java/app/revanced/integrations/patches/spoof/requests/StoryboardRendererRequester.java @@ -49,7 +49,7 @@ private static boolean isPlayabilityStatusOk(@NonNull JSONObject playerResponse) try { return playerResponse.getJSONObject("playabilityStatus").getString("status").equals("OK"); } catch (JSONException e) { - LogHelper.printException(() -> "Failed to get playabilityStatus", e); + LogHelper.printDebug(() -> "Failed to get playabilityStatus for response: " + playerResponse); } return false; @@ -80,7 +80,9 @@ private static StoryboardRenderer getStoryboardRendererUsingResponse(@NonNull JS final var rendererElement = storyboards.getJSONObject(storyboardsRendererTag); StoryboardRenderer renderer = new StoryboardRenderer( rendererElement.getString("spec"), - rendererElement.getInt("recommendedLevel") + rendererElement.has("recommendedLevel") + ? rendererElement.getInt("recommendedLevel") + : null ); LogHelper.printDebug(() -> "Fetched: " + renderer);