Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
funkwhale
mopidy
Commits
21bdb99d
Commit
21bdb99d
authored
Sep 25, 2020
by
Agate
💬
Browse files
Merge branch 'library-cover-images' into 'master'
Add `library.get_images()` support for cover art See merge request
!11
parents
7437b176
d9cd25b5
Pipeline
#12245
passed with stages
in 3 minutes and 55 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
mopidy_funkwhale/library.py
View file @
21bdb99d
...
...
@@ -255,6 +255,41 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
]
return
libraries
,
True
def
get_images
(
self
,
uris
):
logger
.
debug
(
"Handling get images: %s"
,
uris
)
result
=
{}
for
uri
in
uris
:
track_id
=
uri
.
split
(
":"
)[
-
1
]
cache_key
=
"funkwhale:images:%s"
%
track_id
from_cache
=
self
.
cache
.
get
(
cache_key
)
if
from_cache
:
result
[
uri
]
=
from_cache
continue
payload
=
self
.
backend
.
client
.
get_track
(
track_id
)
if
not
payload
[
"album"
][
"cover"
]:
continue
result
[
uri
]
=
[]
for
type
,
cover_url
in
payload
[
"album"
][
"cover"
][
"urls"
].
items
():
if
not
cover_url
:
continue
if
type
==
"large_square_crop"
:
image
=
models
.
Image
(
uri
=
cover_url
,
width
=
600
,
height
=
600
)
elif
type
==
"medium_square_crop"
:
image
=
models
.
Image
(
uri
=
cover_url
,
width
=
200
,
height
=
200
)
else
:
image
=
models
.
Image
(
uri
=
cover_url
)
result
[
uri
].
append
(
image
)
self
.
cache
.
set
(
cache_key
,
result
[
uri
])
return
result
def
search
(
self
,
query
=
None
,
uris
=
None
,
exact
=
False
):
# TODO Support exact search
...
...
@@ -333,8 +368,6 @@ def convert_to_artist(payload, uri_prefix="funkwhale:artists"):
@
cast_to_ref
def
convert_to_album
(
payload
,
uri_prefix
=
"funkwhale:albums"
):
artist
=
convert_to_artist
(
payload
[
"artist"
])
image
=
payload
[
"cover"
][
"original"
]
if
payload
[
"cover"
]
else
None
return
models
.
Album
(
uri
=
uri_prefix
+
":%s"
%
payload
[
"id"
],
name
=
payload
[
"title"
],
...
...
@@ -349,6 +382,7 @@ def convert_to_album(payload, uri_prefix="funkwhale:albums"):
def
convert_to_track
(
payload
,
uri_prefix
=
"funkwhale:tracks"
):
artist
=
convert_to_artist
(
payload
[
"artist"
])
album
=
convert_to_album
(
payload
[
"album"
])
try
:
upload
=
payload
[
"uploads"
][
0
]
except
(
KeyError
,
IndexError
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment