Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check_signal.py on way to replace generate.sh
- Loading branch information
Showing
3 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.