Skip to content

Commit

Permalink
Merge pull request #130 from xibr/display-progress-line
Browse files Browse the repository at this point in the history
Display progress line
  • Loading branch information
xibr authored Feb 8, 2022
2 parents a83bde6 + 5a4d3e4 commit f13a29a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class CommandExampleActivity extends AppCompatActivity implements View.On
private ProgressBar pbLoading;

private boolean running = false;
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private final CompositeDisposable compositeDisposable = new CompositeDisposable();

private DownloadProgressCallback callback = new DownloadProgressCallback() {
private final DownloadProgressCallback callback = new DownloadProgressCallback() {
@Override
public void onProgressUpdate(float progress, long etaInSeconds) {
public void onProgressUpdate(float progress, long etaInSeconds, String line) {
runOnUiThread(() -> {
progressBar.setProgress((int) progress);
tvCommandStatus.setText(String.valueOf(progress) + "% (ETA " + String.valueOf(etaInSeconds) + " seconds)");
tvCommandStatus.setText(line);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class DownloadingExampleActivity extends AppCompatActivity implements Vie

private final DownloadProgressCallback callback = new DownloadProgressCallback() {
@Override
public void onProgressUpdate(float progress, long etaInSeconds) {
public void onProgressUpdate(float progress, long etaInSeconds, String line) {
runOnUiThread(() -> {
progressBar.setProgress((int) progress);
tvDownloadStatus.setText(String.valueOf(progress) + "% (ETA " + String.valueOf(etaInSeconds) + " seconds)");
tvDownloadStatus.setText(line);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_downloading_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="@string/start"
android:textSize="20sp"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="@+id/tv_command_scroller"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.yausername.youtubedl_android;

public interface DownloadProgressCallback {
void onProgressUpdate(float progress, long etaInSeconds);
void onProgressUpdate(float progress, long etaInSeconds, String line);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

class StreamGobbler extends Thread {

private InputStream stream;
private StringBuffer buffer;
private final InputStream stream;
private final StringBuffer buffer;

private static final String TAG = "StreamGobbler";

Expand All @@ -22,7 +23,7 @@ public StreamGobbler(StringBuffer buffer, InputStream stream) {

public void run() {
try {
Reader in = new InputStreamReader(stream, "UTF-8");
Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8);
int nextChar;
while ((nextChar = in.read()) != -1) {
this.buffer.append((char) nextChar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class StreamProcessExtractor extends Thread {
private static final int GROUP_PERCENT = 1;
private static final int GROUP_MINUTES = 2;
private static final int GROUP_SECONDS = 3;
private InputStream stream;
private StringBuffer buffer;
private final InputStream stream;
private final StringBuffer buffer;
private final DownloadProgressCallback callback;

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

private static final String TAG = "StreamProcessExtractor";

Expand All @@ -30,7 +31,7 @@ public StreamProcessExtractor(StringBuffer buffer, InputStream stream, DownloadP

public void run() {
try {
Reader in = new InputStreamReader(stream, "UTF-8");
Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8);
StringBuilder currentLine = new StringBuilder();
int nextChar;
while ((nextChar = in.read()) != -1) {
Expand All @@ -53,7 +54,7 @@ private void processOutputLine(String line) {
if (m.matches()) {
float progress = Float.parseFloat(m.group(GROUP_PERCENT));
long eta = convertToSeconds(m.group(GROUP_MINUTES), m.group(GROUP_SECONDS));
callback.onProgressUpdate(progress, eta);
callback.onProgressUpdate(progress, eta, line);
}
}

Expand Down
Binary file modified library/src/main/res/raw/yt_dlp.zip
Binary file not shown.

0 comments on commit f13a29a

Please sign in to comment.