Skip to content

Instantly share code, notes, and snippets.

@np1
Created September 16, 2013 00:37
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 np1/6575561 to your computer and use it in GitHub Desktop.
Save np1/6575561 to your computer and use it in GitHub Desktop.
Play (almost) any song with 2 lines of python code (requires mplayer)
import urllib2 as u, sys as s, json as j, subprocess as p
p.call(["mplayer", u.urlopen(j.loads(u.urlopen("http://ex.fm/api/v3/song/search/%s" % "+".join(s.argv[1:])).read())['songs'][0]['url']).geturl().split("#")[0]])
# usage:
# python playsong.py {artist and/or song name}
#
# eg:
#
# python playsong.py rolling stones paint it black
# or
# python playsong.py daft punk get lucky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment