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,6 +51,7 @@ 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 shift:
if position is None: if position is None:
today = datetime.date.today() today = datetime.date.today()
seconds_since_midnight = time.time() - time.mktime(today.timetuple()) seconds_since_midnight = time.time() - time.mktime(today.timetuple())
@ -70,4 +78,3 @@ def update_playlist(playlist, prefix, position=None):
f.write('\n'.join(files)) f.write('\n'.join(files))
f.write('\n') f.write('\n')
return position, len(files) return position, len(files)