mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Update vendored beets to 1.6.0
Updates colorama to 0.4.6 Adds confuse version 1.7.0 Updates jellyfish to 0.9.0 Adds mediafile 0.10.1 Updates munkres to 1.1.4 Updates musicbrainzngs to 0.7.1 Updates mutagen to 1.46.0 Updates pyyaml to 6.0 Updates unidecode to 1.3.6
This commit is contained in:
parent
5073ec0c6f
commit
56c6773c6b
385 changed files with 25143 additions and 18080 deletions
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Updates an Plex library whenever the beets library is changed.
|
||||
|
||||
Plex Home users enter the Plex Token to enable updating.
|
||||
|
@ -9,42 +7,51 @@ Put something like the following in your config.yaml to configure:
|
|||
port: 32400
|
||||
token: token
|
||||
"""
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
import requests
|
||||
import xml.etree.ElementTree as ET
|
||||
from six.moves.urllib.parse import urljoin, urlencode
|
||||
from xml.etree import ElementTree
|
||||
from urllib.parse import urljoin, urlencode
|
||||
from beets import config
|
||||
from beets.plugins import BeetsPlugin
|
||||
|
||||
|
||||
def get_music_section(host, port, token, library_name):
|
||||
def get_music_section(host, port, token, library_name, secure,
|
||||
ignore_cert_errors):
|
||||
"""Getting the section key for the music library in Plex.
|
||||
"""
|
||||
api_endpoint = append_token('library/sections', token)
|
||||
url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)
|
||||
url = urljoin('{}://{}:{}'.format(get_protocol(secure), host,
|
||||
port), api_endpoint)
|
||||
|
||||
# Sends request.
|
||||
r = requests.get(url)
|
||||
r = requests.get(url, verify=not ignore_cert_errors)
|
||||
|
||||
# Parse xml tree and extract music section key.
|
||||
tree = ET.fromstring(r.content)
|
||||
tree = ElementTree.fromstring(r.content)
|
||||
for child in tree.findall('Directory'):
|
||||
if child.get('title') == library_name:
|
||||
return child.get('key')
|
||||
|
||||
|
||||
def update_plex(host, port, token, library_name):
|
||||
def update_plex(host, port, token, library_name, secure,
|
||||
ignore_cert_errors):
|
||||
"""Ignore certificate errors if configured to.
|
||||
"""
|
||||
if ignore_cert_errors:
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
"""Sends request to the Plex api to start a library refresh.
|
||||
"""
|
||||
# Getting section key and build url.
|
||||
section_key = get_music_section(host, port, token, library_name)
|
||||
api_endpoint = 'library/sections/{0}/refresh'.format(section_key)
|
||||
section_key = get_music_section(host, port, token, library_name,
|
||||
secure, ignore_cert_errors)
|
||||
api_endpoint = f'library/sections/{section_key}/refresh'
|
||||
api_endpoint = append_token(api_endpoint, token)
|
||||
url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint)
|
||||
url = urljoin('{}://{}:{}'.format(get_protocol(secure), host,
|
||||
port), api_endpoint)
|
||||
|
||||
# Sends request and returns requests object.
|
||||
r = requests.get(url)
|
||||
r = requests.get(url, verify=not ignore_cert_errors)
|
||||
return r
|
||||
|
||||
|
||||
|
@ -56,16 +63,25 @@ def append_token(url, token):
|
|||
return url
|
||||
|
||||
|
||||
def get_protocol(secure):
|
||||
if secure:
|
||||
return 'https'
|
||||
else:
|
||||
return 'http'
|
||||
|
||||
|
||||
class PlexUpdate(BeetsPlugin):
|
||||
def __init__(self):
|
||||
super(PlexUpdate, self).__init__()
|
||||
super().__init__()
|
||||
|
||||
# Adding defaults.
|
||||
config['plex'].add({
|
||||
u'host': u'localhost',
|
||||
u'port': 32400,
|
||||
u'token': u'',
|
||||
u'library_name': u'Music'})
|
||||
'host': 'localhost',
|
||||
'port': 32400,
|
||||
'token': '',
|
||||
'library_name': 'Music',
|
||||
'secure': False,
|
||||
'ignore_cert_errors': False})
|
||||
|
||||
config['plex']['token'].redact = True
|
||||
self.register_listener('database_change', self.listen_for_db_change)
|
||||
|
@ -77,7 +93,7 @@ class PlexUpdate(BeetsPlugin):
|
|||
def update(self, lib):
|
||||
"""When the client exists try to send refresh request to Plex server.
|
||||
"""
|
||||
self._log.info(u'Updating Plex library...')
|
||||
self._log.info('Updating Plex library...')
|
||||
|
||||
# Try to send update request.
|
||||
try:
|
||||
|
@ -85,8 +101,10 @@ class PlexUpdate(BeetsPlugin):
|
|||
config['plex']['host'].get(),
|
||||
config['plex']['port'].get(),
|
||||
config['plex']['token'].get(),
|
||||
config['plex']['library_name'].get())
|
||||
self._log.info(u'... started.')
|
||||
config['plex']['library_name'].get(),
|
||||
config['plex']['secure'].get(bool),
|
||||
config['plex']['ignore_cert_errors'].get(bool))
|
||||
self._log.info('... started.')
|
||||
|
||||
except requests.exceptions.RequestException:
|
||||
self._log.warning(u'Update failed.')
|
||||
self._log.warning('Update failed.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue