Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

feat(YouTube - Download Playlist Button): Add playlist download button #26

Merged
merged 11 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package app.revanced.integrations.youtube.patches.misc;

import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.utils.VideoUtils;

@SuppressWarnings("unused")
public class HookDownloadAction {

/*
* Injection point
*/
public static boolean isPlaylistDownloadButtonHooked() {
return Settings.HOOK_PLAYLIST_DOWNLOAD_BUTTON.get();
}

/*
* Injection point
*/
public static String startPlaylistDownloadActivity(String playlistId) {
if (!isPlaylistDownloadButtonHooked()) return playlistId;

VideoUtils.launchPlaylistExternalDownloader(playlistId);

// return an empty string to prevent
// the original implementation from being called
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting HIDE_GRAY_SEPARATOR = new BooleanSetting("revanced_hide_gray_separator", TRUE);
public static final BooleanSetting HIDE_SNACK_BAR = new BooleanSetting("revanced_hide_snack_bar", FALSE);
public static final BooleanSetting REMOVE_VIEWER_DISCRETION_DIALOG = new BooleanSetting("revanced_remove_viewer_discretion_dialog", FALSE);
public static final BooleanSetting HOOK_PLAYLIST_DOWNLOAD_BUTTON = new BooleanSetting("revanced_hook_playlist_download_button", TRUE);

public static final BooleanSetting ENABLE_PHONE_LAYOUT = new BooleanSetting("revanced_enable_phone_layout", FALSE, true);
public static final BooleanSetting ENABLE_TABLET_LAYOUT = new BooleanSetting("revanced_enable_tablet_layout", FALSE, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ public static boolean checkPackageIsEnabled() {
return checkPackageIsValid(context, packageName);
}

public static boolean checkPackageIsEnabled(String packageName) {
final Context context = Utils.getActivity();
mClickedDialogEntryIndex = Arrays.asList(mEntryValues).indexOf(packageName);
return checkPackageIsValid(context, packageName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static void launchExternalDownloader() {

public static void launchExternalDownloader(@NonNull String videoId) {
try {

String downloaderPackageName = externalDownloaderPackageName.get().trim();

if (downloaderPackageName.isEmpty()) {
Expand All @@ -121,7 +122,9 @@ public static void launchExternalDownloader(@NonNull String videoId) {
}

isExternalDownloaderLaunched.compareAndSet(false, true);

final String content = String.format("https://youtu.be/%s", videoId);

launchExternalDownloader(content, downloaderPackageName);
} catch (Exception ex) {
Logger.printException(() -> "launchExternalDownloader failure", ex);
Expand All @@ -130,6 +133,27 @@ public static void launchExternalDownloader(@NonNull String videoId) {
}
}

public static void launchPlaylistExternalDownloader(@NonNull String playlistId) {
try {
// use default downloader (YTDLnis) if user tries to download a playlist
// because most downloaders don't support playlist download
String downloaderPackageName = "com.deniscerri.ytdl";

final String content = String.format("https://www.youtube.com/playlist?list=%s", playlistId);

if (!checkPackageIsEnabled(downloaderPackageName)) {
return;
}

isExternalDownloaderLaunched.compareAndSet(false, true);
launchExternalDownloader(content, downloaderPackageName);
} catch (Exception ex) {
Logger.printException(() -> "launchPlaylistExternalDownloader failure", ex);
} finally {
runOnMainThreadDelayed(() -> isExternalDownloaderLaunched.compareAndSet(true, false), 500);
}
}

/**
* Create playlist from all channel videos from oldest to newest,
* starting from the video where button is clicked.
Expand Down
Loading