Skip to content

Commit

Permalink
add back exact for album_songs and fix other ones
Browse files Browse the repository at this point in the history
Enable backwards compatability with api < 6
  • Loading branch information
lachlan-00 committed Mar 31, 2023
1 parent bd261c4 commit b9b8ec0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/json-responses/browse.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"basename": "upload"
}
]
}
}
75 changes: 42 additions & 33 deletions src/ampache.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,7 @@ def url_to_song(self, url):
return False
return self.return_data(ampache_response)

def get_similar(self, object_type, filter_id: int,
offset=0, limit=0):
def get_similar(self, object_type, filter_id: int, offset=0, limit=0):
""" get_similar
MINIMUM_API_VERSION=420000
Expand All @@ -596,9 +595,8 @@ def get_similar(self, object_type, filter_id: int,
return False
return self.return_data(ampache_response)

def list(self, object_type,
filter_str: str = False, exact: int = False, add: int = False, update: int = False,
offset=0, limit=0):
def list(self, object_type, filter_str: str = False,
exact: int = False, add: int = False, update: int = False, offset=0, limit=0):
""" list
MINIMUM_API_VERSION=600000
Expand All @@ -625,6 +623,8 @@ def list(self, object_type,
'limit': str(limit)}
if not filter_str:
data.pop('filter')
if not exact:
data.pop('exact')
if not add:
data.pop('add')
if not update:
Expand All @@ -636,8 +636,9 @@ def list(self, object_type,
return False
return self.return_data(ampache_response)

def browse(self, filter_str: str = False, object_type: str = False, catalog: int = False, add: int = False,
update: int = False, offset=0, limit=0):
def browse(self, filter_str: str = False,
object_type: str = False, catalog: int = False, add: int = False, update: int = False,
offset=0, limit=0):
""" browse
MINIMUM_API_VERSION=6.0.0
Expand Down Expand Up @@ -680,9 +681,8 @@ def browse(self, filter_str: str = False, object_type: str = False, catalog: int
return False
return self.return_data(ampache_response)

def get_indexes(self, object_type,
filter_str: str = False, exact: int = False, add: int = False, update: int = False,
include=False, offset=0, limit=0):
def get_indexes(self, object_type, filter_str: str = False,
exact: int = False, add: int = False, update: int = False, include: int = False, offset=0, limit=0):
""" get_indexes
MINIMUM_API_VERSION=400001
Expand All @@ -699,10 +699,6 @@ def get_indexes(self, object_type,
* limit = (integer) //optional
"""
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
if bool(include):
include = 1
else:
include = 0
data = {'action': 'get_indexes',
'auth': self.AMPACHE_SESSION,
'type': object_type,
Expand All @@ -715,6 +711,8 @@ def get_indexes(self, object_type,
'limit': str(limit)}
if not filter_str:
data.pop('filter')
if not exact:
data.pop('exact')
if not add:
data.pop('add')
if not update:
Expand All @@ -729,7 +727,7 @@ def get_indexes(self, object_type,
return self.return_data(ampache_response)

def artists(self, filter_str: str = False,
add: int = False, update: int = False, offset=0, limit=0, include=False, album_artist=False):
add: int = False, update: int = False, offset=0, limit=0, include=False, album_artist: int = False):
""" artists
MINIMUM_API_VERSION=380001
Expand Down Expand Up @@ -848,7 +846,7 @@ def artist_songs(self, filter_id: int, offset=0, limit=0):
return self.return_data(ampache_response)

def albums(self, filter_str: str = False,
exact=False, add: int = False, update: int = False, offset=0, limit=0,
exact: int = False, add: int = False, update: int = False, offset=0, limit=0,
include=False):
""" albums
MINIMUM_API_VERSION=380001
Expand Down Expand Up @@ -878,6 +876,8 @@ def albums(self, filter_str: str = False,
'include': include}
if not filter_str:
data.pop('filter')
if not exact:
data.pop('exact')
if not add:
data.pop('add')
if not update:
Expand Down Expand Up @@ -917,7 +917,8 @@ def album(self, filter_id: int, include=False):
return False
return self.return_data(ampache_response)

def album_songs(self, filter_id: int, offset=0, limit=0):
def album_songs(self, filter_id: int, offset=0, limit=0,
exact: int = False):
""" album_songs
MINIMUM_API_VERSION=380001
Expand All @@ -927,13 +928,21 @@ def album_songs(self, filter_id: int, offset=0, limit=0):
* filter_id = (integer) $album_id
* offset = (integer) //optional
* limit = (integer) //optional
* exact = (integer) 0,1, if true don't group songs from different disks //optional (IGNORED IN API6)
"""
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
if bool(exact):
exact = 1
else:
exact = 0
data = {'action': 'album_songs',
'auth': self.AMPACHE_SESSION,
'filter': filter_id,
'exact': exact,
'offset': str(offset),
'limit': str(limit)}
if not exact:
data.pop('exact')
data = urllib.parse.urlencode(data)
full_url = ampache_url + '?' + data
ampache_response = self.fetch_url(full_url, self.AMPACHE_API, 'album_songs')
Expand All @@ -957,8 +966,8 @@ def genres(self, filter_str: str = False,
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
data = {'action': 'genres',
'auth': self.AMPACHE_SESSION,
'exact': exact,
'filter': filter_str,
'exact': exact,
'offset': str(offset),
'limit': str(limit)}
if not filter_str:
Expand Down Expand Up @@ -1064,8 +1073,8 @@ def genre_songs(self, filter_id: int, offset=0, limit=0):
return False
return self.return_data(ampache_response)

def songs(self, filter_str: str = False, exact: int = False,
add: int = False, update: int = False, offset=0, limit=0):
def songs(self, filter_str: str = False,
exact: int = False, add: int = False, update: int = False, offset=0, limit=0):
""" songs
MINIMUM_API_VERSION=380001
Expand Down Expand Up @@ -1143,8 +1152,8 @@ def song_delete(self, filter_id: int):
return False
return self.return_data(ampache_response)

def playlists(self, filter_str: str = False, exact: int = False, offset=0, limit=0, hide_search: int = False,
show_dupes: int = False):
def playlists(self, filter_str: str = False,
exact: int = False, offset=0, limit=0, hide_search: int = False, show_dupes: int = False):
""" playlists
MINIMUM_API_VERSION=380001
Expand All @@ -1161,8 +1170,8 @@ def playlists(self, filter_str: str = False, exact: int = False, offset=0, limit
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
data = {'action': 'playlists',
'auth': self.AMPACHE_SESSION,
'exact': exact,
'filter': filter_str,
'exact': exact,
'offset': str(offset),
'limit': str(limit),
'hide_search': hide_search,
Expand Down Expand Up @@ -1487,8 +1496,8 @@ def share_create(self, filter_id: int, object_type,
return False
return self.return_data(ampache_response)

def share_edit(self, filter_id: int, can_stream=False, can_download=False,
expires=False, description=False):
def share_edit(self, filter_id: int, can_stream: int = False, can_download: int = False,
expires: int = False, description=False):
""" share_edit
MINIMUM_API_VERSION=420000
Expand Down Expand Up @@ -2049,7 +2058,7 @@ def video(self, filter_id: int):
return False
return self.return_data(ampache_response)

def localplay(self, command, oid=False, otype=False, clear=0):
def localplay(self, command, oid: int = False, otype=False, clear: int = False):
""" localplay
MINIMUM_API_VERSION=380001
CHANGED_IN_API_VERSION=5.0.0
Expand Down Expand Up @@ -2883,8 +2892,8 @@ def preference_delete(self, filter_str):
return False
return self.return_data(ampache_response)

def licenses(self, filter_str: str = False, exact: int = False,
add: int = False, update: int = False, offset=0, limit=0):
def licenses(self, filter_str: str = False,
exact: int = False, add: int = False, update: int = False, offset=0, limit=0):
""" licenses
MINIMUM_API_VERSION=420000
Expand Down Expand Up @@ -2962,8 +2971,8 @@ def license_songs(self, filter_id: int):
return False
return self.return_data(ampache_response)

def live_streams(self, filter_str: str = False, exact: int = False,
offset=0, limit=0):
def live_streams(self, filter_str: str = False,
exact: int = False, offset=0, limit=0):
""" live_streams
MINIMUM_API_VERSION=5.1.0
Expand Down Expand Up @@ -3104,8 +3113,8 @@ def live_stream_delete(self, filter_id: int):
return False
return self.return_data(ampache_response)

def labels(self, filter_str: str = False, exact: int = False,
offset=0, limit=0):
def labels(self, filter_str: str = False,
exact: int = False, offset=0, limit=0):
""" labels
MINIMUM_API_VERSION=420000
Expand All @@ -3120,8 +3129,8 @@ def labels(self, filter_str: str = False, exact: int = False,
ampache_url = self.AMPACHE_URL + '/server/' + self.AMPACHE_API + '.server.php'
data = {'action': 'labels',
'auth': self.AMPACHE_SESSION,
'exact': exact,
'filter': filter_str,
'exact': exact,
'offset': str(offset),
'limit': str(limit)}
if not filter_str:
Expand Down

0 comments on commit b9b8ec0

Please sign in to comment.