forked from david/telegram-music-bot
add some logic so that it doesn't give errors if no YT results are found
This commit is contained in:
parent
fe29eb47e7
commit
31c3fb9ada
9
music.py
9
music.py
@ -65,9 +65,12 @@ def inlinequery(update, context: CallbackContext):
|
|||||||
songlink = "https://song.link/{0}".format(sp_link)
|
songlink = "https://song.link/{0}".format(sp_link)
|
||||||
yt_q = f"{sp_artist} - {sp_title}"
|
yt_q = f"{sp_artist} - {sp_title}"
|
||||||
yt_res = ytmusic.search(yt_q, 'songs', limit=1)
|
yt_res = ytmusic.search(yt_q, 'songs', limit=1)
|
||||||
yt_id = util.get(yt_res, f"[1]/videoId")
|
if yt_res == 0:
|
||||||
yt_link = f"https://music.youtube.com/watch?v={yt_id}"
|
yt_id = util.get(yt_res, f"[1]/videoId")
|
||||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("YouTube", url = yt_link), InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("More", url = songlink)]])
|
yt_link = f"https://music.youtube.com/watch?v={yt_id}"
|
||||||
|
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("YouTube", url = yt_link), InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("More", url = songlink)]])
|
||||||
|
else:
|
||||||
|
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("More", url = songlink)]])
|
||||||
|
|
||||||
description = f"By {sp_artist} on the album {sp_albname}, released {sp_albdate}"
|
description = f"By {sp_artist} on the album {sp_albname}, released {sp_albdate}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user