+ soup = BeautifulSoup(opener.open(request, timeout=0.5))
+ if soup.title:
+ return unescape('%s' % (soup.title.string))
+ else:
+ return None
+ except urllib2.HTTPError as e:
+ return 'Error: %s %s' % (e.code, e.reason)
+ except Exception as e:
+ return 'Error: %r' % (e.message)
+
+url_regex = (
+ re.compile(r'https?://[^/\s]+\.[^/\s]+(?:/\S+)?'),
+)
+spotify_regex = (
+ re.compile(r'spotify:(?P<type>\w+):(?P<track_id>\w{22})'),
+ re.compile(r'https?://open\.spotify\.com/(?P<type>\w+)/(?P<track_id>\w+)')
+)
+youtube_regex = (
+ re.compile(r'https?://(?:www\.)?youtube\.com/watch\?[a-zA-Z0-9=&_\-]+'),
+)
+twitch_regex = (
+ re.compile(r'https?:\/\/(?:www\.)?twitch.tv\/([A-Za-z0-9]*)'),
+)
+other_regexes = (
+ (gotspotify, spotify_regex, 'Spotify'),
+ (gotyoutube, youtube_regex, 'YouTube'),
+ (gottwitch, twitch_regex, 'Twitch'),
+)
+regexes = other_regexes + (
+ (goturl, url_regex, 'Title'),
+)