-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.py
75 lines (63 loc) · 2.83 KB
/
audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from pprint import pprint
from time import sleep
import json
import time
def main():
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="54735820284c4380ac403bb4ae089d9c",
client_secret="3ccbf7901668460e80a03015d5f12da0",
redirect_uri="http://localhost:1337/callback",
scope="user-read-recently-played user-read-playback-state "
"user-top-read playlist-modify-public "
"user-modify-playback-state playlist-modify-private "
"user-follow-modify user-read-currently-playing "
"user-follow-read user-library-modify "
"user-read-playback-position playlist-read-private "
"user-read-email user-read-private user-library-read "
"playlist-read-collaborative",
open_browser=False))
# Shows playing devices
res = sp.devices()
# Gets the device with the name below
device_id = ""
for d in res['devices']:
if d['name'] == 'Web Player (Chrome)':
device_id = d['id']
# Ma
user_list = {"nick": '5sq0472fjzjxdx70quovzgcy7', "yale": 'yaleduffy'}
users_in_scene = ["nick"]
songs = []
for i in range(0,len(users_in_scene)):
songs += get_songs(sp, user_list[users_in_scene[i]])
print(songs)
sp.start_playback(uris=songs, device_id=device_id)
def get_songs(sp, username):
playlists = sp.user_playlists(username)
playlist_id = get_playlists(sp, playlists, "Party")
results = sp.playlist_items(playlist_id, additional_types=['track'])
tracks = []
for x in range(0, len(results['items'])):
tracks += [results['items'][x]['track']['uri']]
return tracks
def get_playlists(sp, playlists, playlist_name):
current_playlist_id = ""
while playlists:
for i, playlist in enumerate(playlists['items']):
# print(
# "%4d %s %s" %
# (i +
# 1 +
# playlists['offset'],
# playlist['uri'],
# playlist['name']))
if playlist['name'] == playlist_name:
current_playlist_id = playlist['uri']
# gets next page
if playlists['next']:
playlists = sp.next(playlists)
else:
playlists = None
return current_playlist_id
if __name__ == "__main__":
main()