I'm working on a program that manages and downloads multiple twitch.tv streams using the streamlink CLI. For the sake of simplicity, let's just focus in one right now.
I want to use the subprocess.Popen() to give a command to start recording a twitch stream and capture it's continous output. I want this way because I want to extract useful information like the current file size and download speed every second. I guess I'm running into a problem because the streamlink CLI uses \r to modify the text in place. Here's my current solution:
import subprocess
import time
cmd = 'streamlink twitch.tv/pokimane best -o C:/Users/username/Desktop/poki.mp4'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
while True:
print(proc.stdout.readline())
time.sleep(1)
My output is like:
[cli][info] Found matching plugin twitch for URL twitch.tv/pokimane
[cli][info] Available streams: audio_only, 160p (worst), 360p, 480p, 720p60, 1080p60 (best)
[cli][info] Opening stream: 1080p60 (hls)
[cli][info] Writing output to
C:\Users\username\Desktop\poki.mp4
As you can see, I don't get the information about the download I want. I have read several articles and similar questions here as well, but none of them helped me. I also need a way to know when this process finishes to handle each case (streamer offline, stream ended, no internet connection, etc).
Thanks so much for your attention. :)