Skip to content

Commit bc8bc8c

Browse files
author
LisoUseInAIKyrios
authored
feat(YouTube - Downloads): Use external downloader when selecting 'Download' in home feed flyout menu (#2881)
1 parent 76805e4 commit bc8bc8c

File tree

4 files changed

+16
-78
lines changed

4 files changed

+16
-78
lines changed

src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/DownloadsPatch.kt

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
66
import app.revanced.patcher.patch.BytecodePatch
77
import app.revanced.patcher.patch.annotation.CompatiblePackage
88
import app.revanced.patcher.patch.annotation.Patch
9-
import app.revanced.patches.youtube.interaction.downloads.fingerprints.DownloadActionCommandResolverFingerprint
10-
import app.revanced.patches.youtube.interaction.downloads.fingerprints.DownloadActionCommandResolverParentFingerprint
11-
import app.revanced.patches.youtube.interaction.downloads.fingerprints.LegacyDownloadCommandResolverFingerprint
9+
import app.revanced.patches.youtube.interaction.downloads.fingerprints.OfflineVideoEndpointFingerprint
1210
import app.revanced.patches.youtube.misc.playercontrols.PlayerControlsBytecodePatch
1311
import app.revanced.patches.youtube.shared.fingerprints.MainActivityFingerprint
1412
import app.revanced.patches.youtube.video.information.VideoInformationPatch
@@ -45,8 +43,7 @@ import app.revanced.util.resultOrThrow
4543
@Suppress("unused")
4644
object DownloadsPatch : BytecodePatch(
4745
setOf(
48-
DownloadActionCommandResolverParentFingerprint,
49-
LegacyDownloadCommandResolverFingerprint,
46+
OfflineVideoEndpointFingerprint,
5047
MainActivityFingerprint
5148
)
5249
) {
@@ -65,36 +62,16 @@ object DownloadsPatch : BytecodePatch(
6562
)
6663
}
6764

68-
val commonInstructions = """
69-
move-result v0
70-
if-eqz v0, :show_native_downloader
71-
return-void
72-
:show_native_downloader
73-
nop
74-
"""
75-
76-
DownloadActionCommandResolverFingerprint.resolve(context,
77-
DownloadActionCommandResolverParentFingerprint.resultOrThrow().classDef)
78-
DownloadActionCommandResolverFingerprint.resultOrThrow().mutableMethod.apply {
79-
addInstructionsWithLabels(
80-
0,
81-
"""
82-
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick()Z
83-
$commonInstructions
84-
"""
85-
)
86-
}
87-
88-
// Legacy fingerprint is used for old spoofed versions,
89-
// or if download playlist is pressed on any version.
90-
// Downloading playlists is not yet supported,
91-
// as the code this hooks does not easily expost the playlist id.
92-
LegacyDownloadCommandResolverFingerprint.resultOrThrow().mutableMethod.apply {
65+
OfflineVideoEndpointFingerprint.resultOrThrow().mutableMethod.apply {
9366
addInstructionsWithLabels(
9467
0,
9568
"""
96-
invoke-static/range {p1 .. p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->inAppDownloadPlaylistLegacyOnClick(Ljava/lang/String;)Z
97-
$commonInstructions
69+
invoke-static/range {p3 .. p3}, $INTEGRATIONS_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/lang/String;)Z
70+
move-result v0
71+
if-eqz v0, :show_native_downloader
72+
return-void
73+
:show_native_downloader
74+
nop
9875
"""
9976
)
10077
}

src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/fingerprints/DownloadActionCommandResolverParentFingerprint.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/fingerprints/LegacyDownloadCommandResolverFingerprint.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import app.revanced.patcher.extensions.or
44
import app.revanced.patcher.fingerprint.MethodFingerprint
55
import com.android.tools.smali.dexlib2.AccessFlags
66

7-
/**
8-
* Resolves to the class found in [DownloadActionCommandResolverParentFingerprint].
9-
*/
10-
internal object DownloadActionCommandResolverFingerprint : MethodFingerprint(
7+
internal object OfflineVideoEndpointFingerprint : MethodFingerprint(
118
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
129
returnType = "V",
13-
parameters = listOf("L", "Ljava/util/Map;")
10+
parameters = listOf(
11+
"Ljava/util/Map;",
12+
"L",
13+
"Ljava/lang/String", // VideoId
14+
"L"),
15+
strings = listOf("Object is not an offlineable video: ")
1416
)

0 commit comments

Comments
 (0)