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
11
music.py
11
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()
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user