def search_song(bot, update):
user = update.message.from_user
song_name = update.message.text
logger.info('search_song for user %s and song name %s' % (user, song_name))
url = '{}/song/{}'
resp = requests.get(
url=url.format(API_SERVER, song_name)
)
if resp.status_code != 200 or not resp.json():
update.message.reply_text('Lo siento pero lo que estás buscando es demasiado raro incluso para Spotify')
return ConversationHandler.END
else:
song_list = json.loads(resp.content)
update.message.reply_text(
u"""{} (Popularidad% {})\nActividad: {}\nAlbum: {}\nArtistas: {}\n{}\n{}""".format(
song_list[0]['track_name'],
song_list[0]['track_popularity'],
song_list[0]['activity'],
song_list[0]['track_album_name'],
','.join(a['name'] for a in song_list[0]['artists']),
song_list[0]['thumb'],
song_list[0]['external_url'],
),
reply_markup=ReplyKeyboardMarkup(
SONG_KEYBOARD,
one_time_keyboard=True,
resize_keyboard=True
)
)
bot.song_cache = song_list[0]
return SONG_ACTION
评论列表
文章目录