]>
Commit | Line | Data |
---|---|---|
9bd05cf6 | 1 | # Erebus IRC bot - Author: Erebus Team |
c6b4a177 | 2 | # Youtube URL Checker |
c3502e73 CS |
3 | # This file is released into the public domain; see http://unlicense.org/ |
4 | ||
5 | # module info | |
6 | modinfo = { | |
9bd05cf6 | 7 | 'author': 'Erebus Team', |
c3502e73 CS |
8 | 'license': 'public domain', |
9 | 'compatible': [1], # compatible module API versions | |
10 | 'depends': [], # other modules required to work properly? | |
11 | } | |
12 | ||
13 | # preamble | |
14 | import modlib | |
15 | lib = modlib.modlib(__name__) | |
16 | modstart = lib.modstart | |
17 | modstop = lib.modstop | |
18 | ||
19 | # module code | |
20 | import re | |
21 | import urllib2 | |
22 | import HTMLParser | |
23 | from BeautifulSoup import BeautifulSoup | |
24 | ||
25 | checkfor = "youtube" | |
c3502e73 | 26 | url_regex = re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') |
c3502e73 CS |
27 | |
28 | @lib.hooknum("PRIVMSG") | |
29 | def privmsg_hook(bot, line): | |
c3502e73 CS |
30 | try: |
31 | linetx = line.split(None, 3)[3][1:] | |
32 | except IndexError: | |
33 | linetx = '' | |
34 | ||
35 | if checkfor not in line: | |
36 | return # doesn't concern us | |
37 | ||
38 | for url in url_regex.findall(linetx): | |
39 | if checkfor in url: | |
40 | html_parser = HTMLParser.HTMLParser() | |
41 | respdata = urllib2.urlopen(url).read() | |
42 | soup = BeautifulSoup(respdata) | |
c6b4a177 | 43 | bot.msg(line.split()[2], BeautifulSoup(soup.title.string, convertEntities=BeautifulSoup.HTML_ENTITIES)) |