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
|
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]:
|
||||||
try:
|
return
|
||||||
search_response = (
|
try:
|
||||||
self.youtube.search()
|
search_response = (
|
||||||
.list(
|
self.youtube.search()
|
||||||
q=self.command.content,
|
.list(
|
||||||
part="id,snippet",
|
q=self.command.content,
|
||||||
maxResults=1,
|
part="id,snippet",
|
||||||
)
|
maxResults=1,
|
||||||
.execute()
|
|
||||||
)
|
)
|
||||||
except GoogleApiError:
|
.execute()
|
||||||
self.signal_failure(target)
|
)
|
||||||
return
|
except GoogleApiError:
|
||||||
|
self.signal_failure(target)
|
||||||
|
return
|
||||||
|
|
||||||
link = ""
|
link = ""
|
||||||
for result in search_response.get("items", []):
|
icon = ""
|
||||||
if result["id"]["kind"] == "youtube#video":
|
title = ""
|
||||||
video_id = result["id"]["videoId"]
|
self.bot.log_i(str(search_response))
|
||||||
link = self.VIDEO_URL_FMT.format(video_id)
|
for result in search_response.get("items", []):
|
||||||
elif result["id"]["kind"] == "youtube#channel":
|
kind = result["id"]["kind"]
|
||||||
channel_id = result["id"]["channelId"]
|
if kind == "youtube#video":
|
||||||
link = self.CHANNEL_URL_FMT.format(channel_id)
|
video_id = result["id"]["videoId"]
|
||||||
elif result["id"]["kind"] == "youtube#playlist":
|
link = self.VIDEO_URL_FMT.format(video_id)
|
||||||
playlist_id = result["id"]["playlistId"]
|
icon = "📼"
|
||||||
link = self.PLAYLIST_URL_FMT.format(playlist_id)
|
elif kind == "youtube#channel":
|
||||||
if link:
|
channel_id = result["id"]["channelId"]
|
||||||
break
|
link = self.CHANNEL_URL_FMT.format(channel_id)
|
||||||
else:
|
icon = "📺"
|
||||||
self.signal_failure(target)
|
elif kind == "youtube#playlist":
|
||||||
return
|
playlist_id = result["id"]["playlistId"]
|
||||||
self.bot.say(target, link)
|
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