Repository: beetbox/beets

Issue:
plexupdate: Doesn't work with libaries not named "Music"
I've named my music libaries `Music (New)` and `Music (Untagged)`. The plex update plugin should update the `Music (New)` section, but instead of updating at least both music libaries it doesn't update anything. If I change the library name from `Music (New)` to `Music` it works like a charm. This is specified on line 33 of the beets plugin. A config option to add libraries other than `Music` would make sense imo.



Discussion:
Odd—did the body of this issue get deleted somehow?

EDIT: Oops; sorry. My browser was displaying the page wrong and I thought the text had disappeared. :flushed:

Sounds quite reasonable!

Yeah, I'm sorry. The initial body of this issue consist of just the problem with the plex update plugin (and my config file etc.), but after some research I've found the real issue which is far more useful I think.


Resolving patch:
diff --git a/beetsplug/plexupdate.py b/beetsplug/plexupdate.py
--- a/beetsplug/plexupdate.py
+++ b/beetsplug/plexupdate.py
@@ -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)
@@ -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 @@ 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)
 
@@ -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:


Test patch:
diff --git a/test/test_plexupdate.py b/test/test_plexupdate.py
--- a/test/test_plexupdate.py
+++ b/test/test_plexupdate.py
@@ -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):
@@ -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():