#!/usr/bin/python3 import os import sys from glob import glob import datetime import time import string import random 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, sub_text_font_size=28, sub_text_font='Menlo' ) #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()) prefix = 'video/' if os.path.exists('local'): prefix = '/srv/pandora/static/render/' files = [] videos = {} for letter in string.ascii_uppercase: videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower())) random.shuffle(videos[letter]) for i in range(10): for letter in string.ascii_uppercase: files.append(videos[letter][i]) position = 0 while position < seconds_since_midnight: f = files.pop(0) try: position += ox.avinfo(f)['duration'] files.append(f) except: pass with open(playlist, 'w') as f: f.write('\n'.join(files)) player.loadlist(playlist) while True: try: player.wait_for_playback() except: sys.exit() del player