2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-03-16 03:47:13 +00:00
|
|
|
import logging, os
|
2014-12-29 03:21:58 +00:00
|
|
|
from logging.handlers import RotatingFileHandler
|
2016-04-02 06:19:32 +00:00
|
|
|
from platform import uname
|
2016-03-16 03:47:13 +00:00
|
|
|
from plexapi.config import PlexConfig, reset_base_headers
|
2017-01-26 06:33:01 +00:00
|
|
|
from plexapi.utils import SecretsFilter
|
2014-12-29 03:21:58 +00:00
|
|
|
from uuid import getnode
|
|
|
|
|
2015-06-02 02:27:43 +00:00
|
|
|
# Load User Defined Config
|
2017-01-26 05:43:19 +00:00
|
|
|
DEFAULT_CONFIG_PATH = os.path.expanduser('~/.config/plexapi/config.ini')
|
|
|
|
CONFIG_PATH = os.environ.get('PLEX_CONFIG_PATH', DEFAULT_CONFIG_PATH)
|
2015-06-02 02:27:43 +00:00
|
|
|
CONFIG = PlexConfig(CONFIG_PATH)
|
|
|
|
|
|
|
|
# Core Settings
|
2016-03-31 20:52:48 +00:00
|
|
|
PROJECT = 'PlexAPI' # name provided to plex server
|
2017-02-07 06:20:49 +00:00
|
|
|
VERSION = '2.9.0' # version of this api
|
2016-04-06 03:32:49 +00:00
|
|
|
TIMEOUT = CONFIG.get('plexapi.timeout', 30, int) # request timeout
|
2016-05-24 02:13:26 +00:00
|
|
|
X_PLEX_CONTAINER_SIZE = 50 # max results to return in a single search page
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
# Plex Header Configuation
|
2016-04-06 03:32:49 +00:00
|
|
|
X_PLEX_PROVIDES = 'controller' # one or more of [player, controller, server]
|
2016-03-16 03:47:13 +00:00
|
|
|
X_PLEX_PLATFORM = CONFIG.get('headers.platorm', uname()[0]) # Platform name, eg iOS, MacOSX, Android, LG, etc
|
|
|
|
X_PLEX_PLATFORM_VERSION = CONFIG.get('headers.platform_version', uname()[2]) # Operating system version, eg 4.3.1, 10.6.7, 3.2
|
|
|
|
X_PLEX_PRODUCT = CONFIG.get('headers.product', PROJECT) # Plex application name, eg Laika, Plex Media Server, Media Link
|
|
|
|
X_PLEX_VERSION = CONFIG.get('headers.version', VERSION) # Plex application version number
|
2016-04-02 06:19:32 +00:00
|
|
|
X_PLEX_DEVICE = CONFIG.get('headers.platform', X_PLEX_PLATFORM) # Device make, eg iPhone, FiteTV, Linux, etc.
|
|
|
|
X_PLEX_DEVICE_NAME = uname()[1] # Device name, hostname or phone name, etc.
|
2016-03-16 03:47:13 +00:00
|
|
|
X_PLEX_IDENTIFIER = CONFIG.get('headers.identifier', str(hex(getnode()))) # UUID, serial number, or other number unique per device
|
|
|
|
BASE_HEADERS = reset_base_headers()
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
# Logging Configuration
|
|
|
|
log = logging.getLogger('plexapi')
|
2015-06-04 14:43:50 +00:00
|
|
|
logfile = CONFIG.get('logging.path')
|
|
|
|
logformat = CONFIG.get('logging.format', '%(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s')
|
2017-02-08 05:36:22 +00:00
|
|
|
loglevel = CONFIG.get('logging.level', 'INFO').upper()
|
2015-06-04 14:43:50 +00:00
|
|
|
loghandler = logging.NullHandler()
|
|
|
|
if logfile:
|
|
|
|
logbackups = CONFIG.get('logging.backup_count', 3, int)
|
|
|
|
logbytes = CONFIG.get('logging.rotate_bytes', 512000, int)
|
|
|
|
loghandler = RotatingFileHandler(os.path.expanduser(logfile), 'a', logbytes, logbackups)
|
|
|
|
loghandler.setFormatter(logging.Formatter(logformat))
|
|
|
|
log.addHandler(loghandler)
|
|
|
|
log.setLevel(loglevel)
|
2017-01-26 06:33:01 +00:00
|
|
|
logfilter = SecretsFilter()
|
|
|
|
if CONFIG.get('logging.show_secrets') != 'true':
|
|
|
|
log.addFilter(logfilter)
|