pandora_cdosea/playout/play.py

59 lines
1.2 KiB
Python
Raw Normal View History

2017-03-01 09:20:55 +00:00
#!/usr/bin/python3
import subprocess
import os
import sys
from glob import glob
import datetime
import time
import ox
import mpv
def my_log(loglevel, component, message):
print('[{}] {}: {}'.format(loglevel, component, message))
base = os.path.dirname(os.path.abspath(__file__))
os.chdir(base)
player = mpv.MPV(log_handler=my_log, input_default_bindings=True, input_vo_keyboard=True)
#player.observe_property('time-pos', lambda pos: print('Now playing at {:.2f}s'.format(pos)))
player.fullscreen = True
player.loop = 'inf'
def q_binding(*args):
global player
player.quit()
del player
player.register_key_binding('q', q_binding)
playlist = 'play.m3u'
today = datetime.date.today()
seconds_since_midnight = time.time() - time.mktime(today.timetuple())
2017-03-06 08:49:33 +00:00
if os.path.exists('local'):
files = sorted(glob('/srv/pandora/static/render/*/*.mp4'))
else:
files = sorted(glob('*/*.mp4'))
2017-03-01 09:20:55 +00:00
position = 0
while position < seconds_since_midnight:
f = files.pop(0)
2017-03-06 08:49:33 +00:00
try:
position += ox.avinfo(f)['duration']
files.append(f)
except:
pass
2017-03-01 09:20:55 +00:00
with open(playlist, 'w') as f:
2017-03-06 08:49:33 +00:00
f.write('\n'.join(files))
2017-03-01 09:20:55 +00:00
player.loadlist(playlist)
while True:
try:
player.wait_for_playback()
except:
sys.exit()
del player