each_line('fifo', function ($line) { // usleep(50000); if (empty($line)) { send('comment', compact('line')); return; } // preparing if (preg_match('/\\[download\\] Resuming download at byte (\\d+)/', $line, $m)) { $offset = $m[1]; send('prepare', compact('line', 'offset')); return; } // preparing if (preg_match('/\\[youtube\\] (.*)/', $line, $m)) { $message = $m[1]; send('prepare', compact('line', 'message')); return; } // preparing if (preg_match('/\\[download\\] Destination: (.*)/', $line, $m)) { $file = $m[1]; send('prepare', compact('line', 'file')); return; } // finishing if (preg_match('/\\[youtube\\] Post-process file (.*)/', $line, $m)) { $file = $m[1]; send('finish', compact('line', 'file')); return; } // progress if (preg_match(preg_from_blankee('[download] :: of :: at :: ETA ::'), $line, $m)) { list(, $done, $size, $speed, $eta) = $m; send('progress', compact('line', 'done', 'eta', 'speed', 'size')); return; } // complete if (preg_match(preg_from_blankee('[download] :: of :: in ::'), $line, $m)) { list(, , $size, $time) = $m; send('complete', compact('line', 'size', 'time')); return; } // error if (preg_match('/ERROR: (.*)/', $line, $m)) { $message = $m[1]; send('error', compact('line', 'message')); return; } // everything else send('unexpected', compact('line')); });
each_line('fifo', function ($line) { if (empty($line)) { return; } // preparing if (preg_match('/\\[download\\] Resuming download at byte (\\d+)/', $line, $m)) { $offset = $m[1]; echo "preparing: resume={$offset}", PHP_EOL; return; } // preparing if (preg_match('/\\[youtube\\] (.*)/', $line, $m)) { $message = $m[1]; echo "preparing: {$message}", PHP_EOL; return; } // preparing if (preg_match('/\\[download\\] Destination: (.*)/', $line, $m)) { $file = $m[1]; echo "preparing: destination={$file}", PHP_EOL; return; } // finishing if (preg_match('/\\[youtube\\] Post-process file (.*)/', $line, $m)) { $file = $m[1]; echo "finishing: {$file}", PHP_EOL; return; } // progress if (preg_match(preg_from_blankee('[download] :: of :: at :: ETA ::'), $line, $m)) { list(, $done, $size, $speed, $eta) = $m; echo "progress: done={$done}, eta={$eta}, speed={$speed}", PHP_EOL; return; } // complete if (preg_match(preg_from_blankee('[download] :: of :: in ::'), $line, $m)) { list(, $done, $size, $time) = $m; echo "complete: size={$size}, time={$time}", PHP_EOL; return; } // error if (preg_match('/ERROR: (.*)/', $line, $m)) { $message = $m[1]; echo "error: {$message}", PHP_EOL; return; } // everything else echo '>>> unexpected: ', strlen($line), PHP_EOL, $line, PHP_EOL; });