2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-06-02 02:27:43 +00:00
|
|
|
"""
|
|
|
|
PlexConfig
|
2016-03-21 04:26:02 +00:00
|
|
|
Settings are stored in an INI file and can be overridden after import
|
|
|
|
plexapi by simply setting the value.
|
2015-06-02 02:27:43 +00:00
|
|
|
"""
|
|
|
|
from collections import defaultdict
|
2015-06-15 02:45:22 +00:00
|
|
|
try:
|
|
|
|
from ConfigParser import ConfigParser # Python2
|
|
|
|
except ImportError:
|
|
|
|
from configparser import ConfigParser # Python3
|
2015-06-02 02:27:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PlexConfig(ConfigParser):
|
|
|
|
|
|
|
|
def __init__(self, path):
|
|
|
|
ConfigParser.__init__(self)
|
|
|
|
self.read(path)
|
2016-03-21 04:26:02 +00:00
|
|
|
self.data = self._asDict()
|
2015-06-02 02:27:43 +00:00
|
|
|
|
|
|
|
def get(self, key, default=None, cast=None):
|
|
|
|
try:
|
|
|
|
section, name = key.split('.')
|
|
|
|
value = self.data.get(section.lower(), {}).get(name.lower(), default)
|
|
|
|
return cast(value) if cast else value
|
|
|
|
except:
|
|
|
|
return default
|
|
|
|
|
2016-03-21 04:26:02 +00:00
|
|
|
def _asDict(self):
|
2015-06-02 02:27:43 +00:00
|
|
|
config = defaultdict(dict)
|
|
|
|
for section in self._sections:
|
|
|
|
for name, value in self._sections[section].items():
|
|
|
|
if name != '__name__':
|
|
|
|
config[section.lower()][name.lower()] = value
|
|
|
|
return dict(config)
|
2016-03-16 03:47:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reset_base_headers():
|
|
|
|
import plexapi
|
|
|
|
return {
|
|
|
|
'X-Plex-Platform': plexapi.X_PLEX_PLATFORM,
|
|
|
|
'X-Plex-Platform-Version': plexapi.X_PLEX_PLATFORM_VERSION,
|
|
|
|
'X-Plex-Provides': plexapi.X_PLEX_PROVIDES,
|
|
|
|
'X-Plex-Product': plexapi.X_PLEX_PRODUCT,
|
|
|
|
'X-Plex-Version': plexapi.X_PLEX_VERSION,
|
|
|
|
'X-Plex-Device': plexapi.X_PLEX_DEVICE,
|
2016-04-02 06:19:32 +00:00
|
|
|
'X-Plex-Device-Name': plexapi.X_PLEX_DEVICE_NAME,
|
2016-03-16 03:47:13 +00:00
|
|
|
'X-Plex-Client-Identifier': plexapi.X_PLEX_IDENTIFIER,
|
|
|
|
}
|