Skip to content

Commit

Permalink
feat(YouTube - External downloader): Add ability to use in-app downlo…
Browse files Browse the repository at this point in the history
…ad button
  • Loading branch information
oSumAtrIX committed Mar 4, 2024
1 parent c4379c0 commit d900011
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 59 deletions.
4 changes: 2 additions & 2 deletions api/revanced-patches.api
Expand Up @@ -1194,8 +1194,8 @@ public final class app/revanced/patches/youtube/interaction/dialog/RemoveViewerD
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsBytecodePatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/interaction/downloads/ExternalDownloadsBytecodePatch;
public final class app/revanced/patches/youtube/interaction/downloads/DownloadsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/interaction/downloads/DownloadsPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}
Expand Down
Expand Up @@ -39,7 +39,6 @@ object CopyVideoUrlBytecodePatch : BytecodePatch(emptySet()) {
)

override fun execute(context: BytecodeContext) {
// Initialize buttons and inject visibility control
BUTTONS_DESCRIPTORS.forEach { descriptor ->
PlayerControlsBytecodePatch.initializeControl("$descriptor->initializeButton(Landroid/view/View;)V")
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$descriptor->changeVisibility(Z)V")
Expand Down
@@ -0,0 +1,67 @@
package app.revanced.patches.youtube.interaction.downloads

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.interaction.downloads.fingerprints.DownloadButtonActionFingerprint
import app.revanced.patches.youtube.misc.playercontrols.PlayerControlsBytecodePatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.exception

@Patch(
name = "Downloads",
description = "Adds support to download videos with an external downloader app" +
"using the in-app download button or a video player action button.",
dependencies = [
DownloadsResourcePatch::class,
PlayerControlsBytecodePatch::class,
VideoInformationPatch::class,
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.48.39",
"18.49.37",
"19.01.34",
"19.02.39",
"19.03.35",
"19.03.36",
"19.04.37",
],
),
],
)
@Suppress("unused")
object DownloadsPatch : BytecodePatch(
setOf(
DownloadButtonActionFingerprint,
),
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/youtube/patches/DownloadsPatch;"
private const val BUTTON_DESCRIPTOR = "Lapp/revanced/integrations/youtube/videoplayer/ExternalDownloadButton;"

override fun execute(context: BytecodeContext) {
PlayerControlsBytecodePatch.initializeControl("$BUTTON_DESCRIPTOR->initializeButton(Landroid/view/View;)V")
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$BUTTON_DESCRIPTOR->changeVisibility(Z)V")

DownloadButtonActionFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
2,
"""
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick()Z
move-result v0
if-eqz v0, :show_dialog
return-void
""",
ExternalLabel("show_dialog", getInstruction(2)),
)
}
} ?: throw DownloadButtonActionFingerprint.exception
}
}
Expand Up @@ -21,7 +21,7 @@ import app.revanced.util.copyResources
AddResourcesPatch::class,
],
)
internal object ExternalDownloadsResourcePatch : ResourcePatch() {
internal object DownloadsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

Expand All @@ -32,6 +32,7 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() {
preferences = setOf(
SwitchPreference("revanced_external_downloader"),
TextPreference("revanced_external_downloader_name", inputType = InputType.TEXT),
SwitchPreference("revanced_use_in_app_download_button"),
),
),
)
Expand Down

This file was deleted.

@@ -0,0 +1,7 @@
package app.revanced.patches.youtube.interaction.downloads.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

internal object DownloadButtonActionFingerprint : MethodFingerprint(
strings = listOf("offline/get_download_action"),
)
5 changes: 4 additions & 1 deletion src/main/resources/addresources/values/strings.xml
Expand Up @@ -226,7 +226,7 @@
<string name="revanced_remove_viewer_discretion_dialog_summary_off">Dialog will be shown</string>
<string name="revanced_remove_viewer_discretion_dialog_user_dialog_message">This does not bypass the age restriction. It just accepts it automatically.</string>
</patch>
<patch id="interaction.downloads.ExternalDownloadsResourcePatch">
<patch id="interaction.downloads.DownloadsResourcePatch">
<string name="revanced_external_downloader_screen_title">External downloads</string>
<string name="revanced_external_downloader_screen_summary">Settings for using an external downloader</string>
<string name="revanced_external_downloader_title">Show external download button</string>
Expand All @@ -235,6 +235,9 @@
<string name="revanced_external_downloader_name_title">Downloader package name</string>
<string name="revanced_external_downloader_name_summary">Package name of your installed external downloader app, such as NewPipe or Seal</string>
<string name="revanced_external_downloader_not_installed_warning">%s is not installed. Please install it.</string>
<string name="revanced_use_in_app_download_button_title">Use in-app download button</string>
<string name="revanced_use_in_app_download_button_summary_on">Button will launch the external downloader</string>
<string name="revanced_use_in_app_download_button_summary_off">Button will launch the native in-app downloader</string>
</patch>
<patch id="interaction.seekbar.DisablePreciseSeekingGesturePatch">
<string name="revanced_disable_precise_seeking_gesture_title">Disable precise seeking gesture</string>
Expand Down

2 comments on commit d900011

@hassan1395
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the same features in yt music

@LisoUseInAIKyrios
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hassan1395 you are welcome to develop a similar patch for YT Music and create a pull request with the changes

Please sign in to comment.