Make wget percentage detection more robust

This commit is contained in:
Robin Kluth
2023-03-30 17:09:49 +02:00
parent 94d1952c5e
commit 63cef77e29

View File

@@ -238,9 +238,9 @@ function download($url, $name, &$error, $write=true) {
if ($file = popen("wget --compression=auto --no-cache --progress=dot --retry-connrefused --prefer-family=IPv4 --timeout=10 --tries=$tries --waitretry=$tries -O $name $url 2>&1", 'r')) {
if ($write) write("plugin: downloading: $plg ...\r");
$level = -1;
while (($line = fgets($file)) !== false) {
if (preg_match('/\d+%/', $line, $matches)) {
$percentage = substr($matches[0],0,-1);
while (($line = fgets($file)) !== false) {
if (preg_match('/ \d+% /', $line, $matches)) {
$percentage = substr(trim($matches[0]),0,-1);
if ($percentage > $level) {
if ($write) write("plugin: downloading: $plg ... $percentage%\r");
$level = $percentage;