Beets remote backend #338

Closed
wants to merge 9 commits into
from

Projects

None yet

2 participants

@dz0ny
Mopidy member

Related to #336

Issues:

  • Needs optimizations on server side (it requests entire library at once)
@jodal jodal commented on the diff Mar 14, 2013
docs/modules/backends/beets.rst
@@ -0,0 +1,8 @@
+.. _beets-backend:
+
+*************************************************
+:mod:`mopidy.backends.beets` -- Beets backend
+*************************************************
@jodal
jodal Mar 14, 2013

Shorten "***" row to match header text length.

@jodal jodal commented on the diff Mar 14, 2013
mopidy/backends/beets/client.py
@@ -0,0 +1,176 @@
+#!/usr/local/bin/python
+# -*- coding: utf-8 -*-
+#
@jodal
jodal Mar 14, 2013

No need for these three lines.

@jodal jodal commented on the diff Mar 14, 2013
mopidy/backends/beets/library.py
+
+from mopidy import settings
+from mopidy.backends import base
+from mopidy.models import SearchResult
+
+from .client import BeetsRemoteClient
+
+logger = logging.getLogger('mopidy.backends.beets')
+
+
+class BeetsLibraryProvider(base.BaseLibraryProvider):
+ def __init__(self, *args, **kwargs):
+ super(BeetsLibraryProvider, self).__init__(*args, **kwargs)
+ self.remote = BeetsRemoteClient(settings.BEETS_SERVER_URI)
+
+ def find_exact(self, **query):
@jodal
jodal Mar 14, 2013

Is exact matching possible? If yes, add TODO, if no, add docstring documenting it.

@jodal jodal commented on an outdated diff Mar 14, 2013
mopidy/backends/beets/library.py
+
+class BeetsLibraryProvider(base.BaseLibraryProvider):
+ def __init__(self, *args, **kwargs):
+ super(BeetsLibraryProvider, self).__init__(*args, **kwargs)
+ self.remote = BeetsRemoteClient(settings.BEETS_SERVER_URI)
+
+ def find_exact(self, **query):
+ return self.search(**query)
+
+ def search(self, **query):
+ self._validate_query(query)
+ if not query:
+ return SearchResult(uri='beets:search', tracks=self.remote.get_tracks())
+
+ for (field, values) in query.iteritems():
+ if field == "album":
@jodal
jodal Mar 14, 2013

Use single quotes.

@jodal jodal commented on an outdated diff Mar 14, 2013
mopidy/backends/beets/library.py
+ def find_exact(self, **query):
+ return self.search(**query)
+
+ def search(self, **query):
+ self._validate_query(query)
+ if not query:
+ return SearchResult(uri='beets:search', tracks=self.remote.get_tracks())
+
+ for (field, values) in query.iteritems():
+ if field == "album":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_album_by(values[0]))
+ if field == "artist":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_item_by(values[0]))
+ if field == "any":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_item_by(values[0]))
+ else:
@jodal
jodal Mar 14, 2013

Either remove the else and move the raise on level out, or change all the above if-s to elif. Currently it looks strange with the else clausing hanging on the last of multiple if-s, even though the behavior is correct.

@jodal jodal commented on an outdated diff Mar 14, 2013
mopidy/backends/beets/library.py
+ return SearchResult(uri='beets:search', tracks=self.remote.get_tracks())
+
+ for (field, values) in query.iteritems():
+ if field == "album":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_album_by(values[0]))
+ if field == "artist":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_item_by(values[0]))
+ if field == "any":
+ return SearchResult(uri='beets:search', tracks=self.remote.get_item_by(values[0]))
+ else:
+ raise LookupError('Invalid lookup field: %s' % field)
+
+ def lookup(self, uri):
+ try:
+ id = uri.split("//")[1]
+ logger.debug(u'Beets track id for "%s": %s', id, uri)
@jodal
jodal Mar 14, 2013

I think id and uri has been switched here.

@jodal
Mopidy member

Overall, good work nicely following the style of existing Mopidy code! Haven't tested it against Beets myself yet, but I'll have to give it a try. As for SoundCloud, and as mentioned on IRC, tests would be great.

@dz0ny
Mopidy member

Don't merge. I will probably rewrite this backend as extension.

@dz0ny dz0ny closed this Mar 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment