load player config from file

This commit is contained in:
j 2024-04-01 12:08:21 +02:00
parent 6cdbf4f1b9
commit 8268166b77

View file

@ -20,10 +20,15 @@ SYNC_GRACE_TIME = 5
SYNC_JUMP_AHEAD = 1 SYNC_JUMP_AHEAD = 1
PORT = 9067 PORT = 9067
DEBUG = False DEBUG = False
FONT = 'Menlo'
FONT_SIZE = 30 CONFIG = {
FONT_BORDER = 4 "font": "Menlo",
SUB_MARGIN = 2 * 36 + 6 "font_size": 30,
"font_border": 4,
"sub_margin": 2 * 36 + 6,
"sub_spacing": 0,
"vf": None
}
def hide_gnome_overview(): def hide_gnome_overview():
@ -74,18 +79,22 @@ class Sync(Thread):
self.mpv = mpv.MPV( self.mpv = mpv.MPV(
log_handler=mpv_log, input_default_bindings=True, log_handler=mpv_log, input_default_bindings=True,
input_vo_keyboard=True, input_vo_keyboard=True,
sub_font_size=FONT_SIZE, sub_font=FONT, sub_font_size=CONFIG["font_size"], sub_font=CONFIG["font"],
sub_border_size=FONT_BORDER, sub_border_size=CONFIG["font_border"],
sub_margin_y=SUB_MARGIN, sub_margin_y=CONFIG["sub_margin"],
sub_ass_line_spacing=CONFIG["sub_spacing"],
) )
else: else:
self.mpv = mpv.MPV( self.mpv = mpv.MPV(
log_handler=mpv_log, input_default_bindings=True, log_handler=mpv_log, input_default_bindings=True,
input_vo_keyboard=True, input_vo_keyboard=True,
sub_text_font_size=FONT_SIZE, sub_text_font=FONT, sub_text_font_size=CONFIG["font_size"], sub_text_font=CONFIG["font"],
sub_border_size=FONT_BORDER, sub_border_size=CONFIG["font_border"],
sub_margin_y=SUB_MARGIN, 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.observe_property('time-pos', self.time_pos_cb)
self.mpv.fullscreen = kwargs.get('fullscreen', False) self.mpv.fullscreen = kwargs.get('fullscreen', False)
self.mpv.loop_file = 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('--debug', action='store_true', help='debug', default=False)
parser.add_argument('--hour', action='store_true', help='hour', 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('--sax', action='store_true', help='hour', default=False)
parser.add_argument('--config', help='config', default=None)
args = parser.parse_args() args = parser.parse_args()
DEBUG = args.debug DEBUG = args.debug
if DEBUG: if DEBUG:
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s' log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_format) 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__)) base = os.path.dirname(os.path.abspath(__file__))
#os.chdir(base) #os.chdir(base)