added pause, replaceplaylisttracks, addplaylisttracks

This commit is contained in:
aj 2019-05-14 13:55:51 +01:00
parent 9ba05eb7a7
commit c8f09bd6c2
2 changed files with 62 additions and 6 deletions

View File

@ -11,7 +11,13 @@ if __name__ == '__main__':
network.getPlaylist('000Eh2vXzYGgrEFlgcWZj3')
network.makePlaylist('new playlist')
playlist = network.makePlaylist('new playlist')
network.addPlaylistTracks(playlist.playlistid, ["spotify:track:78lC4VmDVSSsCUQ0VNdQva"]*149)
network.replacePlaylistTracks(playlist.playlistid, ["spotify:track:78lC4VmDVSSsCUQ0VNdQva"] * 160)
network.pause()
#network.getPlayer()

View File

@ -155,6 +155,17 @@ class network:
req = self._makePutRequest('play', 'me/player/play', params=params, json=payload)
def pause(self, deviceid=None):
log.log("pause", deviceid)
if deviceid is not None:
params = {'device_id': deviceid}
else:
params = None
req = self._makePutRequest('pause', 'me/player/pause', params=params)
def next(self, deviceid=None):
@ -198,7 +209,8 @@ class network:
def makePlaylist(self, name, description=None, public=True, collaborative=False):
log.log("makePlaylist", name, 'description:{}'.format(description), 'public:{}'.format(public), 'collaborative:{}'.format(collaborative))
log.log("makePlaylist", name, 'description:{}'.format(description), 'public:{}'.format(public),
'collaborative:{}'.format(collaborative))
headers = {"Content-Type": "application/json"}
@ -207,11 +219,49 @@ class network:
if description is not None:
json["description"] = description
resp = self._makePostRequest('makePlaylist', 'users/{}/playlists'.format(self.user.username), json=json, headers=headers).json()
req = self._makePostRequest('makePlaylist', 'users/{}/playlists'.format(self.user.username), json=json,
headers=headers)
if resp is not None:
if req is not None:
resp = req.json()
playlist = playlistclass(resp["id"], uri=resp['uri'], name=resp['name'], userid=resp['owner']['id'])
return playlist
if resp is not None:
playlist = playlistclass(resp["id"], uri=resp['uri'], name=resp['name'], userid=resp['owner']['id'])
return playlist
return None
def replacePlaylistTracks(self, playlistid, uris):
log.log("replacePlaylistTracks", playlistid)
headers = {"Content-Type": "application/json"}
json = {"uris": uris[:100]}
req = self._makePutRequest('replacePlaylistTracks', 'playlists/{}/tracks'.format(playlistid), json=json,
headers=headers)
if req is not None:
resp = req.json()
if len(uris) > 100:
self.addPlaylistTracks(playlistid, uris[100:])
def addPlaylistTracks(self, playlistid, uris):
log.log("addPlaylistTracks", playlistid)
headers = {"Content-Type": "application/json"}
json = {"uris": uris[:100]}
req = self._makePostRequest('addPlaylistTracks', 'playlists/{}/tracks'.format(playlistid), json=json,
headers=headers)
if req is not None:
resp = req.json()
if len(uris) > 100:
self.addPlaylistTracks(playlistid, uris[100:])