From 8268166b7744ad08f30c2b709ce6a28d80f1e5dd Mon Sep 17 00:00:00 2001 From: j Date: Mon, 1 Apr 2024 12:08:21 +0200 Subject: [PATCH] load player config from file --- player/player.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/player/player.py b/player/player.py index c3e5cb1..4b56fc8 100755 --- a/player/player.py +++ b/player/player.py @@ -20,10 +20,15 @@ SYNC_GRACE_TIME = 5 SYNC_JUMP_AHEAD = 1 PORT = 9067 DEBUG = False -FONT = 'Menlo' -FONT_SIZE = 30 -FONT_BORDER = 4 -SUB_MARGIN = 2 * 36 + 6 + +CONFIG = { + "font": "Menlo", + "font_size": 30, + "font_border": 4, + "sub_margin": 2 * 36 + 6, + "sub_spacing": 0, + "vf": None +} def hide_gnome_overview(): @@ -74,18 +79,22 @@ class Sync(Thread): self.mpv = mpv.MPV( log_handler=mpv_log, input_default_bindings=True, input_vo_keyboard=True, - sub_font_size=FONT_SIZE, sub_font=FONT, - sub_border_size=FONT_BORDER, - sub_margin_y=SUB_MARGIN, + sub_font_size=CONFIG["font_size"], sub_font=CONFIG["font"], + sub_border_size=CONFIG["font_border"], + sub_margin_y=CONFIG["sub_margin"], + sub_ass_line_spacing=CONFIG["sub_spacing"], ) else: self.mpv = mpv.MPV( log_handler=mpv_log, input_default_bindings=True, input_vo_keyboard=True, - sub_text_font_size=FONT_SIZE, sub_text_font=FONT, - sub_border_size=FONT_BORDER, - sub_margin_y=SUB_MARGIN, + sub_text_font_size=CONFIG["font_size"], sub_text_font=CONFIG["font"], + sub_border_size=CONFIG["font_border"], + sub_margin_y=CONFIG["sub_margin"], + sub_ass_line_spacing=CONFIG["sub_spacing"], ) + if CONFIG.get("vf"): + self.mpv.vf = CONFIG["vf"] self.mpv.observe_property('time-pos', self.time_pos_cb) self.mpv.fullscreen = kwargs.get('fullscreen', False) self.mpv.loop_file = False @@ -386,12 +395,17 @@ def main(): parser.add_argument('--debug', action='store_true', help='debug', default=False) parser.add_argument('--hour', action='store_true', help='hour', default=False) parser.add_argument('--sax', action='store_true', help='hour', default=False) + parser.add_argument('--config', help='config', default=None) args = parser.parse_args() DEBUG = args.debug if DEBUG: log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s' logging.basicConfig(level=logging.DEBUG, format=log_format) + if args.config: + with open(args.config) as fd: + CONFIG.update(json.load(fd)) + base = os.path.dirname(os.path.abspath(__file__)) #os.chdir(base)