Commit 8adc50aa authored by Agate's avatar Agate 💬

Merge branch 'library-albums' into 'master'

Add support for browsing albums (#7)

See merge request !10
parents 21bdb99d c7dfdb58
Pipeline #12246 passed with stages
in 3 minutes and 20 seconds
......@@ -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("Albums", "albums"))
self.add_to_vfs(new_folder("Libraries", "libraries"))
# self.add_to_vfs(new_folder('Following', ['following']))
# self.add_to_vfs(new_folder('Sets', ['sets']))
......@@ -123,8 +124,60 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
return tracks, True
return [], False
def browse_albums(self, uri_prefix, remaining):
def browse_albums(self, remaining, uri_prefix=""):
logger.debug("Handling albums route: %s", remaining)
if remaining == []:
return (
[
new_folder("Recent", "albums:recent"),
new_folder("By name", "albums:by-name"),
new_folder("Own Content", "albums:scope-me"),
],
False,
)
if remaining == ["recent"]:
# list recent albums
payload = self.backend.client.list_albums(
{"ordering": "-creation_date", "page_size": 50, "playable": "true"}
)
uri_prefix = "funkwhale:directory:albums:recent"
albums = [
convert_to_album(row, uri_prefix=uri_prefix, ref=True)
for row in self.backend.client.load_all(payload, max=1)
]
return albums, True
if remaining == ["by-name"]:
# list all albums sorted by name
payload = self.backend.client.list_albums(
{"ordering": "title", "page_size": 50, "playable": "true"}
)
uri_prefix = "funkwhale:directory:albums:by-name"
albums = [
convert_to_album(row, uri_prefix=uri_prefix, ref=True)
for row in self.backend.client.load_all(payload)
]
return albums, True
if remaining == ["scope-me"]:
# list all albums self uploaded
payload = self.backend.client.list_albums(
{"ordering": "title", "page_size": 50, "scope": "me"}
)
uri_prefix = "funkwhale:directory:albums:scope-me"
albums = [
convert_to_album(row, uri_prefix=uri_prefix, ref=True)
for row in self.backend.client.load_all(payload)
]
return albums, True
if len(remaining) == 2:
album = remaining[1]
payload = self.backend.client.list_tracks(
......@@ -139,7 +192,7 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
convert_to_track(row, ref=True, cache=self.cache)
for row in self.backend.client.load_all(payload)
]
return tracks
return tracks, True
else:
artist, album = remaining[0], None
payload = self.backend.client.list_albums(
......@@ -154,7 +207,7 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
convert_to_album(row, uri_prefix=uri_prefix, ref=True)
for row in self.backend.client.load_all(payload)
]
return albums
return albums, True
def browse_artists(self, remaining):
logger.debug("Handling artist route: %s", remaining)
......@@ -176,10 +229,8 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
if root == "recent":
if end:
# list albums
return (
self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end),
True,
)
return self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end)
# list recent artists
payload = self.backend.client.list_artists(
{"ordering": "-creation_date", "page_size": 50, "playable": "true"}
......@@ -195,10 +246,8 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
if root == "by-name":
if end:
# list albums
return (
self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end),
True,
)
return self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end)
# list recent artists
payload = self.backend.client.list_artists(
{"ordering": "name", "page_size": 50, "playable": "true"}
......@@ -213,10 +262,8 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider):
if root == "scope-me":
if end:
# list albums
return (
self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end),
True
)
return self.browse_albums(uri_prefix=albums_uri_prefix, remaining=end)
payload = self.backend.client.list_artists(
{"ordering": "name", "page_size": 50, "scope": "me"}
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment