summaryrefslogtreecommitdiff
path: root/modules/url_titles.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-06-03 17:40:05 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-06-03 17:40:05 +0200
commit5393609d04592eade539355de2e68615de4bdc6f (patch)
tree0f39af21845e380276216b5294a448d0f17cf744 /modules/url_titles.py
parentc5f92bde3d0ac8b27ec8861a9269cd84ccd99457 (diff)
url_titles: Moved spotify code to its own module.
Diffstat (limited to 'modules/url_titles.py')
-rw-r--r--modules/url_titles.py25
1 files changed, 4 insertions, 21 deletions
diff --git a/modules/url_titles.py b/modules/url_titles.py
index 60cc16f..c4f89f4 100644
--- a/modules/url_titles.py
+++ b/modules/url_titles.py
@@ -4,31 +4,17 @@ info = {
'description': 'Fetches the title tags off of URLs.',
}
-import re, urllib2, htmlentitydefs, gzip, cStringIO, spotimeta, time
+import re, urllib2, htmlentitydefs, gzip, cStringIO, time
from PIL import ImageFile
class Module:
re_http = re.compile(r'(https?://[^\ ]+)')
- re_spotify = re.compile(r'spotify:(?:track|artist|album):[\w]{22}')
re_title = re.compile(r'<title[^>]*?>(.*?)</title>', re.S | re.I)
- metadata = spotimeta.Metadata(cache = {})
def __init__(self, bot):
self.irc = bot
- self.irc.register_callback(self)
-
- def spotify(self, s):
- try:
- data = self.metadata.lookup(s)
- except:
- return 'Failed to fetch metadata from spotify.'
- if data['type'] == 'artist':
- return 'Spotify artist: %s' % data['result']['name']
- elif data['type'] == 'track':
- return 'Spotify track: %s - %s (%s)' % (data['result']['artist']['name'], data['result']['name'], data['result']['album']['name'])
- elif data['type'] == 'album':
- return u'Spotify album: %s (%d) by %s' % (data['result']['name'], data['result']['released'],
- ', '.join([x['name'] for x in data['result']['artists']]))
+ if bot:
+ self.irc.register_callback(self)
def get_titles(self, s):
def parse_url(url):
@@ -68,8 +54,8 @@ class Module:
m = self.re_http.findall(s)
titles = []
for url in m:
+ # ignore spotify URLs
if 'open.spotify.com' in url:
- titles.append(self.spotify(url).encode('utf8'))
continue
t = time.time()
try:
@@ -125,9 +111,6 @@ class Module:
finally:
del im
u.close()
- spotify_links = self.re_spotify.findall(s)
- for sp in spotify_links:
- titles.append(self.spotify(sp).encode('utf8'))
if len(titles) == 0:
return
elif len(titles) == 1: