目前正在学习python来原谅我,但我正在使用这个musicbrainzngs API从用户输入中获取艺术家姓名的ID。然后,它应该获取 ID 并列出相关艺术家的 5 首随机歌曲。现在我正在尝试弄清楚从相关艺术家那里获取 ID,以便可以在单独的搜索中使用它来返回该艺术家的 5 首歌曲。
文档 API:https://python-musicbrainzngs.readthedocs.io/en/v0.7.1/usage/
代码如下所示:
from urllib.request import Request, urlopen
import musicbrainzngs
import sys
musicbrainzngs.set_useragent("LyricsWordCount", "1.0", "azizn03",)
#musicbrainzngs.set_hostname("musicbrainz.org", use_https=False)
artist = input("Enter Artist Name ")
result = musicbrainzngs.search_artists(artist="" + artist, type="group",
country="GB")
for artist in result['artist-list']:
print("{name}: {id}".format(name=artist["name"], id=artist['id']))
结果:
Enter Artist Name coldplay
Coldplay: cc197bad-dc9c-440d-a5b5-d52ba2e14234
Viva La Coldplay: 62c54a75-265f-4e13-ad0a-0fb001559a2e
The Beatles: b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d
The Rolling Stones: b071f9fa-14b0-4217-8e97-eb41da73f598
Pink Floyd: 83d91898-7763-47d7-b03b-b92132375c47
George Frideric Handel: 27870d47-bb98-42d1-bf2b-c7e972e6befc
使用这个:
id_of_first_artist = result['artist-list'][0]['id']