cdosea-play/cdoseaplay/play.py

93 lines
2.5 KiB
Python
Raw Permalink Normal View History

2017-08-25 19:21:36 +00:00
#!/usr/bin/python3
2017-08-30 14:07:50 +00:00
import argparse
from glob import glob
2017-08-25 19:21:36 +00:00
import os
import sys
2023-10-12 10:38:34 +00:00
from .utils import update_playlist, get_player, trigger_lights, get_path
2017-10-04 11:02:13 +00:00
from .subtitleserver import SubtitleServer
2017-10-12 16:45:57 +00:00
from . import config
2017-08-25 19:21:36 +00:00
2017-08-30 14:07:50 +00:00
import logging
logger = logging.getLogger('cdosea')
2017-08-25 19:21:36 +00:00
2017-08-30 14:07:50 +00:00
player = None
2017-10-27 20:47:45 +00:00
quit = False
2017-08-25 19:21:36 +00:00
2017-10-27 20:53:44 +00:00
2017-08-25 19:21:36 +00:00
def q_binding(*args):
global player
2017-10-27 20:47:45 +00:00
quit = True
2017-10-27 20:53:44 +00:00
player.quit()
player = None
2017-08-25 19:21:36 +00:00
2017-08-30 14:07:50 +00:00
def main():
global player
playlist = os.path.expanduser('~/Videos/cdosea.m3u')
prefix = os.path.expanduser('~/Videos/CDOSEA')
parser = argparse.ArgumentParser(description='play 2 screens in sync')
parser.add_argument('--playlist', help='play.m3u', default=playlist)
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('--debug', action='store_true', help='debug', default=False)
args = parser.parse_args()
2017-10-12 16:45:57 +00:00
shift = config.start != 'a'
2017-08-30 14:07:50 +00:00
DEBUG = args.debug
if DEBUG:
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_format)
base = os.path.dirname(os.path.abspath(__file__))
os.chdir(base)
2018-07-31 07:37:42 +00:00
player = get_player(font=config.font, font_size=config.font_size)
2017-08-30 14:07:50 +00:00
player.register_key_binding('q', q_binding)
def restart(*a):
update_playlist(args.playlist, args.prefix, shift=False)
player.loadlist(args.playlist)
player.pause = True
2017-10-13 07:33:29 +00:00
sub.load_playlist(args.playlist)
player.register_key_binding('r', restart)
2017-10-12 16:45:57 +00:00
update_playlist(args.playlist, args.prefix, shift=shift)
2017-08-30 14:07:50 +00:00
player.loadlist(args.playlist)
2017-10-13 07:33:29 +00:00
sub = SubtitleServer(player, args.playlist)
2017-10-12 16:45:57 +00:00
if not shift:
player.pause = True
2017-08-30 14:07:50 +00:00
2017-10-27 20:47:45 +00:00
pause_next = False
play_lights = True
path = ''
if player.path:
path = get_path(player.path)
2017-08-30 14:07:50 +00:00
while True:
2017-10-27 20:53:44 +00:00
if not player:
break
if not quit:
if pause_next:
player.pause = True
pause_next = False
play_lights = False
elif player.path and get_path(player.path).endswith('black.mp4'):
2017-10-27 20:53:44 +00:00
pause_next = True
play_lights = False
2017-10-27 20:47:45 +00:00
if play_lights and config.lights and player.path:
trigger_lights(get_path(player.path))
2017-10-27 20:47:45 +00:00
play_lights = True
2017-08-30 14:07:50 +00:00
try:
player.wait_for_playback()
except:
sys.exit()
del player
2017-10-04 11:02:13 +00:00
sub.join()
2017-08-25 19:21:36 +00:00
2017-08-30 14:07:50 +00:00
if __name__ == '__main__':
main()