def select_one_song(songs):
"""Display the songs returned by search api.
:params songs: API['result']['songs']
:return: a Song object.
"""
if len(songs) == 1:
select_i = 0
else:
table = PrettyTable(['Sequence', 'Song Name', 'Artist Name'])
for i, song in enumerate(songs, 1):
table.add_row([i, song['name'], song['ar'][0]['name']])
click.echo(table)
select_i = click.prompt('Select one song', type=int, default=1)
while select_i < 1 or select_i > len(songs):
select_i = click.prompt('Error Select! Select Again', type=int)
song_id, song_name = songs[select_i-1]['id'], songs[select_i-1]['name']
song = Song(song_id, song_name)
return song
评论列表
文章目录