-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpc-wrapper-gmpc.py
40 lines (33 loc) · 1.36 KB
/
mpc-wrapper-gmpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python3
"""
MPC wrapper script that gets the server details from the gmpc config files
Used to use gmpc-remote, but that's been removed in the upgrade to Debian Bullseye.
So lets just use MPC, but then we can't easily change what server mpc talks to via the gmpc GUI.
This should glue the 2 together nicely.
"""
import configparser
import os
import pathlib
import sys
config_dir = pathlib.Path('~/.config/gmpc/').expanduser()
# This config file specifies where what profile is loaded
gmpc_cfg = configparser.ConfigParser()
try:
gmpc_cfg.read(os.fspath(config_dir / 'gmpc.cfg'))
except configparser.ParsingError:
# These aren't quite .ini files, so this is expected
# It's close enough and still works
pass
# This has the profile definitons that include the actual host & port number
profiles_cfg = configparser.ConfigParser()
try:
profiles_cfg.read(config_dir / pathlib.Path('profiles.cfg'))
except configparser.ParsingError:
# These aren't quite .ini files, so this is expected.
# It's close enough and still works
pass
currentProfile = gmpc_cfg['connection']['currentProfile'].strip('"')
# Run MPC with the required environment variables and arguments.
os.execvpe('mpc', sys.argv,
{'MPD_HOST': profiles_cfg[currentProfile]['hostname'].strip('"'),
'MPD_PORT': profiles_cfg[currentProfile]['portnumber'].strip('"')})