youtube: add title and an response type icon
This commit is contained in:
parent
3831987d9d
commit
0978b43d2c
|
@ -40,7 +40,8 @@ class YoutubePlugin(Plugin):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_commands(self, target):
|
def handle_commands(self, target):
|
||||||
if self.command.ident == self.config["commands"][0]:
|
if self.command.ident != self.config["commands"][0]:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
search_response = (
|
search_response = (
|
||||||
self.youtube.search()
|
self.youtube.search()
|
||||||
|
@ -56,19 +57,27 @@ class YoutubePlugin(Plugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
link = ""
|
link = ""
|
||||||
|
icon = ""
|
||||||
|
title = ""
|
||||||
|
self.bot.log_i(str(search_response))
|
||||||
for result in search_response.get("items", []):
|
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"]
|
video_id = result["id"]["videoId"]
|
||||||
link = self.VIDEO_URL_FMT.format(video_id)
|
link = self.VIDEO_URL_FMT.format(video_id)
|
||||||
elif result["id"]["kind"] == "youtube#channel":
|
icon = "📼"
|
||||||
|
elif kind == "youtube#channel":
|
||||||
channel_id = result["id"]["channelId"]
|
channel_id = result["id"]["channelId"]
|
||||||
link = self.CHANNEL_URL_FMT.format(channel_id)
|
link = self.CHANNEL_URL_FMT.format(channel_id)
|
||||||
elif result["id"]["kind"] == "youtube#playlist":
|
icon = "📺"
|
||||||
|
elif kind == "youtube#playlist":
|
||||||
playlist_id = result["id"]["playlistId"]
|
playlist_id = result["id"]["playlistId"]
|
||||||
link = self.PLAYLIST_URL_FMT.format(playlist_id)
|
link = self.PLAYLIST_URL_FMT.format(playlist_id)
|
||||||
|
icon = "➕"
|
||||||
if link:
|
if link:
|
||||||
|
title = result["snippet"]["title"]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.signal_failure(target)
|
self.signal_failure(target)
|
||||||
return
|
return
|
||||||
self.bot.say(target, link)
|
self.bot.say(target, f"{icon} {link} {title}")
|
||||||
|
|
Loading…
Reference in a new issue