Skip to content

Instantly share code, notes, and snippets.

@robertcasanova
Created October 6, 2012 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertcasanova/3845404 to your computer and use it in GitHub Desktop.
Save robertcasanova/3845404 to your computer and use it in GitHub Desktop.
Python Stream Song from SoundCloud
import pygst
pygst.require("0.10")
import gst
import soundcloud
import sys
query = sys.argv[1] ##TODO try catch for no parameters
client = soundcloud.Client(client_id='xxx')
track = client.get('/tracks', q=query)[0]
stream_url = client.get(track.stream_url, allow_redirects=False)
#our stream to play
music_stream_uri = stream_url.location
#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)
#wait and let the music play
raw_input('Press enter to stop playing...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment