]>
jfr.im git - erebus.git/blob - modules/youtube.py
1 # Erebus IRC bot - Author: Erebus Team
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
25 from BeautifulSoup
import BeautifulSoup
28 yturl_regex
= re
.compile(r
'https?://(?:www\.)?youtube\.com/watch\?[a-zA-Z0-9=&_\-]+')
30 @lib.hooknum("PRIVMSG")
31 def privmsg_hook(bot
, line
):
33 linetx
= line
.split(None, 3)[3][1:]
37 if checkfor
not in line
:
38 return # doesn't concern us
40 for url
in yturl_regex
.findall(linetx
):
41 url_data
= urlparse
.urlparse(url
)
42 query
= urlparse
.parse_qs(url_data
.query
)
44 api_url
= 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json&v=2' % video
46 respdata
= urllib2
.urlopen(api_url
).read()
47 video_info
= json
.loads(respdata
)
49 title
= video_info
['entry']['title']["$t"]
50 author
= video_info
['entry']['author'][0]['name']['$t']
52 bot
.msg(line
.split()[2], "Youtube: %s (%s)" % (title
, author
))