aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2020-04-11 20:37:47 +0200
committerneodarz <neodarz@neodarz.net>2020-04-11 20:37:47 +0200
commit47c7023dbaf5eb6682101b93f76e4c7b8acf4f56 (patch)
treec40eb8533490e234cfbc6fa42891b9080f2bc143
parent74dd9d0fb2534eb290fe6c8e7638480d54e91087 (diff)
downloadpyfunkwhale-47c7023dbaf5eb6682101b93f76e4c7b8acf4f56.tar.xz
pyfunkwhale-47c7023dbaf5eb6682101b93f76e4c7b8acf4f56.zip
Add tracks endpoints
Diffstat (limited to '')
-rw-r--r--README.md8
-rw-r--r--pyfunkwhale/funkwhale.py85
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()