Skip to content

Commit b5051d8

Browse files
committed
Update logic to fill defaults into config instance
1 parent a8a9079 commit b5051d8

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

plexapi/config.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,47 @@ def get(self, key, default=None, cast=None):
4242
def _asDict(self):
4343
""" Returns all configuration values as a dictionary. """
4444
config = defaultdict(dict)
45+
config.update(self._defaults())
4546
for section in self._sections:
4647
for name, value in self._sections[section].items():
4748
if name != '__name__':
4849
config[section.lower()][name.lower()] = value
4950
return dict(config)
5051

52+
def _defaults(self):
53+
from uuid import getnode
54+
from platform import uname
55+
from plexapi import PROJECT, VERSION
5156

52-
def reset_base_headers():
53-
""" Convenience function returns a dict of all base X-Plex-* headers for session requests. """
54-
from platform import uname
55-
from uuid import getnode
57+
platform_name, device_name, platform_version = uname()[0:3]
58+
59+
return {
60+
'header': {
61+
'provides': 'controller',
62+
'platform': platform_name,
63+
'platform_version': platform_version,
64+
'product': PROJECT,
65+
'version': VERSION,
66+
'device': platform_name,
67+
'device_name': device_name,
68+
'identifier': str(hex(getnode())),
69+
}
70+
}
5671

57-
from plexapi import CONFIG, PROJECT, VERSION
5872

59-
# Plex Header Configuration
60-
X_PLEX_PROVIDES = CONFIG.get('header.provides', 'controller')
61-
X_PLEX_PLATFORM = CONFIG.get('header.platform', CONFIG.get('header.platorm', uname()[0]))
62-
X_PLEX_PLATFORM_VERSION = CONFIG.get('header.platform_version', uname()[2])
63-
X_PLEX_PRODUCT = CONFIG.get('header.product', PROJECT)
64-
X_PLEX_VERSION = CONFIG.get('header.version', VERSION)
65-
X_PLEX_DEVICE = CONFIG.get('header.device', X_PLEX_PLATFORM)
66-
X_PLEX_DEVICE_NAME = CONFIG.get('header.device_name', uname()[1])
67-
X_PLEX_IDENTIFIER = CONFIG.get('header.identifier', str(hex(getnode())))
73+
def reset_base_headers():
74+
""" Convenience function returns a dict of all base X-Plex-* headers for session requests. """
75+
from plexapi import CONFIG
6876

6977
return {
70-
'X-Plex-Platform': X_PLEX_PLATFORM,
71-
'X-Plex-Platform-Version': X_PLEX_PLATFORM_VERSION,
72-
'X-Plex-Provides': X_PLEX_PROVIDES,
73-
'X-Plex-Product': X_PLEX_PRODUCT,
74-
'X-Plex-Version': X_PLEX_VERSION,
75-
'X-Plex-Device': X_PLEX_DEVICE,
76-
'X-Plex-Device-Name': X_PLEX_DEVICE_NAME,
77-
'X-Plex-Client-Identifier': X_PLEX_IDENTIFIER,
78+
'X-Plex-Platform': CONFIG.get('header.platorm', CONFIG.get('header.platform')),
79+
'X-Plex-Platform-Version': CONFIG.get('header.platform_version'),
80+
'X-Plex-Provides': CONFIG.get('header.provides'),
81+
'X-Plex-Product': CONFIG.get('header.product'),
82+
'X-Plex-Version': CONFIG.get('header.version'),
83+
'X-Plex-Device': CONFIG.get('header.device'),
84+
'X-Plex-Device-Name': CONFIG.get('header.device_name'),
85+
'X-Plex-Client-Identifier': CONFIG.get('header.identifier'),
7886
'X-Plex-Sync-Version': '2',
7987
'X-Plex-Features': 'external-media',
8088
}

0 commit comments

Comments
 (0)