-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscoSounds.py
73 lines (60 loc) · 2.26 KB
/
discoSounds.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
import soundcloud as sc
import json
import requests
# client_secret='67422b6c159a389c9cfed1a9607227ef'
client = sc.Client(client_id='VouLZKnkCQYDVMu86Y8dJ1Nt7h8DMeT0',
client_secret='gRIEjS8jCajOpJ3Gkcgs3e1wg8vf39KA')
# client.authorize_url()
def getSongList(g):
##number of results per page
trackList = []
scTracks = client.get('/tracks', tags=g, limit=50, streamable='True', track_type='original',sharing='public',)
i = 0
for t in scTracks:
#parse track information to what is relevant to us
#returns duration in milliseconds to sync songs.
if t.duration <= 240000:
username = t.user['username']
new_track = {'id':t.id,'title':t.title, 'creator_user':username,'track_permalink':t.permalink_url,'stream_url':"",'artwork':t.artwork_url, 'duration':t.duration,'start_time':'','chosen_by':None}
trackList.append(new_track)
# for x in range(0,4):
# trackList[x]['stream_url'] = getSongURLLocation(trackList[x]['id'])
return trackList
def getSongURLLocation(track_id):
track = '/tracks/' + str(track_id)
tracks = client.get(track)
track_stream = client.get(tracks.stream_url, allow_redirects=False)
# print(track_stream.location)
return track_stream.location
def refresh_streams(songList):
for x in range(0,4):
songList[x]['stream_url'] = getSongURLLocation(songList[x]['id'])
return songList
def refresh_song(song,start_time):
# print("****INSIDE REFRESH SONG****",song)
song['stream_url'] = getSongURLLocation(song['id'])
song['start_time'] = start_time
return song
def try_i1(track_id):
track = 'i1/tracks/'+str(track_id)
# resolved = client.get(track)
resolved = requests.get(('https://api.soundcloud.com/i1/tracks/' + str(track_id) + '/streams?client_id=VouLZKnkCQYDVMu86Y8dJ1Nt7h8DMeT0'))
json = resolved.json()
# print(json)
if json['http_mp3_128_url'] is not None:
return json['http_mp3_128_url']
else:
return False
# print("********songlist*******")
# songs = getSongList("rock")
# print(songs[0])
# url = getSongURLLocation(songs[0]['id'])
# il1 = try_i1(songs[0]['id'])
# print("getsongURL",url)
# print("ul:1", il1)
# if url == il1:
# print("yes muthafuckaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
# print(try_i1(319172154))
# print(json.dumps(songs,indent=4))
# print("****refreshed*****")
# print(json.dumps(refresh_streams(songs),indent=4))