added pagination for albums

This commit is contained in:
gordielachance
2016-10-01 00:17:55 +02:00
parent 86888b5a7a
commit a6c18a2eb0
2 changed files with 49 additions and 17 deletions

View File

@ -380,7 +380,7 @@ class SubsonicClient(libsonic.Connection):
for genre in response["genres"]["genre"]:
yield genre
def walk_albums(self, ltype, size=None, from_year=None,to_year=None, genre=None):
def walk_albums(self, ltype, size=None, from_year=None,to_year=None, genre=None, offset=None):
"""
Request all albums for a given genre and iterate over each album.
"""
@ -390,20 +390,16 @@ class SubsonicClient(libsonic.Connection):
if ltype == 'byYear' and (from_year is None or to_year is None):
return
offset = 0
while True:
response = self.getAlbumList2(
ltype=ltype, genre=genre, size=size, offset=offset)
response = self.getAlbumList2(
ltype=ltype, genre=genre, size=size, offset=offset)
if not response["albumList2"]["album"]:
break
if not response["albumList2"]["album"]:
return
for album in response["albumList2"]["album"]:
yield album
for album in response["albumList2"]["album"]:
yield album
offset += size
def walk_album(self, album_id):
"""