0

I use youtube-dl to download videos, through PHP CLI. In order to see the continous output, I have to use passthru() instead of the other functions, such as shell_exec(), and this works. It outputs something like:

[YouTube] ...
[download]  51.0% of 308.05MiB at 243.73KiB/s ETA 14:09

... where the last line keeps updating to reflect the current stats.

However, I'm trying to make a little nice feature where it shows the % in the process title. To do that, I need to be able to grab the "current last line" so that I can parse it out.

How do I do this? The manual for passthru() doesn't mention anything like a "callback function" that I can define to accomplish this.

I need PHP to call a function of my choosing each time the last line is updated/outputted (with the line sent as a string to it).

Note: I am aware of the "--console-title" flag for youtube-dl. While it technically "works", it "takes over" the entire process/window title with its own, quite ugly string which looks very jarring. I have a certain format and style for all my scripts' process/window titles, and need to keep that. For that reason, I need to be able to grab this data and process it in my own code. I can't just have youtube-dl set the title on its own. Also, this is not about youtube-dl anyway; it was just an example of the latest case where I need to be able to do this.

0 Answers0