def get_tracks_by_album_id(self, album_id):
self.logger.info("Get tracks of the album(" +
album_id + ") from Spotify.")
if not album_id:
return None
offset = 0
tracks = []
while True:
params = {
"offset": offset,
"limit": 50
}
buf = BytesIO()
client = pycurl.Curl()
client.setopt(pycurl.URL, self.service_host + "/v1/albums/" +
album_id + "/tracks" + "?" + urlencode(params))
client.setopt(pycurl.WRITEFUNCTION, buf.write)
client.perform()
client.close()
body = json.loads(buf.getvalue().decode("utf-8"))
buf.close()
if body["total"] > 0:
for data in body["items"]:
tracks.append(
Track(data["name"], None, data["track_number"]))
if body["total"] > body["limit"] * (offset + 1):
offset = offset + 1
else:
break
return tracks
评论列表
文章目录