1

I run the following command in a linux terminal:

vlc http://streamx/live/....stream/playlist.m3u8 --rate=1 --video-filter=scene --vout=dummy --run-time=3 --scene-format=png --scene-ratio=24 --scene-path=/home/pi/Desktop vlc://quit

If the url is okay, it makes some pictures from streams. I would like to know if the command ran successfully or not.

if the url is not correct is writes out:

[73b00508] core input error: open of 'http://streamx/live/....stream/playlist.m3u8' failed
[73b00508] core input error: Your input can't be opened
[73b00508] core input error: VLC is unable to open the MRL 'http://streamx/live/....stream/playlist.m3u8'. Check the log for details.

if the url is correct is writes out:

[73b03f20] httplive stream: HTTP Live Streaming (streamx/live/....stream/playlist.m3u8)

How can I get after running the command (for example in a python script) if the url was okay or not?

Thanks in advance!

1
  • Use something like wget to check that you get a valid response (ie. not 500 or 404 etc) and that the response encoding is of the type you want before actually opening VLC. Commented Sep 13, 2017 at 18:44

1 Answer 1

2

We need to check two things.

  • 1) If the URL itself is alive
  • 2) If the URL is alive, is the data streaming (you may have broken link).

1) To check if URL is alive. We can check status code. Anything 2xx or 3xx is good (you can tailor this to your needs).

import urllib
url = 'http://aska.ru-hoster.com:8053/autodj'

code = urllib.urlopen(url).getcode()
 if str(code).startswith('2') or str(code).startswith('3') :
    print 'Stream is working'
else:
    print 'Stream is dead'

2) Now we have good URL , but we need to check if we have streaming and link is not dead.
Using VLC, we can connect to site, try to play the media at the link and then check for errors.

Here is a working example that I have from my other posting.

import vlc
import time

url = 'http://aska.ru-hoster.com:8053/autodj'
#define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')

#Define VLC player
player=instance.media_player_new()

#Define VLC media
media=instance.media_new(url)

#Set player media
player.set_media(media)

#Play the media
player.play()


#Sleep for 5 sec for VLC to complete retries.
time.sleep(5)
#Get current state.
state = str(player.get_state())

#Find out if stream is working.
if state == "vlc.State.Error" or state == "State.Error":
    print 'Stream is dead. Current state = {}'.format(state)
    player.stop()
else:
    print 'Stream is working. Current state = {}'.format(state)
    player.stop()
Sign up to request clarification or add additional context in comments.

13 Comments

Thanks for the quick answer, i'll definetly check this out!
Let me know if it works out. If it does, do consider up-voting and accepting answer to close the loop. If not let me know issues so that I can revisit problem.
1) is working in python 2, but when I try in python 3: import urllib.request with urllib.request.urlopen(url) as url: s = url.read() the shell writes out nothing. Could you include a python 3 solution? Thanks
For python3, add import urllib.request and change code= with code = urllib.request.urlopen(url).getcode() see if it works.
working stream is okay, but I get urllib.error.HTTPError: HTTP Error 404: Not Found when stream is down
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.