youtube: add title and an response type icon

This commit is contained in:
dece 2022-08-15 13:21:24 +02:00
parent 3831987d9d
commit 0978b43d2c

View file

@ -40,7 +40,8 @@ class YoutubePlugin(Plugin):
return False
def handle_commands(self, target):
if self.command.ident == self.config["commands"][0]:
if self.command.ident != self.config["commands"][0]:
return
try:
search_response = (
self.youtube.search()
@ -56,19 +57,27 @@ class YoutubePlugin(Plugin):
return
link = ""
icon = ""
title = ""
self.bot.log_i(str(search_response))
for result in search_response.get("items", []):
if result["id"]["kind"] == "youtube#video":
kind = result["id"]["kind"]
if kind == "youtube#video":
video_id = result["id"]["videoId"]
link = self.VIDEO_URL_FMT.format(video_id)
elif result["id"]["kind"] == "youtube#channel":
icon = "📼"
elif kind == "youtube#channel":
channel_id = result["id"]["channelId"]
link = self.CHANNEL_URL_FMT.format(channel_id)
elif result["id"]["kind"] == "youtube#playlist":
icon = "📺"
elif kind == "youtube#playlist":
playlist_id = result["id"]["playlistId"]
link = self.PLAYLIST_URL_FMT.format(playlist_id)
icon = ""
if link:
title = result["snippet"]["title"]
break
else:
self.signal_failure(target)
return
self.bot.say(target, link)
self.bot.say(target, f"{icon} {link} {title}")