Skip to content

Instantly share code, notes, and snippets.

@samstarling
Created May 26, 2011 20:44
Show Gist options
  • Save samstarling/994036 to your computer and use it in GitHub Desktop.
Save samstarling/994036 to your computer and use it in GitHub Desktop.
Measures the loudness of the MP3 streams passed in the 'stations' dictionary
# Requires pyechonest
import urllib
from pyechonest import config
from pyechonest import track
config.ECHO_NEST_API_KEY = "YOUR_API_KEY_HERE"
stations = {
'Fun Kids': 'http://media-ice.musicradio.com:80/FunKidsMP3Low',
'talkSPORT': 'http://stream5.radiomonitor.com:80/utv_fallback',
'Kiss': 'http://icy-e-03.sharp-stream.com:80/kiss100.mp3',
}
for k, v in stations.iteritems():
try:
filename = "%s.mp3" % (k.replace(' ', ''))
print '<- Listening to', k
conn = urllib.urlopen(v)
stream = None
stream = conn.read(100000)
print '-- Saving'
target = open(filename, "w")
target.write(stream)
print '-- Analysing'
t = track.track_from_filename(filename)
print '->', k + ':', t.loudness, 'dB'
except Exception, e:
print 'Exception', e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment