From: John Runyon Date: Sat, 25 Jan 2014 15:29:33 +0000 (-0600) Subject: Various fixed to spotify.py X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/822b8906df33c3c6091c4663ff4c909fad5746be Various fixed to spotify.py - Use str.split(None) not str.split(' ') (Collapses multiple whitespace, splits on all whitespace instead of only ) - Don't test lines against regex unless the line has spotify in it (`str in str` is much faster than doing multiple regex) --- diff --git a/modules/spotify.py b/modules/spotify.py index cd5e767..7325cef 100644 --- a/modules/spotify.py +++ b/modules/spotify.py @@ -22,6 +22,7 @@ import ctlmod import urllib2 from BeautifulSoup import BeautifulSoup +checkfor = "spotify" hostmask_regex = re.compile('^(.*)!(.*)@(.*)$') spotify_regex = ( re.compile(r'spotify:(?P\w+):(?P\w{22})'), re.compile(r'http://open.spotify.com/(?P\w+)/(?P\w{22})') ) @@ -55,13 +56,16 @@ def privmsg_hook(bot, line): sender = parser_hostmask(line[1:line.find(' ')]) try: - linetx = line.split(' ', 3)[3][1:] + linetx = line.split(None, 3)[3][1:] except IndexError: linetx = '' + if checkfor not in line: + return # doesn't concern us + for r in spotify_regex: for type, track in r.findall(linetx): - url = '%s?uri=spotify:%s:%s' %(spotify_gateway, type, track) + url = '%s?uri=spotify:%s:%s' % (spotify_gateway, type, track) xml = urllib2.urlopen(url).read() soup = BeautifulSoup(xml) lookup_type = soup.contents[2].name