diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-25 21:12:22 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-05-25 21:12:22 +0200 |
commit | a9a8c128af7a7d366e448a918c07b7fbc8176f7b (patch) | |
tree | 74cc6672d4c47a668442ed62805387c07d04774c /modules | |
parent | f9e9af49233ba05a87f6c00c387134394443bfb3 (diff) |
url_titles: Support spotify-links (non-http) and albums.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/url_titles.py | 21 |
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 = '' |