Add checks to prevent bot saying "None", fix error building youtube message
This commit is contained in:
parent
b9466cd223
commit
a599ff7212
|
@ -36,7 +36,9 @@ class LinkTitler(ModuleBase):
|
||||||
done = []
|
done = []
|
||||||
for item in matches:
|
for item in matches:
|
||||||
if not item in done:
|
if not item in done:
|
||||||
self.bot.act_PRIVMSG(args[0], self.get_video_description(item))
|
vidinfo = self.get_video_description(item)
|
||||||
|
if vidinfo:
|
||||||
|
self.bot.act_PRIVMSG(args[0], vidinfo)
|
||||||
done.append(item)
|
done.append(item)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -122,7 +124,8 @@ class LinkTitler(ModuleBase):
|
||||||
out += '%dh ' % int(duration["hours"])
|
out += '%dh ' % int(duration["hours"])
|
||||||
if duration["minutes"]!=None:
|
if duration["minutes"]!=None:
|
||||||
out += '%dm ' % int(duration["minutes"])
|
out += '%dm ' % int(duration["minutes"])
|
||||||
out += "%ds\x02" % int(duration["seconds"])
|
if duration["seconds"]!=None:
|
||||||
|
out += "%ds\x02" % int(duration["seconds"])
|
||||||
|
|
||||||
totalvotes = float(video["statistics"]["dislikeCount"])+float(video["statistics"]["likeCount"])
|
totalvotes = float(video["statistics"]["dislikeCount"])+float(video["statistics"]["likeCount"])
|
||||||
rating = float(video["statistics"]["likeCount"]) / totalvotes
|
rating = float(video["statistics"]["likeCount"]) / totalvotes
|
||||||
|
|
|
@ -47,7 +47,9 @@ class Youtube(ModuleBase):
|
||||||
self.bot.act_PRIVMSG(args[0], "YouTube: No results found.")
|
self.bot.act_PRIVMSG(args[0], "YouTube: No results found.")
|
||||||
else:
|
else:
|
||||||
vid_id = j['data']['items'][0]['id']
|
vid_id = j['data']['items'][0]['id']
|
||||||
self.bot.act_PRIVMSG(args[0], "http://youtu.be/%s :: %s" % (vid_id, self.get_video_description(vid_id)))
|
vidinfo = self.get_video_description(vid_id)
|
||||||
|
if vidinfo:
|
||||||
|
self.bot.act_PRIVMSG(args[0], "http://youtu.be/%s :: %s" % (vid_id, vidinfo))
|
||||||
|
|
||||||
def get_video_description(self, vid_id):
|
def get_video_description(self, vid_id):
|
||||||
apidata = get('https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=%s&key=%s' % (vid_id, self.config["api_key"])).json()
|
apidata = get('https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=%s&key=%s' % (vid_id, self.config["api_key"])).json()
|
||||||
|
|
Loading…
Reference in New Issue