Created
June 1, 2014 00:51
-
-
Save cschmittiey/62115af1a81366e4ddc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# encoding: utf-8 | |
# encoding declaration as specified here http://www.python.org/dev/peps/pep-0263/ | |
import soundcloud | |
from subprocess import call | |
# create client object with app and user credentials | |
client = soundcloud.Client(client_id='', | |
client_secret='') | |
query = raw_input("What do you want to search for? ") | |
tracks = client.get('/tracks', q=query, limit=10, filter="streamable") | |
i = 1 | |
temp = {} #initalize dictionary | |
for track in tracks: | |
print u'[{2}] Title: {0}\n ID: {1}'.format(track.title.encode('utf-8'), track.id, i) | |
temp.update({i:track.id}) #set dictionary key | |
i=i + 1 | |
queryb = input("Which track would you like to play?") | |
trackid = temp.get(queryb) #retrieve key | |
print "Artist: {0}".format(track.user.get(u'username')) | |
track = client.get('/tracks/{0}'.format(trackid)) | |
stream_url = client.get(track.stream_url, allow_redirects=False) | |
call (["mplayer", "{0}".format(stream_url.location)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment