From 82c7a307a3a04b6802a0c4734bcce1e7d13f4a76 Mon Sep 17 00:00:00 2001 From: Jordan Cannon Date: Fri, 27 Sep 2019 21:58:49 -0500 Subject: [PATCH] Respect the user's mpv input.conf settings --- anime_downloader/players/mpv.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/anime_downloader/players/mpv.py b/anime_downloader/players/mpv.py index c7e6659..bb27a2a 100644 --- a/anime_downloader/players/mpv.py +++ b/anime_downloader/players/mpv.py @@ -22,17 +22,32 @@ class mpv(BasePlayer): return ['--input-conf='+get_mpv_configfile(), self.stream_url] +def get_mpv_home(): + if 'MPV_HOME' in os.environ: + return os.environ.get('MPV_HOME') + elif 'XDG_CONFIG_HOME' in os.environ: + return os.path.join(os.environ.get('XDG_CONFIG_HOME'), 'mpv') + elif os.path.exists(os.path.expanduser('~/.mpv')): + return os.path.expanduser('~/.mpv') + elif os.name == 'posix': + return os.path.expanduser('~/.config/mpv') + else: + return os.path.join(os.environ.get('APPDATA'), 'mpv') + + def get_mpv_configfile(): + # Read the user's input config file if it exists + userconf = os.path.join(get_mpv_home(), 'input.conf') + userconftext = '' + if os.path.exists(userconf): + with open(userconf, 'r') as userconfigfile: + userconftext = userconfigfile.read() + + # Create a new config file to add anime-downloader specific key bindings conf = os.path.join(config.APP_DIR, 'mpv-config.conf') - - # TODO: Use available config too(?) - - # For now don't do this - # if os.path.exists(conf): - # return conf - with open(conf, 'w') as configfile: configfile.write( + userconftext + 'q quit 50\nCLOSE_WIN quit 50\nSTOP quit 50\nctrl+c quit 50\n' '> quit 51\nNEXT quit 51\n< quit 52\nPREV quit 52\ni seek 80\n' )