pandora_cdosea/playout/play.py

70 lines
1.5 KiB
Python
Raw Normal View History

2017-03-01 09:20:55 +00:00
#!/usr/bin/python3
import os
import sys
from glob import glob
import datetime
import time
2017-03-15 10:08:49 +00:00
import string
import random
2017-03-01 09:20:55 +00:00
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
2017-05-15 17:03:28 +00:00
prefix = 'video/'
2017-03-06 08:49:33 +00:00
if os.path.exists('local'):
2017-03-15 10:08:49 +00:00
prefix = '/srv/pandora/static/render/'
files = []
videos = {}
for letter in string.ascii_uppercase:
2017-05-15 17:03:28 +00:00
videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower()))
2017-03-15 10:08:49 +00:00
random.shuffle(videos[letter])
for i in range(10):
for letter in string.ascii_uppercase:
files.append(videos[letter][i])
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