nzbToMedia/nzb2media/plex.py
Labrys of Knossos bfb45c180a Lots of refactoring.
Remove version checks and update logic
Remove extraneous constants: SOURCE_ROOT, SYS_ARGV, APP_FILENAME, CONFIG_MOVIE_FILE, MY_APP, CONFIG_TV_FILE, GIT_*
Remove nzb2media.utils.processes
Update requirements
Flatten project structure
Keep settings close to code
Refactor NZBget, torrent configs, torrents, transcoder, tools, constants and forks
Refactor `nzbToMedia.main` to `nzb2media.app.main`
Fix flake/lint issues
2023-01-03 16:40:36 -05:00

56 lines
1.5 KiB
Python

from __future__ import annotations
import logging
import requests
import nzb2media
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
SSL = None
HOST = None
PORT = None
TOKEN = None
SECTION: list[tuple[str, str]] = []
def configure_plex(config):
global SSL
global HOST
global PORT
global TOKEN
global SECTION
SSL = int(config['Plex']['plex_ssl'])
HOST = config['Plex']['plex_host']
PORT = config['Plex']['plex_port']
TOKEN = config['Plex']['plex_token']
plex_section = config['Plex']['plex_sections'] or []
if plex_section:
if isinstance(plex_section, list):
plex_section = ','.join(plex_section) # fix in case this imported as list.
plex_section = [tuple(item.split(',')) for item in plex_section.split('|')]
SECTION = plex_section
def plex_update(category):
if nzb2media.FAILED:
return
scheme = 'https' if SSL else 'http'
url = f'{scheme}://{HOST}:{PORT}/library/sections/'
section = None
if not SECTION:
return
log.debug(f'Attempting to update Plex Library for category {category}.')
for item in SECTION:
if item[0] == category:
section = item[1]
if section:
url = f'{url}{section}/refresh?X-Plex-Token={TOKEN}'
requests.get(url, timeout=(60, 120), verify=False)
log.debug('Plex Library has been refreshed.')
else:
log.debug('Could not identify SECTION for plex update')