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
29490324
Commit
29490324
authored
Jul 01, 2020
by
Agate
💬
Browse files
Merge branch 'browse_libs' into 'master'
Support library browsing See merge request
!7
parents
3b26b1df
e4227b43
Pipeline
#11237
passed with stage
in 1 minute and 17 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
mopidy_funkwhale/client.py
View file @
29490324
...
...
@@ -141,6 +141,11 @@ class APIClient(object):
response
.
raise_for_status
()
return
response
.
json
()
def
list_libraries
(
self
,
filters
):
response
=
self
.
session
.
get
(
"libraries/"
,
params
=
filters
)
response
.
raise_for_status
()
return
response
.
json
()
def
load_all
(
self
,
first_page
,
max
=
0
):
for
i
in
first_page
[
"results"
]:
yield
i
...
...
mopidy_funkwhale/library.py
View file @
29490324
...
...
@@ -69,6 +69,7 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
self
.
vfs
=
{
"funkwhale:directory"
:
collections
.
OrderedDict
()}
self
.
add_to_vfs
(
new_folder
(
"Favorites"
,
"favorites"
))
self
.
add_to_vfs
(
new_folder
(
"Artists"
,
"artists"
))
self
.
add_to_vfs
(
new_folder
(
"Libraries"
,
"libraries"
))
# self.add_to_vfs(new_folder('Following', ['following']))
# self.add_to_vfs(new_folder('Sets', ['sets']))
# self.add_to_vfs(new_folder('Stream', ['stream']))
...
...
@@ -123,6 +124,7 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
return
[],
False
def
browse_albums
(
self
,
uri_prefix
,
remaining
):
logger
.
debug
(
"Handling albums route: %s"
,
remaining
)
if
len
(
remaining
)
==
2
:
album
=
remaining
[
1
]
payload
=
self
.
backend
.
client
.
list_tracks
(
...
...
@@ -225,8 +227,35 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
]
return
artists
,
True
if
root
==
"by-library"
:
logger
.
debug
(
"Handling artists by lib route: %s"
,
end
)
if
len
(
end
)
==
1
:
payload
=
self
.
backend
.
client
.
list_artists
(
{
"ordering"
:
"name"
,
"page_size"
:
50
,
"library"
:
end
}
)
uri_prefix
=
"funkwhale:directory:artists:by-name"
artists
=
[
convert_to_artist
(
row
,
uri_prefix
=
uri_prefix
,
ref
=
True
)
for
row
in
self
.
backend
.
client
.
load_all
(
payload
)
]
return
artists
,
True
return
[],
False
def
browse_libraries
(
self
,
remaining
):
logger
.
debug
(
"Handling libraries route: %s"
,
remaining
)
payload
=
self
.
backend
.
client
.
list_libraries
(
{
"ordering"
:
"name"
,
"page_size"
:
50
}
)
uri_prefix
=
"funkwhale:directory:artists:by-library"
libraries
=
[
convert_to_ref
(
row
,
uri_prefix
=
uri_prefix
)
for
row
in
self
.
backend
.
client
.
load_all
(
payload
)
]
return
libraries
,
True
def
search
(
self
,
query
=
None
,
uris
=
None
,
exact
=
False
):
# TODO Support exact search
if
not
query
:
...
...
@@ -337,6 +366,17 @@ def convert_to_track(payload, uri_prefix="funkwhale:tracks"):
)
def
convert_to_ref
(
payload
,
uri_prefix
=
"funkwhale:libraries"
):
try
:
upload
=
payload
[
"uploads"
][
0
]
except
(
KeyError
,
IndexError
):
upload
=
{}
return
models
.
Ref
(
uri
=
uri_prefix
+
":%s"
%
payload
[
"uuid"
],
name
=
payload
[
"name"
],
)
def
to_ref
(
obj
):
getter
=
getattr
(
models
.
Ref
,
obj
.
__class__
.
__name__
.
lower
())
return
getter
(
uri
=
obj
.
uri
,
name
=
obj
.
name
)
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