Skip to content

Instantly share code, notes, and snippets.

@Achifaifa
Last active August 29, 2015 14:08
Show Gist options
  • Save Achifaifa/370cd2a2b82811fa67ea to your computer and use it in GitHub Desktop.
Save Achifaifa/370cd2a2b82811fa67ea to your computer and use it in GitHub Desktop.
Reads author and title from input and plays a random matching song via VLC
#! /usr/bin/env python
import json,subprocess,urllib2
jsonshit=json.loads(urllib2.urlopen("http://developer.echonest.com/api/v4/song/search?bucket=id:spotify&bucket=tracks&results=100&api_key=MZFEPELDSKFX4WAMA&artist=%s&title=%s"%(raw_input("group? ",),raw_input("title? ",))).read())
print jsonshit["response"]["songs"][0]["artist_name"],jsonshit["response"]["songs"][0]["title"]
processeddata=json.loads(urllib2.urlopen("https://api.spotify.com/v1/tracks/"+jsonshit["response"]["songs"][0]["tracks"][0]["foreign_id"].split(':')[2]).read())
subprocess.call(["vlc", processeddata["preview_url"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment