From 31c3fb9ada2e29c40025b9cbc95af2143abd177b Mon Sep 17 00:00:00 2001 From: david Date: Sat, 13 Feb 2021 00:11:45 -0600 Subject: [PATCH] add some logic so that it doesn't give errors if no YT results are found --- music.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/music.py b/music.py index 60727cd..76bcf08 100755 --- a/music.py +++ b/music.py @@ -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() \ No newline at end of file + main()