Possibly optimise download speed by rate-limiting update messages?
This commit is contained in:
parent
268af0ff3f
commit
c2c748470f
|
@ -437,6 +437,9 @@ public final class Chords extends ListenerAdapter
|
||||||
|
|
||||||
private static final String PROGRESS_SYMBOLS = " ▏▎▍▌▋▊▉█";
|
private static final String PROGRESS_SYMBOLS = " ▏▎▍▌▋▊▉█";
|
||||||
|
|
||||||
|
private double lastProgressUpdate = 0.0;
|
||||||
|
private boolean initialUpdateSent = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
⠀⡀⣀⣠⣤⣦⣶⣾⣿
|
⠀⡀⣀⣠⣤⣦⣶⣾⣿
|
||||||
🌑🌘🌗🌖🌕
|
🌑🌘🌗🌖🌕
|
||||||
|
@ -455,6 +458,7 @@ public final class Chords extends ListenerAdapter
|
||||||
@Override
|
@Override
|
||||||
public void accept(TrackRequest request, Exception ex)
|
public void accept(TrackRequest request, Exception ex)
|
||||||
{
|
{
|
||||||
|
boolean shouldUpdate = false;
|
||||||
String response = "";
|
String response = "";
|
||||||
if (request.getTracks().size() > 1)
|
if (request.getTracks().size() > 1)
|
||||||
response += "Downloading " + request.getTracks().size() + " tracks:\n";
|
response += "Downloading " + request.getTracks().size() + " tracks:\n";
|
||||||
|
@ -467,6 +471,7 @@ public final class Chords extends ListenerAdapter
|
||||||
{
|
{
|
||||||
response += ("Finished downloading " + track + "!");
|
response += ("Finished downloading " + track + "!");
|
||||||
log("DOWN", "Downloaded " + track);
|
log("DOWN", "Downloaded " + track);
|
||||||
|
shouldUpdate = true;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Format format = track.getBestFormat();
|
Format format = track.getBestFormat();
|
||||||
|
@ -482,7 +487,14 @@ public final class Chords extends ListenerAdapter
|
||||||
|
|
||||||
String progressDetails = "";
|
String progressDetails = "";
|
||||||
if (track.getProgress() >= 0)
|
if (track.getProgress() >= 0)
|
||||||
|
{
|
||||||
|
if (track.getProgress() >= lastProgressUpdate + 10.0)
|
||||||
|
{
|
||||||
|
shouldUpdate = true;
|
||||||
|
lastProgressUpdate = track.getProgress();
|
||||||
|
}
|
||||||
progressDetails = " [" + String.format("%.1f", track.getProgress()) + "%]";
|
progressDetails = " [" + String.format("%.1f", track.getProgress()) + "%]";
|
||||||
|
}
|
||||||
|
|
||||||
response += ("Now downloading " + track + formatDetails + progressDetails + " ...");
|
response += ("Now downloading " + track + formatDetails + progressDetails + " ...");
|
||||||
log("DOWN", "Downloading " + track + "...");
|
log("DOWN", "Downloading " + track + "...");
|
||||||
|
@ -491,11 +503,15 @@ public final class Chords extends ListenerAdapter
|
||||||
{
|
{
|
||||||
response += ("Failed to download " + track + "! Reason: " + ex.getMessage());
|
response += ("Failed to download " + track + "! Reason: " + ex.getMessage());
|
||||||
log("DOWN", "Failed to download " + track + "! Reason: " + ex.getMessage());
|
log("DOWN", "Failed to download " + track + "! Reason: " + ex.getMessage());
|
||||||
|
shouldUpdate = true;
|
||||||
}
|
}
|
||||||
response += "\n";
|
response += "\n";
|
||||||
}
|
}
|
||||||
if (!response.isEmpty())
|
if (!response.isEmpty() && (shouldUpdate || initialUpdateSent))
|
||||||
|
{
|
||||||
request.getInvocation().respond(response);
|
request.getInvocation().respond(response);
|
||||||
|
initialUpdateSent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue