add title, option to play from a and restart

This commit is contained in:
j 2017-10-12 18:35:29 +02:00
parent 40472ec6f9
commit 3529e01aba
3 changed files with 40 additions and 24 deletions

View file

@ -28,6 +28,7 @@ def main():
parser.add_argument('--prefix', help='video location', default=prefix) parser.add_argument('--prefix', help='video location', default=prefix)
parser.add_argument('--window', action='store_true', help='run in window', default=False) parser.add_argument('--window', action='store_true', help='run in window', default=False)
parser.add_argument('--debug', action='store_true', help='debug', default=False) parser.add_argument('--debug', action='store_true', help='debug', default=False)
parser.add_argument('-a', '--always-a', action='store_true', help='start from A', default=False)
args = parser.parse_args() args = parser.parse_args()
DEBUG = args.debug DEBUG = args.debug
@ -40,9 +41,17 @@ def main():
player = get_player() player = get_player()
player.register_key_binding('q', q_binding) player.register_key_binding('q', q_binding)
update_playlist(args.playlist, args.prefix) def restart(*a):
update_playlist(args.playlist, args.prefix, shift=False)
player.loadlist(args.playlist)
player.pause = True
player.register_key_binding('r', restart)
update_playlist(args.playlist, args.prefix, shift=not args.always_a)
sub = SubtitleServer(player, args.playlist) sub = SubtitleServer(player, args.playlist)
player.loadlist(args.playlist) player.loadlist(args.playlist)
if args.always_a:
player.pause = True
while True: while True:
try: try:

BIN
cdoseaplay/static/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -11,11 +11,16 @@ import ox
from . import mpv from . import mpv
import logging import logging
logger = logging.getLogger('cdosea') logger = logging.getLogger('cdosea')
STATIC_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static')
def mpv_log(loglevel, component, message): def mpv_log(loglevel, component, message):
logger.info('[{}] {}: {}'.format(loglevel, component, message)) logger.info('[{}] {}: {}'.format(loglevel, component, message))
def get_player(fullscreen=True): def get_player(fullscreen=True):
# 42 max # 42 max
player = mpv.MPV( player = mpv.MPV(
@ -26,16 +31,18 @@ def get_player(fullscreen=True):
player.fullscreen = fullscreen player.fullscreen = fullscreen
player.loop = 'inf' player.loop = 'inf'
player.loop_file = 'no' player.loop_file = 'no'
return player return player
def update_playlist(playlist, prefix, position=None):
def update_playlist(playlist, prefix, position=None, shift=True):
files = [] files = []
videos = {} videos = {}
if not prefix.endswith('/'): if not prefix.endswith('/'):
prefix += '/' prefix += '/'
if not shift:
files.append(os.path.join(STATIC_ROOT, 'title.png'))
for letter in string.ascii_uppercase: for letter in string.ascii_uppercase:
videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower())) videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower()))
random.shuffle(videos[letter]) random.shuffle(videos[letter])
@ -44,30 +51,30 @@ def update_playlist(playlist, prefix, position=None):
for letter in string.ascii_uppercase: for letter in string.ascii_uppercase:
files.append(videos[letter][i]) files.append(videos[letter][i])
if position is None: if shift:
today = datetime.date.today() if position is None:
seconds_since_midnight = time.time() - time.mktime(today.timetuple()) today = datetime.date.today()
offset = 0 seconds_since_midnight = time.time() - time.mktime(today.timetuple())
position = 0 offset = 0
position = 0
while offset < seconds_since_midnight: while offset < seconds_since_midnight:
f = files.pop(0) f = files.pop(0)
try: try:
offset += ox.avinfo(f)['duration'] offset += ox.avinfo(f)['duration']
files.append(f)
except:
logger.debug('WTF', exc_info=True)
pass
position += 1
else:
pos = position
while pos:
f = files.pop(0)
files.append(f) files.append(f)
except: pos -= 1
logger.debug('WTF', exc_info=True)
pass
position += 1
else:
pos = position
while pos:
f = files.pop(0)
files.append(f)
pos -= 1
with open(playlist, 'w') as f: with open(playlist, 'w') as f:
f.write('\n'.join(files)) f.write('\n'.join(files))
f.write('\n') f.write('\n')
return position, len(files) return position, len(files)