From 74dd9d0fb2534eb290fe6c8e7638480d54e91087 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Apr 2020 20:24:16 +0200 Subject: Add albums endpoints --- README.md | 8 ++++---- pyfunkwhale/funkwhale.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 77b14e1..2b1cb57 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,10 @@ List of features implemented or planned: - [x] List artists - [x] Retrieve a single artist - [x] List available user libraries containing work from this artist -- [ ] Albums - - [ ] List albums - - [ ] Retrieve a single album - - [ ] List available user libraries containing work from this album +- [x] Albums + - [x] List albums + - [x] Retrieve a single album + - [x] List available user libraries containing work from this album - [ ] Tracks - [ ] List tracks - [ ] Retrieve a single tracks diff --git a/pyfunkwhale/funkwhale.py b/pyfunkwhale/funkwhale.py index fc1b4d6..0c92e72 100644 --- a/pyfunkwhale/funkwhale.py +++ b/pyfunkwhale/funkwhale.py @@ -67,3 +67,45 @@ class Funkwhale(object): return self.client.call( f'/artists/{_id}/libraries/', 'get', params).json() + + def albums(self, q: str = None, artist: int = None, ordering: str = None, + playable: bool = None, page: int = None, + page_size: int = None) -> dict: + """ + List albums + """ + + arguments = locals() + + ordering_field = ['creation_date', 'release_date', 'title'] + if ordering is not None and ordering not in ordering_field: + raise ValueError("The ordering field {} is not in the ordering" + "fields accepted".format(ordering)) + + params = self._build_params(arguments) + + return self.client.call('/albums/', 'get', params).json() + + def album(self, _id: int, refresh: bool = False): + """ + Retrieve a single album + """ + + arguments = locals() + + params = self._build_params(arguments) + + return self.client.call(f'/albums/{_id}', 'get', params).json() + + def album_libraries(self, _id: int, page: int = None, + page_size: int = None): + """ + List available user libraries containing work from this album + """ + + arguments = locals() + + params = self._build_params(arguments) + + return self.client.call( + f'/albums/{_id}/libraries/', 'get', params).json() -- cgit v1.2.1