Skip to content

Commit

Permalink
Respect the user's mpv input.conf settings (#230)
Browse files Browse the repository at this point in the history
Respect the user's mpv input.conf settings
  • Loading branch information
vn-ki committed Sep 28, 2019
2 parents a3414a1 + 82c7a30 commit abdaebb
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions anime_downloader/players/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,32 @@ def args(self):
return ['--input-conf='+get_mpv_configfile(), self.stream_url]


def get_mpv_configfile():
conf = os.path.join(config.APP_DIR, 'mpv-config.conf')

# TODO: Use available config too(?)
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')

# For now don't do this
# if os.path.exists(conf):
# return conf

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')
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'
)
Expand Down

0 comments on commit abdaebb

Please sign in to comment.