Skip to content

Commit

Permalink
mpc-be: Look in WebServer for Port in Windows reg
Browse files Browse the repository at this point in the history
Fixes #198
  • Loading branch information
iamkroot committed Oct 8, 2023
1 parent edb8db3 commit 61fe63e
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions trakt_scrobbler/player_monitors/mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ def __init__(self, scrobble_queue):
super().__init__(scrobble_queue)

@staticmethod
def _read_registry_cfg(path):
def _read_registry_cfg(*paths):
import winreg
try:
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path)
except FileNotFoundError as e:
e.filename = path
raise
return {"port": lambda: winreg.QueryValueEx(hkey, "WebServerPort")[0]}
error = FileNotFoundError
for path, key in paths:
try:
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path)
except FileNotFoundError as e:
error = e
# try next entry in paths
else:
# found!
break
else:
error.filename = ",".join(paths)
raise error
return {"port": lambda: winreg.QueryValueEx(hkey, key)[0]}

def get_vars(self):
response = self.sess.get(self.URL)
Expand Down Expand Up @@ -61,7 +69,7 @@ class MPCHCMon(MPCMon):
@classmethod
def read_player_cfg(cls, auto_keys=None):
path = "Software\\MPC-HC\\MPC-HC\\Settings"
return cls._read_registry_cfg(path)
return cls._read_registry_cfg((path, "WebServerPort"))


class MPCBEMon(MPCHCMon):
Expand All @@ -70,5 +78,7 @@ class MPCBEMon(MPCHCMon):

@classmethod
def read_player_cfg(cls, auto_keys=None):
path = "Software\\MPC-BE\\Settings"
return cls._read_registry_cfg(path)
path1, key1 = "Software\\MPC-BE\\WebServer", "Port"
# old versions can store their port under Settings hkey
path2, key2 = "Software\\MPC-BE\\Settings", "WebServerPort"
return cls._read_registry_cfg((path1, key1), (path2, key2))

0 comments on commit 61fe63e

Please sign in to comment.