mirror of
https://github.com/revanced/revanced-integrations
synced 2024-11-24 20:07:14 +01:00
feat(YouTube - Downloads): Use external downloader when selecting 'Download' in home feed flyout menu (#587)
fix(YouTube - Downloads): Use external downloader when selecting 'Download' from home feed flyout menu
This commit is contained in:
parent
7c40c947ef
commit
254da31d16
@ -6,14 +6,13 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Objects;
|
||||
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.StringRef;
|
||||
import app.revanced.integrations.shared.Utils;
|
||||
import app.revanced.integrations.youtube.patches.spoof.SpoofAppVersionPatch;
|
||||
import app.revanced.integrations.youtube.settings.Settings;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -31,25 +30,13 @@ public final class DownloadsPatch {
|
||||
/**
|
||||
* Injection point.
|
||||
*
|
||||
* Call if download playlist is pressed, or if download button is used
|
||||
* for old spoofed version (both playlists and the player action button).
|
||||
* Called from the in app download hook,
|
||||
* for both the player action button (below the video)
|
||||
* and the 'Download video' flyout option for feed videos.
|
||||
*
|
||||
* Downloading playlists is not supported yet,
|
||||
* as the hooked code does not easily expose the playlist id.
|
||||
* Appears to always be called from the main thread.
|
||||
*/
|
||||
public static boolean inAppDownloadPlaylistLegacyOnClick(@Nullable String videoId) {
|
||||
if (videoId == null || videoId.isEmpty()) {
|
||||
// videoId is null or empty if download playlist is pressed.
|
||||
Logger.printDebug(() -> "Ignoring playlist download button press");
|
||||
return false;
|
||||
}
|
||||
return inAppDownloadButtonOnClick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static boolean inAppDownloadButtonOnClick() {
|
||||
public static boolean inAppDownloadButtonOnClick(@NonNull String videoId) {
|
||||
try {
|
||||
if (!Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get()) {
|
||||
return false;
|
||||
@ -65,7 +52,7 @@ public final class DownloadsPatch {
|
||||
isActivityContext = false;
|
||||
}
|
||||
|
||||
launchExternalDownloader(context, isActivityContext);
|
||||
launchExternalDownloader(videoId, context, isActivityContext);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "inAppDownloadButtonOnClick failure", ex);
|
||||
@ -77,29 +64,29 @@ public final class DownloadsPatch {
|
||||
* @param isActivityContext If the context parameter is for an Activity. If this is false, then
|
||||
* the downloader is opened as a new task (which forces YT to minimize).
|
||||
*/
|
||||
public static void launchExternalDownloader(@NonNull Context context, boolean isActivityContext) {
|
||||
Logger.printDebug(() -> "Launching external downloader with context: " + context);
|
||||
|
||||
// Trim string to avoid any accidental whitespace.
|
||||
var downloaderPackageName = Settings.EXTERNAL_DOWNLOADER_PACKAGE_NAME.get().trim();
|
||||
|
||||
boolean packageEnabled = false;
|
||||
public static void launchExternalDownloader(@NonNull String videoId,
|
||||
@NonNull Context context, boolean isActivityContext) {
|
||||
try {
|
||||
packageEnabled = context.getPackageManager().getApplicationInfo(downloaderPackageName, 0).enabled;
|
||||
} catch (PackageManager.NameNotFoundException error) {
|
||||
Logger.printDebug(() -> "External downloader could not be found: " + error);
|
||||
}
|
||||
Objects.requireNonNull(videoId);
|
||||
Logger.printDebug(() -> "Launching external downloader with context: " + context);
|
||||
|
||||
// If the package is not installed, show the toast
|
||||
if (!packageEnabled) {
|
||||
Utils.showToastLong(StringRef.str("revanced_external_downloader_not_installed_warning", downloaderPackageName));
|
||||
return;
|
||||
}
|
||||
// Trim string to avoid any accidental whitespace.
|
||||
var downloaderPackageName = Settings.EXTERNAL_DOWNLOADER_PACKAGE_NAME.get().trim();
|
||||
|
||||
// Launch intent
|
||||
try {
|
||||
String content = String.format("https://youtu.be/%s", VideoInformation.getVideoId());
|
||||
boolean packageEnabled = false;
|
||||
try {
|
||||
packageEnabled = context.getPackageManager().getApplicationInfo(downloaderPackageName, 0).enabled;
|
||||
} catch (PackageManager.NameNotFoundException error) {
|
||||
Logger.printDebug(() -> "External downloader could not be found: " + error);
|
||||
}
|
||||
|
||||
// If the package is not installed, show the toast
|
||||
if (!packageEnabled) {
|
||||
Utils.showToastLong(StringRef.str("revanced_external_downloader_not_installed_warning", downloaderPackageName));
|
||||
return;
|
||||
}
|
||||
|
||||
String content = "https://youtu.be/" + videoId;
|
||||
Intent intent = new Intent("android.intent.action.SEND");
|
||||
intent.setType("text/plain");
|
||||
intent.setPackage(downloaderPackageName);
|
||||
@ -109,8 +96,8 @@ public final class DownloadsPatch {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
} catch (Exception error) {
|
||||
Logger.printException(() -> "Failed to launch intent: " + error, error);
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "launchExternalDownloader failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.youtube.patches.DownloadsPatch;
|
||||
import app.revanced.integrations.youtube.patches.VideoInformation;
|
||||
import app.revanced.integrations.youtube.settings.Settings;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -43,7 +44,10 @@ public class ExternalDownloadButton extends BottomControlButton {
|
||||
}
|
||||
|
||||
private static void onDownloadClick(View view) {
|
||||
DownloadsPatch.launchExternalDownloader(view.getContext(), true);
|
||||
DownloadsPatch.launchExternalDownloader(
|
||||
VideoInformation.getVideoId(),
|
||||
view.getContext(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user