#!/usr/bin/python3 import argparse from glob import glob import os import sys from .utils import update_playlist, get_player, trigger_lights from .subtitleserver import SubtitleServer from . import config import logging logger = logging.getLogger('cdosea') player = None quit = False def q_binding(*args): global player quit = True player.quit() player = None 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() shift = config.start != 'a' 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) player = get_player(font=config.font, font_size=config.font_size) 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 sub.load_playlist(args.playlist) player.register_key_binding('r', restart) update_playlist(args.playlist, args.prefix, shift=shift) player.loadlist(args.playlist) sub = SubtitleServer(player, args.playlist) if not shift: player.pause = True pause_next = False play_lights = True while True: if not player: break if not quit: if pause_next: player.pause = True pause_next = False play_lights = False elif player.path.decode().endswith('black.mp4'): pause_next = True play_lights = False if play_lights and config.lights and player.path: trigger_lights(player.path.decode()) play_lights = True try: player.wait_for_playback() except: sys.exit() del player sub.join() if __name__ == '__main__': main()