summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-25 21:13:04 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-25 21:13:04 +0200
commit0fb03f9ac451f46147fde56a370b62f7f66765ef (patch)
treeffd88ebadd50ccbbdce4685a65249fe6a66fd0d0 /modules
parent2066a309d2672f6b071da87c2fb156a2af15c5d3 (diff)
parenta9a8c128af7a7d366e448a918c07b7fbc8176f7b (diff)
Merge branch 'master' into ipv6
Diffstat (limited to 'modules')
-rw-r--r--modules/url_titles.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/modules/url_titles.py b/modules/url_titles.py
index 6fa48f2..11c0472 100644
--- a/modules/url_titles.py
+++ b/modules/url_titles.py
@@ -9,6 +9,7 @@ from PIL import ImageFile
class Module:
re_http = re.compile(r'(http://[^\ ]+)')
+ 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 = {})
@@ -21,9 +22,12 @@ class Module:
except:
return 'Failed to fetch metadata from spotify.'
if data['type'] == 'artist':
- return 'Spotify: %s' % data['result']['name']
- else:
- return 'Spotify: %s - %s' % (data['result']['artist']['name'], data['result']['name'])
+ return 'Spotify artist: %s' % data['result']['name']
+ elif data['type'] == 'track':
+ return 'Spotify track: %s - %s' % (data['result']['artist']['name'], data['result']['artist']['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']]))
def get_titles(self, s):
def parse_url(url):
@@ -61,11 +65,9 @@ class Module:
return s
m = self.re_http.findall(s)
- if not m:
- return
titles = []
for url in m:
- if any([x in url for x in ('open.spotify.com', 'spotify:track:', 'spotify:artist:', 'spotify:album:')]):
+ if 'open.spotify.com' in url:
titles.append(self.spotify(url).encode('utf8'))
continue
t = time.time()
@@ -122,7 +124,12 @@ class Module:
finally:
del im
u.close()
- if len(titles) == 1:
+ 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:
s = format_text(titles[0])
else:
s = ''