Add checks to prevent bot saying "None", fix error building youtube message

dave/xdcc
dpedu 7 years ago
parent b9466cd223
commit a599ff7212
  1. 7
      pyircbot/modules/LinkTitler.py
  2. 4
      pyircbot/modules/Youtube.py

@ -36,7 +36,9 @@ class LinkTitler(ModuleBase):
done = []
for item in matches:
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)
return
@ -122,7 +124,8 @@ class LinkTitler(ModuleBase):
out += '%dh ' % int(duration["hours"])
if duration["minutes"]!=None:
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"])
rating = float(video["statistics"]["likeCount"]) / totalvotes

@ -47,7 +47,9 @@ class Youtube(ModuleBase):
self.bot.act_PRIVMSG(args[0], "YouTube: No results found.")
else:
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):
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…
Cancel
Save