feat: add output path

console keys: -o or --output

specify absolute or relative save path when adding a new video URL
master
kharon-nd 2020-03-24 01:28:10 +03:00
parent 9a6e6847c2
commit 0bad80cb03
3 changed files with 71 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.PasswordAuthentication;
import java.nio.file.Paths;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -156,6 +157,9 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
} else if ("-s".equals(args[i])) {
key = "screen";
expect = true;
} else if ("-o".equals(args[i]) || "--output".equals(args[i])) {
key = "output";
expect = true;
}
}
@ -408,16 +412,45 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (metadata != null
&& Config.getInstance().isDownloadAutoStart()) {
String fileName = file;
if (StringUtils.isNullOrEmptyOrBlank(file)) {
String fileName;
String folderPath;
if (StringUtils.isNullOrEmptyOrBlank(file)) {
if(metadata != null) {
fileName = XDMUtils.getFileName(metadata.getUrl());
} else {
fileName = null;
}
createDownload(fileName, null, metadata, true, "", 0, 0);
folderPath = null;
}
else {
var path = Paths.get(file);
fileName = path.getFileName().toString();
var parentPath = path.getParent();
if(parentPath.isAbsolute()) {
folderPath = parentPath.toString();
} else {
String downloadFolderPath;
if (Config.getInstance().isForceSingleFolder()) {
downloadFolderPath = Config.getInstance().getDownloadFolder();
} else {
var category = XDMUtils.findCategory(file);
downloadFolderPath = XDMApp.getInstance().getFolder(category);
}
folderPath = Paths.get(downloadFolderPath, parentPath.toString()).toString();
}
}
if (metadata != null
&& Config.getInstance().isDownloadAutoStart()) {
createDownload(fileName, folderPath, metadata, true, "", 0, 0);
return;
}
new NewDownloadWindow(metadata, file).setVisible(true);
new NewDownloadWindow(metadata, fileName, folderPath).setVisible(true);
}
});
}
@ -737,6 +770,10 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
return Config.getInstance().getDownloadFolder();
}
int category = ent.getCategory();
return this.getFolder(category);
}
public String getFolder(int category) {
switch (category) {
case XDMConstants.DOCUMENTS:
return Config.getInstance().getCategoryDocuments();

View File

@ -158,6 +158,10 @@ public class MonitoringSession implements Runnable {
XDMApp.getInstance().showMainWindow();
} else {
String[] arr = new String(data).split("\n");
String url = null;
String output = null;
for (int i = 0; i < arr.length; i++) {
String str = arr[i];
int index = str.indexOf(":");
@ -166,12 +170,25 @@ public class MonitoringSession implements Runnable {
String key = str.substring(0, index).trim();
String val = str.substring(index + 1).trim();
if (key.equals("url")) {
String url = val;
HttpMetadata metadata = new HttpMetadata();
metadata.setUrl(url);
String file = XDMUtils.getFileName(url);
XDMApp.getInstance().addDownload(metadata, file);
url = val;
}
if(key.equals("output")){
output = val;
}
}
if(url != null) {
var metadata = new HttpMetadata();
metadata.setUrl(url);
String file;
if(output != null) {
file = output;
} else {
file = XDMUtils.getFileName(url);
}
XDMApp.getInstance().addDownload(metadata, file);
}
}
setResponseOk(res);

View File

@ -52,7 +52,7 @@ public class NewDownloadWindow extends JDialog implements ActionListener, Docume
// private String folder;
private String queueId;
public NewDownloadWindow(HttpMetadata metadata, String file) {
public NewDownloadWindow(HttpMetadata metadata, String fileName, String folderPath) {
initUI();
// this.folder = Config.getInstance().getDownloadFolder();
this.metadata = metadata;
@ -71,8 +71,11 @@ public class NewDownloadWindow extends JDialog implements ActionListener, Docume
Logger.log(e);
}
}
if (file != null && file.length() > 0) {
filePane.setFileName(file);
if (!StringUtils.isNullOrEmptyOrBlank(fileName)) {
filePane.setFileName(fileName);
}
if (!StringUtils.isNullOrEmptyOrBlank(folderPath)) {
filePane.setFolder(folderPath);
}
getRootPane().setDefaultButton(btnDN);