Skip to content
Permalink
Browse files

Add port autodetection for MPC-BE and MPC-HC

  • Loading branch information
iamkroot committed Jan 29, 2020
1 parent 68b2018 commit b06bb85d1ccb141520fd21a9aea85ecdd48012d2
Showing with 16 additions and 10 deletions.
  1. +5 −5 sample_config.toml
  2. +1 −1 trakt_scrobbler/player_monitors/__init__.py
  3. +10 −4 trakt_scrobbler/player_monitors/mpc.py
@@ -19,17 +19,17 @@ episode = [
]

[players]
monitored = ['mpchc', 'mpv'] # players to be monitored. Allowed: 'mpcbe', 'mpchc', 'mpv', 'plex', 'vlc'
monitored = ['mpc-hc', 'mpv'] # players to be monitored. Allowed: 'mpc-be', 'mpc-hc', 'mpv', 'plex', 'vlc'
skip_interval = 5 # min percent jump to consider for scrobbling to trakt

[players.mpcbe] # enable web interface from options
[players.mpc-be] # enable web interface from options
ip = "localhost"
port = "13579" # from Options -> Player -> Web Interface -> Listen on port (ensure it is ticked)
port = "auto-detect" # set from Options -> Player -> Web Interface -> Listen on port (ensure it is ticked)
poll_interval = 10 # in seconds. How frequently the monitor should check for player update.

[players.mpchc] # enable web interface from options
[players.mpc-hc] # enable web interface from options
ip = "localhost"
port = "13579" # if both mpchc and mpcbe are to be monitored, then ensure that their ports are different
port = "auto-detect" # if both mpchc and mpcbe are to be monitored, then ensure that their ports are different
poll_interval = 10 # in seconds

[players.vlc] # enable web interface from options
@@ -1 +1 @@
player_names = ["mpcbe", "mpchc", "mpv", "plex", "vlc"]
player_names = ["mpc-be", "mpc-hc", "mpv", "plex", "vlc"]
@@ -1,7 +1,6 @@
import re
import logging
from player_monitors.monitor import WebInterfaceMon
from utils import config

logger = logging.getLogger('trakt_scrobbler')

@@ -13,12 +12,19 @@ class MPCMon(WebInterfaceMon):

def __init__(self, scrobble_queue):
try:
self.URL = self.URL.format(**config['players'][self.name])
self.URL = self.URL.format(**self.config)
except KeyError:
logger.exception(f'Check config for correct {self.name} params.')
return
super().__init__(scrobble_queue)

@classmethod
def read_player_cfg(cls, auto_keys=None):
import winreg
subkey = f"Software\\{cls.name.upper()}\\Settings"
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, subkey)
return {"port": lambda: winreg.QueryValueEx(hkey, "WebServerPort")[0]}

def get_vars(self):
response = self.sess.get(self.URL)
matches = self.PATTERN.findall(response.text)
@@ -40,9 +46,9 @@ def update_status(self):

class MPCHCMon(MPCMon):
exclude_import = False
name = 'mpchc'
name = 'mpc-hc'


class MPCBEMon(MPCHCMon):
exclude_import = False
name = 'mpcbe'
name = 'mpc-be'

0 comments on commit b06bb85

Please sign in to comment.
You can’t perform that action at this time.