Skip to content

Commit

Permalink
add "ask" option to PlayListOption
Browse files Browse the repository at this point in the history
  • Loading branch information
awidesky committed May 5, 2021
1 parent 9f58085 commit f428e76
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/com/awidesky/YoutubeClipboardAutoDownloader/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ public static synchronized void setQuality(String quality) {

}


public static PlayListOption getPlaylistOption() {

return playlistOption;

}

public static synchronized void setPlaylistOption(String playlist) {
Expand Down
14 changes: 10 additions & 4 deletions src/com/awidesky/YoutubeClipboardAutoDownloader/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static void checkClipBoard() {

SwingUtilities.invokeLater(() -> {

if (!GUI.confirm("Download link in clipboard?", "Download link : " + data)) {
if (!GUI.confirm("Download link in clipboard?", "Link : " + data)) {

Main.log("\n[GUI.linkAcceptChoose] Download link " + data + "? : " + false + "\n");

Expand Down Expand Up @@ -199,14 +199,20 @@ private static void submitDownload(String data) {
TaskStatusModel.getinstance().addTask(t);

String url = "\"" + data + "\"";

if (YoutubeAudioDownloader.validateAndSetName(url, t)) {

PlayListOption p = Config.getPlaylistOption();

if (p == PlayListOption.ASK) {
p = (GUI.confirm("Download entire Playlist?", "Link : " + url)) ? PlayListOption.YES : PlayListOption.NO;
}

if (YoutubeAudioDownloader.validateAndSetName(url, t, p)) {

t.setStatus("Preparing...");

try {

YoutubeAudioDownloader.download(url, t);
YoutubeAudioDownloader.download(url, t, p);

} catch (Exception e1) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public enum PlayListOption {

YES("yes", "--yes-playlist"),
NO("no", "--no-playlist");

NO("no", "--no-playlist"),
ASK("ask", null);

private String toComboBox;
private String toCommandArgm;
Expand Down Expand Up @@ -33,6 +33,9 @@ public static PlayListOption get(String s) {
case "no":
case "--no-playlist":
return NO;

case "ask":
return ASK;

default:
throw new RuntimeException("Invalid parameter : PlayListOption.get(" + s + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static String getProjectpath() {
}


public static void download(String url, TaskData task) throws Exception {
public static void download(String url, TaskData task, PlayListOption playListOption) throws Exception {

Main.log("\n"); Main.log("\n");
Main.logProperties("[Task" + task.getTaskNum() + "|preparing] " + "Current");
Expand All @@ -148,7 +148,7 @@ public static void download(String url, TaskData task) throws Exception {
Main.log("\n");
long startTime = System.nanoTime();
ProcessBuilder pb = new ProcessBuilder(youtubedlpath + "youtube-dl" + options, "--newline",
"--extract-audio", Config.getPlaylistOption().toCommandArgm(), "--audio-format",
"--extract-audio", playListOption.toCommandArgm(), "--audio-format",
Config.getFormat(), "--output", "\"" + Config.getFileNameFormat() + "\"", "--audio-quality",
Config.getQuality(), url);

Expand Down Expand Up @@ -230,14 +230,15 @@ public static void download(String url, TaskData task) throws Exception {
}

/** get video name
* @param p
* @throws Exception */
public static boolean validateAndSetName(String url, TaskData task) {
public static boolean validateAndSetName(String url, TaskData task, PlayListOption p) {

try {
Main.log("\n");
long startTime = System.nanoTime();
ProcessBuilder pbGetName = new ProcessBuilder(youtubedlpath + "youtube-dl", "--get-filename",
Config.getPlaylistOption().toCommandArgm(), "-o", Config.getFileNameFormat().replace("%(ext)s", Config.getFormat()), url);
p.toCommandArgm(), "-o", Config.getFileNameFormat().replace("%(ext)s", Config.getFormat()), url);

// retrieve command line argument
Main.log("[Task" + task.getTaskNum() + "|validating] " + "Getting video name by \"" + pbGetName.command().stream().collect(Collectors.joining(" ")) + "\"");
Expand All @@ -250,7 +251,7 @@ public static boolean validateAndSetName(String url, TaskData task) {

if ((name.contains("WARNING")) || (name.contains("ERROR")) || (p1.waitFor() != 0)) return false;

if (Config.getPlaylistOption() == PlayListOption.YES) {
if (p == PlayListOption.YES) {

name += " ¹× Ç÷¹À̸®½ºÆ® Àüü";
task.setVideoName(name);
Expand All @@ -265,7 +266,7 @@ public static boolean validateAndSetName(String url, TaskData task) {
Main.log("[Task" + task.getTaskNum() + "|validating] " + "Ended with exit code : " + p1.waitFor());

try {
br1.close();
if (br1 != null) br1.close();
} catch (IOException i) {
GUI.error("[Task" + task.getTaskNum() + "|validating] " + "Error when closing process stream", "%e%", i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void addComboBoxes() {

cb_format = new JComboBox<>(new String[] { "mp3", "best", "aac", "flac", "m4a", "opus", "vorbis", "wav" });
cb_quality = new JComboBox<>(new String[] { "0(best)", "1", "2", "3", "4", "5", "6", "7", "8", "9(worst)" });
cb_playList = new JComboBox<>(new String[] { "yes", "no" });
cb_playList = new JComboBox<>(new String[] { "yes", "no", "ask" });
cb_clipboardOption = new JComboBox<>(new String[] { "Download link automatically",
"Ask when a link is found",
"Stop listening clipboard" });
Expand Down

0 comments on commit f428e76

Please sign in to comment.