mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
54b26fdc25
* [sync] initial commit * fix populating of `state` field in sync.Status * [connection] add posibliity to return first established connection faster * [base] add timeout argument to PlexObject.fetchItems() * [sync] add timeout arg to SyncItem.getMedia() When you have multiple media within one SyncItem it takes a lot of time to get all the info for this media (on my machine it takes about a second for each movie). * [sync] fix marking media as downloaded * [sync] pass clientIdentifier to created SyncItem() * [sync] override __repr__() for sync.Status * fix after @mikes-nasuni`s review * fix python2 compatibility * get rid of sync.init() * use list comprehension * remove timeout from PlexObject.fetchItems() * fix SyncItem under python 2.7 * fix __doc__ in sync module * revert myplex._connect() back to it`s original state * improve sync docs * get rid of PlexObjects where not needed * add X-Plex-Sync-Version=2 to headers * add sync() method into Video, LibrarySection and MyPlexAccount * add SyncItem.delete() * add sync.Policy.create() * use self._default_sync_title instead of _prettyfilename as default title * let the tests begin * add items for refreshing synclists to PlexServer * fix sync tests * sync for everybody! * add TODO doctring for Audio._defaultSyncTitle() * SyncItems tag may be presented only once, there is no need for loop * add more TODO docstrings * hello docs * remove relative import * remove unused variable from tests/test_sync.py
64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
from collections import defaultdict
|
|
from plexapi.compat import ConfigParser
|
|
|
|
|
|
class PlexConfig(ConfigParser):
|
|
""" PlexAPI configuration object. Settings are stored in an INI file within the
|
|
user's home directory and can be overridden after importing plexapi by simply
|
|
setting the value. See the documentation section 'Configuration' for more
|
|
details on available options.
|
|
|
|
Parameters:
|
|
path (str): Path of the configuration file to load.
|
|
"""
|
|
def __init__(self, path):
|
|
ConfigParser.__init__(self)
|
|
self.read(path)
|
|
self.data = self._asDict()
|
|
|
|
def get(self, key, default=None, cast=None):
|
|
""" Returns the specified configuration value or <default> if not found.
|
|
|
|
Parameters:
|
|
key (str): Configuration variable to load in the format '<section>.<variable>'.
|
|
default: Default value to use if key not found.
|
|
cast (func): Cast the value to the specified type before returning.
|
|
"""
|
|
try:
|
|
# First: check environment variable is set
|
|
envkey = 'PLEXAPI_%s' % key.upper().replace('.', '_')
|
|
value = os.environ.get(envkey)
|
|
if value is None:
|
|
# Second: check the config file has attr
|
|
section, name = key.lower().split('.')
|
|
value = self.data.get(section, {}).get(name, default)
|
|
return cast(value) if cast else value
|
|
except: # noqa: E722
|
|
return default
|
|
|
|
def _asDict(self):
|
|
""" Returns all configuration values as a dictionary. """
|
|
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)
|
|
|
|
|
|
def reset_base_headers():
|
|
""" Convenience function returns a dict of all base X-Plex-* headers for session requests. """
|
|
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,
|
|
'X-Plex-Device-Name': plexapi.X_PLEX_DEVICE_NAME,
|
|
'X-Plex-Client-Identifier': plexapi.X_PLEX_IDENTIFIER,
|
|
'X-Plex-Sync-Version': '2',
|
|
}
|