add some logic so that it doesn't give errors if no YT results are found

This commit is contained in:
David Daily 2021-02-13 00:11:45 -06:00
parent fe29eb47e7
commit 31c3fb9ada
1 changed files with 7 additions and 4 deletions

View File

@ -65,9 +65,12 @@ def inlinequery(update, context: CallbackContext):
songlink = "https://song.link/{0}".format(sp_link)
yt_q = f"{sp_artist} - {sp_title}"
yt_res = ytmusic.search(yt_q, 'songs', limit=1)
yt_id = util.get(yt_res, f"[1]/videoId")
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)]])
if yt_res == 0:
yt_id = util.get(yt_res, f"[1]/videoId")
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}"
@ -154,4 +157,4 @@ def main():
if __name__ == '__main__':
main()
main()