Skip to content

Commit

Permalink
NEW: add plex profile/user support
Browse files Browse the repository at this point in the history
possibility to switch to a defined plex user/profile
  • Loading branch information
risiko79 committed Oct 6, 2022
1 parent c547bc3 commit 56a7c2c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions mopidy_plex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_config_schema(self):
schema['token'] = config.Secret(optional=True)
schema['username'] = config.String(optional=True)
schema['password'] = config.Secret(optional=True)
schema['profile'] = config.String(optional=True)

#frontend config
schema["port"] = config.Port(optional=True)
Expand Down
1 change: 1 addition & 0 deletions mopidy_plex/ext.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ username =
password =
port =
host =
profile =
29 changes: 22 additions & 7 deletions mopidy_plex/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(self, config:dict=None, session=None):
if config is None:
return
self._core = None
token=config['token']
token=config.get('token', None)
user=config.get('profile', None)
if token is None:
self._plexaccount = MopidyPlexAccount(
username=config['username'],
Expand All @@ -77,18 +78,32 @@ def __init__(self, config:dict=None, session=None):

token = self._plexaccount.authenticationToken

self._plexserver = None
for dev in self._plexaccount.devices():
_plexserver = None
devices = self._plexaccount.devices()
for dev in devices:
if not 'server' in dev.provides:
continue
logger.info("plex server %s found" % dev.name)
if dev.name.lower() == config['server'].lower():
self._plexserver = dev.connect()
_plexserver = dev.connect()
break

if self._plexserver is None:
self._plexserver = PlexServer(config['server'], session=session, token=token)

if _plexserver is None:
try:
_plexserver = PlexServer(config['server'], session=session, token=token)
except:
logger.error("no plex server found")
return

self._plex_admin_server = _plexserver
if user is not None:
try:
_plexserver = _plexserver.switchUser(user)
except Exception as ex:
logger.error("switch to user %s failed: %s",user,str(ex))

self._plexserver = _plexserver


@property
def server(self):
Expand Down
1 change: 1 addition & 0 deletions mopidy_plex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
settings['debug_httpd'] = False
settings['host'] = ""
settings['token'] = None
settings['profile'] = None
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
from setuptools import find_packages, setup

__version__ = "0.2.1"
__version__ = "0.2.2"

setup(
name='Mopidy-Plex',
Expand All @@ -22,7 +22,7 @@
'setuptools>=42',
'wheel',
'Mopidy>=3',
'PlexAPI>=4.7',
'PlexAPI>=4.13',
],
entry_points={
'mopidy.ext': [
Expand Down

0 comments on commit 56a7c2c

Please sign in to comment.