From a1c5108b456aa5689f75944b48d5cb44b1b5a2cf Mon Sep 17 00:00:00 2001 From: j Date: Mon, 6 Mar 2017 09:49:33 +0100 Subject: [PATCH] playout --- playout/play.py | 15 +++++++++++---- playout/update.py | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/playout/play.py b/playout/play.py index 3119878..1babfd8 100755 --- a/playout/play.py +++ b/playout/play.py @@ -31,15 +31,22 @@ playlist = 'play.m3u' today = datetime.date.today() seconds_since_midnight = time.time() - time.mktime(today.timetuple()) -files = sorted(glob('*/*.mp4')) + +if os.path.exists('local'): + files = sorted(glob('/srv/pandora/static/render/*/*.mp4')) +else: + files = sorted(glob('*/*.mp4')) position = 0 while position < seconds_since_midnight: f = files.pop(0) - position += ox.avinfo(f)['duration'] - files.append(f) + try: + position += ox.avinfo(f)['duration'] + files.append(f) + except: + pass with open(playlist, 'w') as f: - f.write('\n'.join(sorted(glob('*/*.mp4')))) + f.write('\n'.join(files)) player.loadlist(playlist) while True: diff --git a/playout/update.py b/playout/update.py index 544e59a..4772c46 100755 --- a/playout/update.py +++ b/playout/update.py @@ -5,12 +5,21 @@ import string import time import datetime import shutil +import sys +import socket +import ox + +socket.setdefaulttimeout(10) base = 'https://cdosea.0x2620.org/static/render' - +lock = '/tmp/update.lock' folder = os.path.abspath(os.path.dirname(__file__)) os.chdir(folder) +if os.path.exists(lock): + sys.exit(0) +with open(lock, 'w') as f: f.write('') + for i in range(10): for letter in string.ascii_uppercase: name = '%02d/%s.mp4' % (i, letter) @@ -26,10 +35,11 @@ for i in range(10): get = True if get: try: - #print(url) - r = requests.get(url) + r = requests.get(url, stream=True) with open('%s.tmp' % name, 'wb') as fd: shutil.copyfileobj(r.raw, fd) + ox.avinfo('%s.tmp' % name)['duration'] shutil.move('%s.tmp' % name, name) except: - pass + print(url, 'failed') +os.unlink(lock)