fix(YouTube - Spoof client): Restore livestream audio only playback with iOS spoofing (#3504)

This commit is contained in:
LisoUseInAIKyrios 2024-08-04 15:38:10 -04:00 committed by GitHub
parent becaad4a98
commit 90d3288090
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 54 deletions

View file

@ -16,7 +16,9 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMu
import app.revanced.patches.all.misc.resources.AddResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.*
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
@ -38,16 +40,21 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
SettingsPatch::class,
AddResourcesPatch::class,
UserAgentClientSpoofPatch::class,
// Required since iOS livestream fix partially enables background playback.
BackgroundPlaybackPatch::class,
PlayerTypeHookPatch::class,
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.37.36",
"18.38.44",
"18.43.45",
"18.44.41",
"18.45.43",
// This patch works with these versions,
// but the dependent background playback patch does not.
// "18.37.36",
// "18.38.44",
// "18.43.45",
// "18.44.41",
// "18.45.43",
"18.48.39",
"18.49.37",
"19.01.34",
@ -89,9 +96,9 @@ object SpoofClientPatch : BytecodePatch(
// Video qualities missing.
BuildRequestFingerprint,
// Watch history.
GetTrackingUriFingerprint,
),
// Livestream audio only background playback.
PlayerResponseModelBackgroundAudioPlaybackFingerprint,
)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/spoof/SpoofClientPatch;"
@ -316,6 +323,23 @@ object SpoofClientPatch : BytecodePatch(
// endregion
// region Fix livestream audio only background play if spoofing to iOS.
// This force enables audio background playback.
PlayerResponseModelBackgroundAudioPlaybackFingerprint.resultOrThrow().mutableMethod.addInstructions(
0,
"""
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideBackgroundAudioPlayback()Z
move-result v0
if-eqz v0, :do_not_override
return v0
:do_not_override
nop
"""
)
// endregion
// Fix playback speed menu item if spoofing to iOS.
CreatePlaybackSpeedMenuItemFingerprint.resultOrThrow().let {
@ -340,25 +364,6 @@ object SpoofClientPatch : BytecodePatch(
// endregion
// Fix watch history if spoofing to iOS.
GetTrackingUriFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val returnUrlIndex = it.scanResult.patternScanResult!!.endIndex
val urlRegister = getInstruction<OneRegisterInstruction>(returnUrlIndex).registerA
addInstructions(
returnUrlIndex,
"""
invoke-static { v$urlRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideTrackingUrl(Landroid/net/Uri;)Landroid/net/Uri;
move-result-object v$urlRegister
"""
)
}
}
// endregion
// region Fix video qualities missing, if spoofing to iOS by overriding the user agent.
BuildRequestFingerprint.resultOrThrow().let { result ->

View file

@ -1,21 +0,0 @@
package app.revanced.patches.youtube.misc.fix.playback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
internal object GetTrackingUriFingerprint : MethodFingerprint(
returnType = "Landroid/net/Uri;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT
),
customFingerprint = { _, classDef ->
classDef.endsWith("TrackingUrlModel;")
}
)

View file

@ -0,0 +1,25 @@
package app.revanced.patches.youtube.misc.fix.playback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
internal object PlayerResponseModelBackgroundAudioPlaybackFingerprint : MethodFingerprint(
returnType = "Z",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("Lcom/google/android/libraries/youtube/innertube/model/player/PlayerResponseModel;"),
opcodes = listOf(
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.GOTO,
Opcode.RETURN,
null, // Opcode.CONST_4 or Opcode.MOVE
Opcode.RETURN,
)
)

View file

@ -32,11 +32,12 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
CompatiblePackage(
"com.google.android.youtube",
setOf(
"18.37.36",
"18.38.44",
"18.43.45",
"18.44.41",
"18.45.43",
// Patch supports these versions but ClientSpoof does not.
// "18.37.36",
// "18.38.44",
// "18.43.45",
// "18.44.41",
// "18.45.43",
"18.48.39",
"18.49.37",
"19.01.34",

View file

@ -1135,7 +1135,7 @@ This is because Crowdin requires temporarily flattening this file and removing t
<string name="revanced_spoof_client_summary_off">Client is not spoofed\n\nVideo playback may not work</string>
<string name="revanced_spoof_client_user_dialog_message">Turning off this setting may cause video playback issues.</string>
<string name="revanced_spoof_client_use_ios_title">Spoof client to iOS</string>
<string name="revanced_spoof_client_use_ios_summary_on">Client is currently spoofed to iOS\n\nSide effects include:\n• No HDR video\n• Higher video qualities may be missing\n• Live streams cannot play as audio only</string>
<string name="revanced_spoof_client_use_ios_summary_on">Client is currently spoofed to iOS\n\nSide effects include:\n• HDR video may not be available\n• Watch history may not work</string>
<string name="revanced_spoof_client_use_ios_summary_off">Client is currently spoofed to Android VR\n\nSide effects include:\n• No HDR video\n• Kids videos do not playback\n• Paused videos can randomly resume\n• Low quality Shorts seekbar thumbnails\n• Download action button is hidden\n• End screen cards are hidden</string>
<string name="revanced_spoof_client_storyboard_timeout">Spoof client thumbnails not available (API timed out)</string>
<string name="revanced_spoof_client_storyboard_io_exception">Spoof client thumbnails temporarily not available: %s</string>