From 764fcc6b4c82aee67efe900546241ff1e41b0155 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Tue, 8 Sep 2015 12:45:19 +0100 Subject: [PATCH] Add `library_name` configuration property --- beetsplug/plexupdate.py | 14 ++++++++------ docs/plugins/plexupdate.rst | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/beetsplug/plexupdate.py b/beetsplug/plexupdate.py index 02ed2324c..340bcdf4d 100644 --- a/beetsplug/plexupdate.py +++ b/beetsplug/plexupdate.py @@ -18,7 +18,7 @@ from beets import config from beets.plugins import BeetsPlugin -def get_music_section(host, port, token): +def get_music_section(host, port, token, library_name): """Getting the section key for the music library in Plex. """ api_endpoint = append_token('library/sections', token) @@ -30,15 +30,15 @@ def get_music_section(host, port, token): # Parse xml tree and extract music section key. tree = ET.fromstring(r.text) for child in tree.findall('Directory'): - if child.get('title') == 'Music': + if child.get('title') == library_name: return child.get('key') -def update_plex(host, port, token): +def update_plex(host, port, token, library_name): """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) + section_key = get_music_section(host, port, token, library_name) api_endpoint = 'library/sections/{0}/refresh'.format(section_key) api_endpoint = append_token(api_endpoint, token) url = urljoin('http://{0}:{1}'.format(host, port), api_endpoint) @@ -64,7 +64,8 @@ class PlexUpdate(BeetsPlugin): config['plex'].add({ u'host': u'localhost', u'port': 32400, - u'token': u''}) + u'token': u'', + u'library_name': u'Music'}) self.register_listener('database_change', self.listen_for_db_change) @@ -82,7 +83,8 @@ class PlexUpdate(BeetsPlugin): update_plex( config['plex']['host'].get(), config['plex']['port'].get(), - config['plex']['token'].get()) + config['plex']['token'].get(), + config['plex']['library_name'].get()) self._log.info('... started.') except requests.exceptions.RequestException: diff --git a/docs/plugins/plexupdate.rst b/docs/plugins/plexupdate.rst index f99e6de66..4ac047660 100644 --- a/docs/plugins/plexupdate.rst +++ b/docs/plugins/plexupdate.rst @@ -39,3 +39,5 @@ The available options under the ``plex:`` section are: Default: 32400. - **token**: The Plex Home token. Default: Empty. +- **library_name**: The name of the Plex library to update. + Default: ``Music``