X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/325937f6d7b74f3855e646a44364401f55c39ce8..7a540f7cf9237aa129e5ce6a59412b65210dbe2f:/modules/youtube.py diff --git a/modules/youtube.py b/modules/youtube.py index 38b4470..538c91e 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -1,10 +1,10 @@ -# Erebus IRC bot - Author: Conny Sjoblom +# Erebus IRC bot - Author: Erebus Team # Youtube URL Checker # This file is released into the public domain; see http://unlicense.org/ # module info modinfo = { - 'author': 'Conny Sjoblom', + 'author': 'Erebus Team', 'license': 'public domain', 'compatible': [1], # compatible module API versions 'depends': [], # other modules required to work properly? @@ -25,8 +25,7 @@ import HTMLParser from BeautifulSoup import BeautifulSoup checkfor = "youtube" -url_regex = re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') -yturl_regex = re.compile('(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?') +yturl_regex = re.compile(r'https?://(?:www\.)?youtube\.com/watch\?[a-zA-Z0-9=&_\-]+') @lib.hooknum("PRIVMSG") def privmsg_hook(bot, line): @@ -38,13 +37,12 @@ def privmsg_hook(bot, line): if checkfor not in line: return # doesn't concern us - print "Meow" - for url in url_regex.findall(linetx): - if checkfor in url: - url_data = urlparse.urlparse(url) - query = urlparse.parse_qs(url_data.query) - video = query["v"][0] - api_url = 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json&v=2' % video + for url in yturl_regex.findall(linetx): + url_data = urlparse.urlparse(url) + query = urlparse.parse_qs(url_data.query) + video = query["v"][0] + api_url = 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json&v=2' % video + try: respdata = urllib2.urlopen(api_url).read() video_info = json.loads(respdata) @@ -52,3 +50,5 @@ def privmsg_hook(bot, line): author = video_info['entry']['author'][0]['name']['$t'] bot.msg(line.split()[2], "Youtube: %s (%s)" % (title, author)) + except: + pass