2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-02-20 05:37:00 +00:00
|
|
|
import logging
|
|
|
|
import 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')
|
2017-02-20 03:18:23 +00:00
|
|
|
CONFIG_PATH = os.environ.get('PLEXAPI_CONFIG_PATH', DEFAULT_CONFIG_PATH)
|
2015-06-02 02:27:43 +00:00
|
|
|
CONFIG = PlexConfig(CONFIG_PATH)
|
|
|
|
|
2017-02-20 03:18:23 +00:00
|
|
|
# PlexAPI Settings
|
|
|
|
PROJECT = 'PlexAPI'
|
2020-05-11 02:27:04 +00:00
|
|
|
VERSION = '3.5.0'
|
2017-02-20 03:18:23 +00:00
|
|
|
TIMEOUT = CONFIG.get('plexapi.timeout', 30, int)
|
2017-11-01 23:25:43 +00:00
|
|
|
X_PLEX_CONTAINER_SIZE = CONFIG.get('plexapi.container_size', 100, int)
|
2018-09-14 18:28:35 +00:00
|
|
|
X_PLEX_ENABLE_FAST_CONNECT = CONFIG.get('plexapi.enable_fast_connect', False, bool)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
# Plex Header Configuation
|
2017-02-20 03:18:23 +00:00
|
|
|
X_PLEX_PROVIDES = CONFIG.get('header.provides', 'controller')
|
2018-09-08 15:27:54 +00:00
|
|
|
X_PLEX_PLATFORM = CONFIG.get('header.platform', CONFIG.get('header.platorm', uname()[0]))
|
2017-02-20 03:18:23 +00:00
|
|
|
X_PLEX_PLATFORM_VERSION = CONFIG.get('header.platform_version', uname()[2])
|
|
|
|
X_PLEX_PRODUCT = CONFIG.get('header.product', PROJECT)
|
|
|
|
X_PLEX_VERSION = CONFIG.get('header.version', VERSION)
|
|
|
|
X_PLEX_DEVICE = CONFIG.get('header.device', X_PLEX_PLATFORM)
|
|
|
|
X_PLEX_DEVICE_NAME = CONFIG.get('header.device_name', uname()[1])
|
|
|
|
X_PLEX_IDENTIFIER = CONFIG.get('header.identifier', str(hex(getnode())))
|
2016-03-16 03:47:13 +00:00
|
|
|
BASE_HEADERS = reset_base_headers()
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
# Logging Configuration
|
|
|
|
log = logging.getLogger('plexapi')
|
2017-02-20 03:18:23 +00:00
|
|
|
logfile = CONFIG.get('log.path')
|
|
|
|
logformat = CONFIG.get('log.format', '%(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s')
|
|
|
|
loglevel = CONFIG.get('log.level', 'INFO').upper()
|
2015-06-04 14:43:50 +00:00
|
|
|
loghandler = logging.NullHandler()
|
2017-10-28 22:40:35 +00:00
|
|
|
|
|
|
|
if logfile: # pragma: no cover
|
2017-02-20 03:18:23 +00:00
|
|
|
logbackups = CONFIG.get('log.backup_count', 3, int)
|
|
|
|
logbytes = CONFIG.get('log.rotate_bytes', 512000, int)
|
2015-06-04 14:43:50 +00:00
|
|
|
loghandler = RotatingFileHandler(os.path.expanduser(logfile), 'a', logbytes, logbackups)
|
2017-10-28 22:40:35 +00:00
|
|
|
|
2015-06-04 14:43:50 +00:00
|
|
|
loghandler.setFormatter(logging.Formatter(logformat))
|
|
|
|
log.addHandler(loghandler)
|
|
|
|
log.setLevel(loglevel)
|
2017-01-26 06:33:01 +00:00
|
|
|
logfilter = SecretsFilter()
|
2017-02-22 06:22:10 +00:00
|
|
|
if CONFIG.get('log.show_secrets', '').lower() != 'true':
|
2017-01-26 06:33:01 +00:00
|
|
|
log.addFilter(logfilter)
|