added json parsing, added generate playlists
This commit is contained in:
parent
c8f09bd6c2
commit
92f4d906bd
43
generateplaylists.py
Normal file
43
generateplaylists.py
Normal file
@ -0,0 +1,43 @@
|
||||
import spotframework.net.const as const
|
||||
import spotframework.net.network as network
|
||||
import spotframework.net.user as user
|
||||
import spotframework.log.log as log
|
||||
import spotframework.io.json as json
|
||||
|
||||
import os
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
# try:
|
||||
if os.path.exists(os.path.join(const.config_path, 'playlists.json')):
|
||||
|
||||
data = json.loadJson(os.path.join(const.config_path, 'playlists.json'))
|
||||
|
||||
net = network.network(user.User())
|
||||
playlists = net.getUserPlaylists()
|
||||
|
||||
for tomake in data['playlists']:
|
||||
|
||||
tracks = []
|
||||
|
||||
for part in tomake['playlists']:
|
||||
|
||||
play = next((i for i in playlists if i.name == part), None)
|
||||
|
||||
if play is not None:
|
||||
|
||||
if len(play.tracks) == 0:
|
||||
log.log("pulling tracks for {}".format(play.name))
|
||||
play.tracks = net.getPlaylistTracks(play.playlistid)
|
||||
|
||||
tracks += [i for i in play.tracks if i['track']['uri'] not in [j['track']['uri'] for j in tracks]]
|
||||
|
||||
else:
|
||||
log.log("requested playlist {} not found".format(part))
|
||||
|
||||
tracks.sort(key=lambda x: x['track']['album']['release_date'], reverse=True)
|
||||
|
||||
net.replacePlaylistTracks(tomake['id'], [i['track']['uri'] for i in tracks])
|
||||
|
||||
# except:
|
||||
# log.dumpLog()
|
28
main.py
28
main.py
@ -2,22 +2,32 @@ import spotframework.net.user as userclass
|
||||
import spotframework.net.network as networkclass
|
||||
import spotframework.net.network as playlist
|
||||
|
||||
import spotframework.io.json as json
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('hello world')
|
||||
|
||||
# data = json.loadJson('.spot/playlists.json')
|
||||
|
||||
# print(data)
|
||||
|
||||
network = networkclass.network(userclass.User())
|
||||
|
||||
# tracks = network.getPlaylistTracks("76ynkbkyc4uq11u1FcpOyG")
|
||||
|
||||
# print(tracks[0])
|
||||
|
||||
# network.setVolume(105)
|
||||
|
||||
network.getPlaylist('000Eh2vXzYGgrEFlgcWZj3')
|
||||
|
||||
playlist = network.makePlaylist('new playlist')
|
||||
|
||||
network.addPlaylistTracks(playlist.playlistid, ["spotify:track:78lC4VmDVSSsCUQ0VNdQva"]*149)
|
||||
|
||||
network.replacePlaylistTracks(playlist.playlistid, ["spotify:track:78lC4VmDVSSsCUQ0VNdQva"] * 160)
|
||||
|
||||
network.pause()
|
||||
# network.getPlaylist('000Eh2vXzYGgrEFlgcWZj3')
|
||||
#
|
||||
# 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()
|
||||
|
||||
|
19
spotframework/io/json.py
Normal file
19
spotframework/io/json.py
Normal file
@ -0,0 +1,19 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import spotframework.log.log as log
|
||||
|
||||
def loadJson(path):
|
||||
|
||||
log.log("load json", path)
|
||||
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r') as fileobj:
|
||||
|
||||
data = json.load(fileobj)
|
||||
return data
|
||||
|
||||
else:
|
||||
log.log("load json", "file doesn't exist")
|
||||
|
||||
return None
|
Loading…
Reference in New Issue
Block a user