cdosea-play/cdoseaplay/play.py
2017-08-25 21:24:38 +02:00

68 lines
1.5 KiB
Python
Executable file

#!/usr/bin/python3
import os
import sys
from glob import glob
import datetime
import time
import string
import random
import ox
from . 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 = os.path.expanduser('~/Videos/cdosea.m3u')
prefix = os.path.expanduser('~/Videos/CDOSEA')
today = datetime.date.today()
seconds_since_midnight = time.time() - time.mktime(today.timetuple())
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