Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for exposing cover art via library.get_images() #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mopidy_beets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class BeetsExtension(ext.Extension):

dist_name = "Mopidy-Beets"
ext_name = "beets"
version = __version__
Expand Down
1 change: 0 additions & 1 deletion mopidy_beets/browsers/albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class AlbumsCategoryBrowser(GenericBrowserBase):

field = None
sort_fields = None
label_fields = None
Expand Down
4 changes: 2 additions & 2 deletions mopidy_beets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def quote_and_encode(text):

@cache()
def get_artists(self):
""" returns all artists of one or more tracks """
"""returns all artists of one or more tracks"""
names = self._get("/artist/")["artist_names"]
names.sort()
# remove empty names
Expand All @@ -216,7 +216,7 @@ def get_sorted_unique_album_attributes(self, field):

@cache(ctl=32)
def _get_unique_attribute_values(self, base_url, field, sort_field):
""" returns all artists, genres, ... of tracks or albums """
"""returns all artists, genres, ... of tracks or albums"""
if not hasattr(self, "__legacy_beets_api_detected"):
try:
result = self._get(
Expand Down
12 changes: 10 additions & 2 deletions mopidy_beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class BeetsLibraryProvider(backend.LibraryProvider):

root_directory = models.Ref.directory(
uri="beets:library", name="Beets library"
)
Expand Down Expand Up @@ -95,7 +94,7 @@ def search(self, query=None, uris=None, exact=False):

self._validate_query(query)
search_list = []
for (field, values) in query.items():
for field, values in query.items():
for val in values:
# missing / unsupported fields: uri, performer
if field == "any":
Expand Down Expand Up @@ -177,6 +176,15 @@ def lookup(self, uri=None, uris=None):
# the newer method (mopidy>=1.0): return a dict of uris and tracks
return {uri: self.lookup(uri=uri) for uri in uris}

def get_images(self, uris):
images = {}
for uri in uris:
path, item_id = parse_uri(uri, uri_prefix=self.root_directory.uri)
if path == "album" and isinstance(item_id, int):
url = self.remote.get_album_art_url(item_id)
images[uri] = [models.Image(uri=url)]
return images

def get_distinct(self, field, query=None):
logger.debug("Beets distinct query: %s (uri=%s)", field, query)
if not self.remote.has_connection:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ select =
# pep8-naming rules
N
ignore =
# B019: Use of `functools.lru_cache` on methods can lead to memory leaks.
B019
# E203: whitespace before ':' (not PEP8 compliant)
E203
# E501: line too long (replaced by B950)
Expand Down