pandora_cdosea/playout/play.py

52 lines
1.1 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())
files = sorted(glob('*/*.mp4'))
position = 0
while position < seconds_since_midnight:
f = files.pop(0)
position += ox.avinfo(f)['duration']
files.append(f)
with open(playlist, 'w') as f:
f.write('\n'.join(sorted(glob('*/*.mp4'))))
player.loadlist(playlist)
while True:
try:
player.wait_for_playback()
except:
sys.exit()
del player