Skip to content

Commit

Permalink
Merge pull request #1595 from jackwilsdon/add-plex-library-config
Browse files Browse the repository at this point in the history
Add `library_name` configuration property to PlexUpdate plugin (fixes #1572)
  • Loading branch information
sampsyo committed Sep 10, 2015
2 parents 225ba28 + 40f9f65 commit c7603fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
14 changes: 8 additions & 6 deletions beetsplug/plexupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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)
Expand All @@ -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)
Expand All @@ -64,7 +64,8 @@ def __init__(self):
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)

Expand All @@ -82,7 +83,8 @@ def update(self, lib):
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:
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The new features:
:bug:`1591` :bug:`733`
* :doc:`/plugins/play`: You can now configure the number of tracks that
trigger a "lots of music" warning. :bug:`1577`
* :doc:`/plugins/plexupdate`: A new ``library_name`` option allows you to select
which Plex library to update. :bug:`1572` :bug:`1595`

Fixes:

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/plexupdate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
6 changes: 4 additions & 2 deletions test/test_plexupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def test_get_music_section(self):
self.assertEqual(get_music_section(
self.config['plex']['host'],
self.config['plex']['port'],
self.config['plex']['token']), '2')
self.config['plex']['token'],
self.config['plex']['library_name'].get()), '2')

@responses.activate
def test_update_plex(self):
Expand All @@ -100,7 +101,8 @@ def test_update_plex(self):
self.assertEqual(update_plex(
self.config['plex']['host'],
self.config['plex']['port'],
self.config['plex']['token']).status_code, 200)
self.config['plex']['token'],
self.config['plex']['library_name'].get()).status_code, 200)


def suite():
Expand Down

0 comments on commit c7603fc

Please sign in to comment.