-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
39 lines (31 loc) · 1006 Bytes
/
app.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
import soundcloud
import pygst
import gst
QUERY = 'girlsgeneration'
CLIENT_ID = ''
client = soundcloud.Client(client_id=CLIENT_ID)
track_url = 'http://soundcloud.com/forss/flickermood'
tracks = client.get('/tracks', q=QUERY, order='hotness', limit=1)
for track in tracks:
print vars(track)
stream_url = track.attachments_uri
def on_tag(bus, msg):
taglist = msg.parse_tag()
print 'on_tag:'
for key in taglist.keys():
print '\t%s = %s' % (key, taglist[key])
#our stream to play
music_stream_uri = stream_url
#creates a playbin (plays media form an uri)
player = gst.element_factory_make("playbin", "player")
#set the uri
player.set_property('uri', music_stream_uri)
#start playing
player.set_state(gst.STATE_PLAYING)
#listen for tags on the message bus; tag event might be called more than once
bus = player.get_bus()
bus.enable_sync_message_emission()
bus.add_signal_watch()
bus.connect('message::tag', on_tag)
#wait and let the music play
raw_input('Press enter to stop playing...')