diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 5b4d8681..299b38f4 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -582,6 +582,12 @@ public final class app/revanced/patches/reddit/customclients/boostforreddit/api/ public fun patchUserAgent (Ljava/util/Set;Lapp/revanced/patcher/data/BytecodeContext;)V } +public final class app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch : app/revanced/patches/reddit/customclients/BaseFixSLinksPatch { public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch; } diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt new file mode 100644 index 00000000..10356965 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads.fingerprints.DownloadAudioFingerprint +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + name = "Fix missing audio in video downloads", + description = "Fixes audio missing in videos downloaded from v.redd.it.", + compatiblePackages = [CompatiblePackage("com.rubenmayayo.reddit")], +) +@Suppress("unused") +object FixAudioMissingInDownloadsPatch : BytecodePatch( + setOf(DownloadAudioFingerprint), +) { + private val endpointReplacements = mapOf( + "/DASH_audio.mp4" to "/DASH_AUDIO_128.mp4", + "/audio" to "/DASH_AUDIO_64.mp4", + ) + override fun execute(context: BytecodeContext) { + DownloadAudioFingerprint.resultOrThrow().let { result -> + result.scanResult.stringsScanResult!!.matches.take(2).forEach { match -> + result.mutableMethod.apply { + val replacement = endpointReplacements[match.string] + val register = getInstruction(match.index).registerA + + replaceInstruction(match.index, "const-string v$register, \"$replacement\"") + } + } + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/fingerprints/DownloadAudioFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/fingerprints/DownloadAudioFingerprint.kt new file mode 100644 index 00000000..b5261523 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/fingerprints/DownloadAudioFingerprint.kt @@ -0,0 +1,7 @@ +package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object DownloadAudioFingerprint : MethodFingerprint( + strings = setOf("/DASH_audio.mp4", "/audio", "v.redd.it", "/"), +)