From 140f484b4b251b0dfa94163a63f61f45f5302052 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Mon, 16 Dec 2024 22:43:50 +0400
Subject: [PATCH] fix(YouTube - Spoof video streams): Make livestreams start at
the current time when using iOS client (#4137)
---
.../shared/spoof/SpoofVideoStreamsPatch.java | 17 +++++++++++++++++
.../patches/shared/misc/spoof/Fingerprints.kt | 11 +++++++++++
.../shared/misc/spoof/SpoofVideoStreamsPatch.kt | 10 ++++++++++
.../resources/addresources/values/strings.xml | 1 -
4 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java
index 9e61eca99..8e480c40e 100644
--- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java
+++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java
@@ -16,6 +16,10 @@ import app.revanced.extension.shared.spoof.requests.StreamingDataRequest;
@SuppressWarnings("unused")
public class SpoofVideoStreamsPatch {
private static final boolean SPOOF_STREAMING_DATA = BaseSettings.SPOOF_VIDEO_STREAMS.get();
+
+ private static final boolean FIX_HLS_CURRENT_TIME = SPOOF_STREAMING_DATA
+ && BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS;
+
/**
* Any unreachable ip address. Used to intentionally fail requests.
*/
@@ -165,6 +169,19 @@ public class SpoofVideoStreamsPatch {
return postData;
}
+ /**
+ * Injection point.
+ *
+ * Fixes iOS livestreams starting from the beginning.
+ */
+ public static boolean fixHLSCurrentTime(boolean original) {
+ if (FIX_HLS_CURRENT_TIME) {
+ return false;
+ }
+
+ return original;
+ }
+
public static final class SpoofiOSAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt
index 3976d03e7..0c8293536 100644
--- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt
@@ -1,6 +1,7 @@
package app.revanced.patches.shared.misc.spoof
import app.revanced.patcher.fingerprint
+import app.revanced.util.literal
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@@ -110,3 +111,13 @@ internal val buildMediaDataSourceFingerprint = fingerprint {
"Ljava/lang/Object;",
)
}
+
+internal const val HLS_CURRENT_TIME_FEATURE_FLAG = 45355374L
+
+internal val hlsCurrentTimeFingerprint = fingerprint {
+ accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
+ parameters("Z", "L")
+ literal {
+ HLS_CURRENT_TIME_FEATURE_FLAG
+ }
+}
diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt
index 9b64e386b..004443ed1 100644
--- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt
@@ -12,6 +12,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMu
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
+import app.revanced.util.insertFeatureFlagBooleanOverride
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
@@ -201,6 +202,15 @@ fun spoofVideoStreamsPatch(
}
// endregion
+ // region Fix iOS livestream current time.
+
+ hlsCurrentTimeFingerprint.method.insertFeatureFlagBooleanOverride(
+ HLS_CURRENT_TIME_FEATURE_FLAG,
+ "$EXTENSION_CLASS_DESCRIPTOR->fixHLSCurrentTime(Z)Z"
+ )
+
+ // endregion
+
executeBlock()
}
}
diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml
index e45b97d09..b622d5b28 100644
--- a/patches/src/main/resources/addresources/values/strings.xml
+++ b/patches/src/main/resources/addresources/values/strings.xml
@@ -1290,7 +1290,6 @@ Video playback may not work"
AVC has a maximum resolution of 1080p, Opus audio codec is not available, and video playback will use more internet data than VP9 or AV1."
iOS spoofing side effects
"• Private kids videos may not play
-• Livestreams start from the beginning
• Videos end 1 second early"
Android VR spoofing side effects
"• Kids videos may not play