Automatic stream capture script not detecting live broadcasts

I’m working on a Python script in my IDE that should automatically capture streams when a specific broadcaster goes live. The script keeps showing that the stream is offline even when I can see the person is actually streaming.

Here’s my current approach:

import subprocess
import json
import time
import os

broadcaster = "example_user"
video_quality = "720p"
output_directory = "D:/recordings/streams"

if not os.path.exists(output_directory):
    os.makedirs(output_directory)

while True:
    try:
        result = subprocess.check_output(["streamlink", "--json", f"https://www.twitch.tv/{broadcaster}", video_quality])
        data = json.loads(result.decode("utf-8"))
        stream_link = data["streams"][video_quality]["url"]
        timestamp = time.strftime('%Y%m%d_%H%M%S')
        filename = f"{broadcaster}_{timestamp}.mp4"
        full_path = os.path.join(output_directory, filename)
        print("Found active stream, beginning capture...")
        subprocess.call(["streamlink", stream_link, video_quality, "-o", full_path])
    except:
        print("No active stream found, waiting 60 seconds...")
        time.sleep(60)

The output constantly shows “No active stream found” even during confirmed live broadcasts. I’ve tried reinstalling Python and all dependencies but the issue persists. Any ideas what might be causing this detection problem?

you’re mixing up the streamlink syntax. don’t extract the json stream url - just pass the twitch url directly. that bare except is hiding the real error messages too. add print(e) in your except block to see what’s actually failing first.

This is probably an authentication issue, not your code. Twitch has been cracking down on API access lately - lots of streams need proper auth tokens now to check if they’re live. I ran into the same thing with my monitoring script until I figured out streamlink wasn’t getting channel access. First, update streamlink to the latest version. Then set up auth by running streamlink --twitch-oauth-authenticate to grab a token. Also, ditch that bare except clause and catch the specific exception instead - print the actual error so you can see what streamlink’s complaining about. In my experience, about 70% of these detection problems are auth-related, not coding issues.

hey, it sounds like ur having a tough time! try running streamlink --json https://www.twitch.tv/example_user first to see if it detects the channel at all. if that works, then use streamlink https://www.twitch.tv/example_user 720p -o filename.mp4 to get the stream.

Your streamlink command structure is the problem. You’re passing the extracted stream URL directly to streamlink in the second call, but streamlink needs the original Twitch URL format. When you grab the stream link from the JSON output, you get a raw video URL that streamlink can’t handle. I ran into this exact issue building my own capture system. Don’t extract the stream URL and pass it back - just use the original Twitch URL throughout. Replace your subprocess.call line with:

subprocess.call(["streamlink", f"https://www.twitch.tv/{broadcaster}", video_quality, "-o", full_path])

Throw in --retry-streams and --retry-max parameters too - they’ll handle connection hiccups during long streams. This approach has worked solid for my automated recording setup.

Had this exact problem six months ago - drove me crazy for days. You’re probably hitting Twitch’s rate limits with how you’ve set up the detection loop. Running streamlink every 60 seconds triggers their anti-bot stuff, especially without proper delays. Bump your sleep interval to at least 300 seconds and add random delay variation so requests aren’t perfectly timed. Also try the --twitch-disable-ads flag - sometimes helps with detection. What really fixed it for me: check the Twitch API directly for stream status first, then only call streamlink when the API confirms it’s live. Way less load on streamlink and much more reliable detection. Also make sure your streamlink version supports the newer OAuth flow - older versions are garbage with recent Twitch changes.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.