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