Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bug fixes #165

Merged
merged 2 commits into from
Jul 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class StreamProcessExtractor extends Thread {
private final DownloadProgressCallback callback;

private final Pattern p = Pattern.compile("\\[download\\]\\s+(\\d+\\.\\d)% .* ETA (\\d+):(\\d+)");
private float progress = PERCENT;
private long eta = ETA;

public StreamProcessExtractor(StringBuffer buffer, InputStream stream, DownloadProgressCallback callback) {
this.stream = stream;
Expand Down Expand Up @@ -59,15 +61,15 @@ private void processOutputLine(String line) {
private float getProgress(String line) {
final Matcher matcher = p.matcher(line);
if (matcher.find())
return Float.parseFloat(matcher.group(GROUP_PERCENT));
return PERCENT;
return progress = Float.parseFloat(matcher.group(GROUP_PERCENT));
return progress;
}

private long getEta(String line) {
final Matcher matcher = p.matcher(line);
if (matcher.find())
return convertToSeconds(matcher.group(GROUP_MINUTES), matcher.group(GROUP_SECONDS));
return ETA;
return eta = convertToSeconds(matcher.group(GROUP_MINUTES), matcher.group(GROUP_SECONDS));
return eta;
}

private int convertToSeconds(String minutes, String seconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,15 @@ public YoutubeDLResponse execute(YoutubeDLRequest request) throws YoutubeDLExcep
return execute(request, null);
}

private boolean ignoreErrors(YoutubeDLRequest request, String out) {
return request.hasOption("--dump-json") && !out.isEmpty() && request.hasOption("--ignore-errors");
}

public YoutubeDLResponse execute(YoutubeDLRequest request, @Nullable DownloadProgressCallback callback) throws YoutubeDLException, InterruptedException {
assertInit();

// disable caching unless explicitly requested
if(request.getOption("--cache-dir") == null){
if(!request.hasOption("--cache-dir") || request.getOption("--cache-dir") == null){
request.addOption("--no-cache-dir");
}

Expand Down Expand Up @@ -197,7 +201,7 @@ public YoutubeDLResponse execute(YoutubeDLRequest request, @Nullable DownloadPro
String out = outBuffer.toString();
String err = errBuffer.toString();

if (exitCode > 0) {
if (exitCode > 0 && !ignoreErrors(request, out)) {
throw new YoutubeDLException(err);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public Object getOption(String key){
return options.get(key);
}

public boolean hasOption(String key){
return options.containsKey(key);
}

public List<String> buildOptions(){
List<String> optionsList = new ArrayList<>();
for (Map.Entry<String, String> entry : options.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public Object getOption(String key){
return options.getOption(key);
}

public boolean hasOption(String key){
return options.hasOption(key);
}

public List<String> buildCommand(){
List<String> command = new ArrayList<>();
command.addAll(options.buildOptions());
Expand Down