63
63
if(name == 'author'):
66
if(name == 'rating_avg'):
69
if(name == 'rating_count'):
70
self.rating_count = ''
68
if(name == 'gd:rating'):
69
self.rating_count = attributes.getValue('numRaters')
71
# Compute percentage rating based on the average rating and the maximum rating
72
self.rating = ( float(attributes.getValue('average')) / float(attributes.getValue('max')) ) * 100
71
73
self.inRatingCount = 1
72
if(name == 'view_count'):
74
if(name == 'yt:statistics'):
75
self.views = attributes.getValue('viewCount')
77
if(name == 'yt:duration'):
78
self.duration = timedelta(seconds = float(attributes.getValue('seconds')))
76
80
def characters(self,data):
83
if(self.inAuthor and self.inName):
80
84
self.author += data
83
if(self.inRatingCount):
84
self.rating_count += data
87
86
def endElement(self,name):
88
87
if(name == 'title'):
90
89
if(name == 'author'):
92
if(name == 'rating_avg'):
94
if(name == 'rating_count'):
95
self.inRatingCount = 0
96
self.rating = (float(self.rating)/5)*100
97
if(name == 'view_count'):
100
94
class Supytube(callbacks.Plugin):
101
95
"""Add the help for "@plugin help Supytube" here
105
99
def doPrivmsg(self, irc, msg):
106
if(self.registryValue('enable',msg.args[0])):
107
# If this is a youtube link, commence lookup
108
if(msg.args[1].find("youtube") != -1):
109
for word in msg.args[1].split(' '):
110
if(word.find("youtube") != -1):
111
videoid = urlparse(word)[4].split('=')[1].split('&')[0]
112
devid = self.registryValue('devid')
113
#log.critical(videoid)
115
f = urllib.urlopen('http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=%s&video_id=%s' % (devid,videoid))
116
parser = xml.sax.make_parser()
117
handler = YoutubeHandler()
118
parser.setContentHandler(handler)
120
#log.critical(handler.title)
121
irc.queueMsg(ircmsgs.privmsg(msg.args[0],'Title: %s, Views: %s, Rating: %s%%' % (ircutils.bold(handler.title), ircutils.bold(handler.views),ircutils.bold(handler.rating))))
100
if(self.registryValue('enable',msg.args[0])):
101
# If this is a youtube link, commence lookup
102
if(msg.args[1].find("youtube") != -1):
103
for word in msg.args[1].split(' '):
104
if(word.find("youtube") != -1):
105
videoid = urlparse(word)[4].split('=')[1].split('&')[0]
107
f = urllib.urlopen('http://gdata.youtube.com/feeds/videos/%s' % (videoid))
108
parser = xml.sax.make_parser()
109
handler = YoutubeHandler()
110
parser.setContentHandler(handler)
113
#log.critical('Title: %s' % handler.title)
114
#log.critical('Author: %s' % handler.author)
115
#log.critical('Rating: %s' % handler.rating)
116
#log.critical('Views: %s' % handler.views)
117
#log.critical('Rating Count: %s' % handler.rating_count)
118
#log.critical('Duration: %s' % handler.duration)
120
irc.queueMsg(ircmsgs.privmsg(msg.args[0],'Title: %s, Views: %s, Rating: %s%%' % (ircutils.bold(handler.title), ircutils.bold(handler.views),ircutils.bold(handler.rating))))
130
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: