This commit is contained in:
j 2017-03-06 09:49:33 +01:00
parent 1da2ac0475
commit a1c5108b45
2 changed files with 25 additions and 8 deletions

View file

@ -31,15 +31,22 @@ playlist = 'play.m3u'
today = datetime.date.today() today = datetime.date.today()
seconds_since_midnight = time.time() - time.mktime(today.timetuple()) 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 position = 0
while position < seconds_since_midnight: while position < seconds_since_midnight:
f = files.pop(0) f = files.pop(0)
position += ox.avinfo(f)['duration'] try:
files.append(f) position += ox.avinfo(f)['duration']
files.append(f)
except:
pass
with open(playlist, 'w') as f: with open(playlist, 'w') as f:
f.write('\n'.join(sorted(glob('*/*.mp4')))) f.write('\n'.join(files))
player.loadlist(playlist) player.loadlist(playlist)
while True: while True:

View file

@ -5,12 +5,21 @@ import string
import time import time
import datetime import datetime
import shutil import shutil
import sys
import socket
import ox
socket.setdefaulttimeout(10)
base = 'https://cdosea.0x2620.org/static/render' base = 'https://cdosea.0x2620.org/static/render'
lock = '/tmp/update.lock'
folder = os.path.abspath(os.path.dirname(__file__)) folder = os.path.abspath(os.path.dirname(__file__))
os.chdir(folder) 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 i in range(10):
for letter in string.ascii_uppercase: for letter in string.ascii_uppercase:
name = '%02d/%s.mp4' % (i, letter) name = '%02d/%s.mp4' % (i, letter)
@ -26,10 +35,11 @@ for i in range(10):
get = True get = True
if get: if get:
try: try:
#print(url) r = requests.get(url, stream=True)
r = requests.get(url)
with open('%s.tmp' % name, 'wb') as fd: with open('%s.tmp' % name, 'wb') as fd:
shutil.copyfileobj(r.raw, fd) shutil.copyfileobj(r.raw, fd)
ox.avinfo('%s.tmp' % name)['duration']
shutil.move('%s.tmp' % name, name) shutil.move('%s.tmp' % name, name)
except: except:
pass print(url, 'failed')
os.unlink(lock)