Is there a way to download a YouTube live stream as it's happening in real-time in Python?
My best guess would be to use Pafy. For example,
import pafy
url = "https://www.youtube.com/watch?v=_9OBhtLA9Ig"
video = pafy.new(url)
best = video.getbest(preftype="mp4")
However, I'm not sure if this works for live streams and how to download frames in real-time.
Or maybe using vidgear
:
from vidgear.gears import CamGear
stream = CamGear(source='https://youtu.be/dQw4w9WgXcQ', stream_mode = True, logging=True).start()
while True:
frame = stream.read()
I'm also not sure if that works in real-time.
These code examples are borrowed from a related question: How to read Youtube live stream using openCV python?
I'd like to be able to process the frames in a while loop kind of like this:
while True:
# The current frame in real-time
frame = get_frame()