Skip to content

Commit 6bc8056

Browse files
committed
Update logic to fill defaults into config instance
1 parent 544ae2f commit 6bc8056

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

plexapi/config.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,46 @@ 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
56+
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+
}
71+
5172

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

6877
return {
69-
'X-Plex-Platform': X_PLEX_PLATFORM,
70-
'X-Plex-Platform-Version': X_PLEX_PLATFORM_VERSION,
71-
'X-Plex-Provides': X_PLEX_PROVIDES,
72-
'X-Plex-Product': X_PLEX_PRODUCT,
73-
'X-Plex-Version': X_PLEX_VERSION,
74-
'X-Plex-Device': X_PLEX_DEVICE,
75-
'X-Plex-Device-Name': X_PLEX_DEVICE_NAME,
76-
'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'),
7786
'X-Plex-Sync-Version': '2',
7887
}

0 commit comments

Comments
 (0)