Skip to content

Commit

Permalink
check_signal.py on way to replace generate.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsOps committed Feb 4, 2015
1 parent 263a176 commit c9c224a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
22 changes: 0 additions & 22 deletions check_signal.py

This file was deleted.

58 changes: 58 additions & 0 deletions tools/preview/check_signal.py
@@ -0,0 +1,58 @@
import os
import errno
import requests
import shutil
import config
from gi.repository import Gst

Gst.init(None)

loaded_config = config.config_load()
channels = loaded_config.groups()


def generate_thumb(channel, url):
pipeline = "uridecodebin uri=%s \
! videoconvert \
! videoscale \
! video/x-raw,width=300,height=217 \
! pngenc snapshot=true \
! filesink location=/srv/%s/snapshot.png" % (url, channel)

pipeline = Gst.parse_launch(pipeline)
bus = pipeline.get_bus()
pipeline.set_state(Gst.State.PLAYING)
bus.poll(Gst.MessageType.EOS, Gst.CLOCK_TIME_NONE)
pipeline.set_state(Gst.State.NULL)
print "%s snapshot generated" % channel

for channel in channels:
try:
os.makedirs("/srv/%s" % channel)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise

for channel in channels:
os.chdir("/srv")
encoder_url = loaded_config.config(channel)["flumotion-encoder"]
url = "http://%s:8081/loop.raw" % encoder_url
print "\nscanning %s" % channel

try:
r = requests.head(url, stream=True)
except:
print "%s is down..." % channel
continue

if r.headers["content-type"] == "None":
print "NO SIGNAL in %s" % channel
try:
shutil.copy("./no_signal.png",
"/srv/%s/latest.png" % channel)
except Exception, e:
raise shutil.Error("Unable to copy no_signal.png\n%s" % e)
else:
os.chdir("/srv/%s" % channel)
generate_thumb(channel, url)
# TODO: Compress PNG (pngcrush replacement)
Binary file added tools/preview/no_signal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c9c224a

Please sign in to comment.