From 47c7023dbaf5eb6682101b93f76e4c7b8acf4f56 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Apr 2020 20:37:47 +0200 Subject: Add tracks endpoints --- README.md | 8 ++--- pyfunkwhale/funkwhale.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2b1cb57..56c264e 100644 --- a/README.md +++ b/README.md @@ -77,10 +77,10 @@ List of features implemented or planned: - [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 - - [ ] List available user libraries containing work from this track +- [x] Tracks + - [x] List tracks + - [x] Retrieve a single tracks + - [x] List available user libraries containing work from this track - [ ] Download the audio file matching the given track uuid - [ ] License - [ ] List licences diff --git a/pyfunkwhale/funkwhale.py b/pyfunkwhale/funkwhale.py index 0c92e72..c7c543c 100644 --- a/pyfunkwhale/funkwhale.py +++ b/pyfunkwhale/funkwhale.py @@ -109,3 +109,88 @@ class Funkwhale(object): return self.client.call( f'/albums/{_id}/libraries/', 'get', params).json() + + def tracks(self, q: str = None, artist: int = None, ordering: str = None, + playable: bool = None, page: int = None, + page_size: int = None) -> dict: + """ + List tracks + + Parameters + ---------- + q : str, optional + Search query used to filter tracks + artist : int, optional + Only include tracks by the requested artist + favorites : bool, optional + filter/exclude tracks favorited by the current user + album : int, optional + Only include tracks from the requested album + license : str, optional + Only include tracks with the given license + ordering : str, optional + Ordering for the results, prefix with - for DESC ordering + Available values: creation_date, release_date, title + playable : bool, optional + Filter/exclude resources with playable tracks + page : int, optional + Default value: 1 + page_size : int, optional + Default value: 25 + + Raises + ------ + ValueError + If ordering are set with wrong values + """ + + 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('/tracks/', 'get', params).json() + + def track(self, _id: int, refresh: bool = False): + """ + Retrieve a single track + + Parameters + ---------- + _id : int + Object ID + refresh : bool, optional + Trigger an ActivityPub fetch to refresh local data + """ + + arguments = locals() + + params = self._build_params(arguments) + + return self.client.call(f'/tracks/{_id}', 'get', params).json() + + def track_libraries(self, _id: int, page: int = None, + page_size: int = None): + """ + List available user libraries containing work from this track + + Parameters + ---------- + _id : int + Object ID + page : int, optional + Default value: 1 + page_size : int, optional + Default value: 25 + """ + + arguments = locals() + + params = self._build_params(arguments) + + return self.client.call( + f'/tracks/{_id}/libraries/', 'get', params).json() -- cgit v1.2.1