How? Check stream connection in script

Just curious if anybody knows how to check the connection of a video stream using a CLI/script.

The idea is just to check if a channel is working without doing it manually.

One thought I had was to create a custom recording on the channel for 30s and then check if the recording succeeded. And then have to make sure to delete the recording. That doesn't seem to be very efficient.

Ideally, it would be as simple as opening the stream to the channel and make sure it succeeds. I just don't know how to do it.

I checked the web inspector when I played a live stream in the browser, and then I tried to send the same request from a terminal. Got a 404 response. So that doesn't work.

I'm sure the developers know the best answer. :grin:

/devices/ANY/channels/####/stream.mpg

Fill in the channel number you want to check, and you'll get a stream. (Obviously you need to prepend your server IP:PORT.)

Thank you. What command should I call with this URL (in my script)?

Edit: I have a piece of code suggested by AI that I will try.

Will this command keep streaming until stopped? I too am interested in something like this.

Edit tested keeps streaming.

Great question! I didn't even think of that.

I modified my prompt to the AI to make sure the stream stops after my test.

I don't have time to try it yet. I will let you know what results I get.

Ultimately, if I get it to work for one, my end goal is to create a TVE checker that will report when it finds broken streams.

If you want to give it a try, here is the suggested Python code by the AI:

import requests

def test_video_stream(url):
    try:
        with requests.get(url, stream=True, timeout=10) as response:
            if response.status_code == 200:
                print("The video stream is working!")
                # Read a chunk of the stream to verify it's working
                for chunk in response.iter_content(chunk_size=1024):
                    if chunk:
                        print("Received a chunk of data.")
                        break
            else:
                print("The video stream is not working. Status code:", response.status_code)
    except requests.exceptions.RequestException as e:
        print("An error occurred:", e)

# Example usage
stream_url = "http://your-stream-url/stream.mpg"
test_video_stream(stream_url)
2 Likes

I just gave it a try with channel 5985 and it seems that it worked. :slight_smile:

C:\Users\mjitk\Documents\Scripts\TVE Checker>python cdvr_tve_checker.py
The video stream is working!
Received a chunk of data.

Channels log:

2025/01/31 16:23:24.043606 [TVE] stream timestamps: abc-wabc: start_at=2025-01-31T16:22:54-05:00 end_at=2025-01-31T16:23:00-05:00 live_delay=21.3326065s
2025/01/31 16:23:24.043606 [TNR] Opened connection to TVE-DTV for ch5985 WABC
2025/01/31 16:23:24.953029 [SNR] Rewriter statistics for 127.0.0.1 (127.0.0.1) for ch5985 WABC: discontinuity_detected=0 transport_errors=0 saw_pcr=false saw_pmt=true highest_pts=0.055478
2025/01/31 16:23:24.953029 [SNR] Buffer statistics for 127.0.0.1 (127.0.0.1) for ch5985 WABC: buf=0% drop=0%
2025/01/31 16:23:24.953589 [SNR] Streaming statistics for 127.0.0.1 (127.0.0.1) for ch5985 WABC: timeouts=0 segment_timeouts=0 playlist_timeouts=0
2025/01/31 16:23:24.954206 [TNR] Closed connection to TVE-DTV for ch5985 WABC

I just tried with the channel TBD and it failed as reported in another thread:

C:\Users\mjitk\Documents\Scripts\TVE Checker>python cdvr_tve_checker.py
The video stream is working!
An error occurred: HTTPConnectionPool(host='127.0.0.1', port=8089): Read timed out.

Need to tweak the script a bit because The video stream is working! is misleading.

Channels log:

2025/01/31 16:28:58.311191 [TVE] stream timestamps: tbd: start_at=2025-01-31T16:27:58-05:00 end_at=2025-01-31T16:28:27-05:00 live_delay=26.7231915s
2025/01/31 16:28:58.311988 [TNR] Opened connection to TVE-DTV for ch6755 TBD
2025/01/31 16:29:22.436516 [SNR] Buffer statistics for 127.0.0.1 (127.0.0.1) for ch6755 TBD: buf=0% drop=0%
2025/01/31 16:29:22.437019 [SNR] Streaming statistics for 127.0.0.1 (127.0.0.1) for ch6755 TBD: timeouts=0 segment_timeouts=0 playlist_timeouts=0
2025/01/31 16:29:22.437590 [TNR] Closed connection to TVE-DTV for ch6755 TBD
2025/01/31 16:29:22.437590 [TNR] Error during live stream for ch6755 TBD: Failed to download segment 5: http://cf.cdn.uplynk.com/ausw2/slices/2d0/34d28c6069b34f1d96307c80809697d7/2d0eb082ba9549a9a931d29c6808e286/G00000005.ts?pbs=8ceaa4a98a9148cf941d9083b73f5c0b&_jt=l&chid=1831163f97674328ad9f4b4814ed39c5&cloud=aws&cdn=cfi&si=0: GET: https://content-ausw2-up-1.uplynk.com/check2?b=2d0eb082ba9549a9a931d29c6808e286&v=1831163f97674328ad9f4b4814ed39c5&r=g&c=1831163f97674328ad9f4b4814ed39c5&pbs=8ceaa4a98a9148cf941d9083b73f5c0b: 403 Forbidden

That's interesting. In the process of testing this script, I got this for CONTV:

C:\Users\mjitk\Documents\Scripts\TVE Checker>python cdvr_tve_checker.py
The video stream is not working. Status code: 503

Channels log:

2025/01/31 16:44:27.259442 [ERR] Could not start stream for ANY ch6753 CONTV: TVE: Could not fetch playlist from contvanime.cinedigm.com: Get "https://contvanime.cinedigm.com/conapp-ssai/amagi_hls_data_xumo-host-contvanime-junction/CDN/playlist.m3u8": dial tcp: lookup contvanime.cinedigm.com: no such host

So it seems that this script will have some value. :slight_smile:

I will report the issue.

Thanks to @racameron who provided a crucial part of the solution, and also thank you to @Edwin_Perez for making sure the stream gets closed.

Add to this some help from AI, and my question has been answered.

Final solution: