-
Notifications
You must be signed in to change notification settings - Fork 0
/
auk.py
66 lines (53 loc) · 2.2 KB
/
auk.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
import sys, soundcloud, pyen
#Configuration
pyen_key = "8GDKECFTIJHEADTWC" #echonest
client_id = "53188e4558d06691aac3cf57ef3a7cd7" #soundcloud
en = pyen.Pyen(pyen_key)
client = soundcloud.Client(client_id=client_id)
def aukfetch(root_track, root_artist = None):
related_dict={}
# response = en.get('song/search', artist=root_artist, title=root_track, bucket=['audio_summary'], results=1)
# for song in response['songs']:
# root_duration = song["audio_summary"]['duration']
# #print root_duration
# root_artist = song["artist_name"]
# root_track = song["title"]
# #handle exceptions for license
# print "root %-32.32s %s" % (root_artist, root_track)
# print sc_streamurl(root_track, root_artist, root_duration)
response = en.get('playlist/static', artist=root_artist, type='artist-radio', results=10)
for i, new_song in enumerate(response['songs']):
templist=[]
response2 = en.get('song/search', artist=new_song['artist_name'], title=new_song['title'], bucket=['audio_summary'], results=1)
for song in response2['songs']:
new__duration = song["audio_summary"]['duration']
#print "%d %-32.32s %s" % (i, new_song['artist_name'], new_song['title'])
#print sc_streamurl(new_song['title'], new_song['artist_name'], new__duration)
templist.append(new_song['artist_name'])
templist.append(new_song['title'])
templist.append(sc_streamurl(new_song['title'], new_song['artist_name'], new__duration))
related_dict[i] = templist
return related_dict
def sc_streamurl(root_track, root_artist, root_duration):
"""
Gives back the soundcloud stream url for a given track input
"""
tracks = client.get('/tracks', q=root_artist+' '+root_track, duration={'from': root_duration-2,'to': root_duration+2}, results=3)
try:
#print tracks[0].title
su =tracks[0].stream_url
stream_url = client.get(su, allow_redirects=False)
# print the tracks stream URLnj
return stream_url.location
except:
#print tracks[1].title
try:
su =tracks[1].stream_url
stream_url = client.get(su, allow_redirects=False)
return stream_url.location
except:
pass
# print "Welcome to auk-0.1","\n"
# root_track= raw_input("Enter track name: ")
# root_artist = raw_input("Enter artist name: ")
# auk(root_track, root_artist)