From 7b21727285e50b0b050c4ddd70d07542229c5366 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:17:03 -0700 Subject: init --- python/ytdl/live.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 python/ytdl/live.py (limited to 'python/ytdl/live.py') diff --git a/python/ytdl/live.py b/python/ytdl/live.py new file mode 100644 index 0000000..eaa78cf --- /dev/null +++ b/python/ytdl/live.py @@ -0,0 +1,35 @@ +import yt_dlp +import subprocess + +def stream_video(url): + ydl_opts = { + 'format': 'bestvideo+bestaudio/best', + 'quiet': True, + 'no_warnings': True, + 'noplaylist': True, + 'forceurl': True, + 'skip_download': True, + } + + with yt_dlp.YoutubeDL(ydl_opts) as ydl: + try: + info = ydl.extract_info(url, download=False) + if 'url' in info: + video_url = info['url'] + else: + # For some videos (like YouTube), it's nested in 'formats' + formats = info.get('formats', []) + if formats: + video_url = formats[-1]['url'] + else: + print("Could not extract video URL.") + return + + print("Streaming to mpv...") + subprocess.run(['mpv', video_url]) + except Exception as e: + print(f"An error occurred: {e}") + +# Example usage +video_url = input("Video URL: ") +stream_video(video_url) -- cgit v1.2.3