【问题标题】:musicbrainzngs: grab ID from artist searchmusicbrainzngs:从艺术家搜索中获取 ID
【发布时间】:2020-02-01 18:34:38
【问题描述】:

目前正在学习 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,即第一个coldplay结果之后的字符串并将其存储在一个变量中。@myke @DYZ
  • @myke 这是pastebin.com/DkvCV7Qd的输出
  • 那是什么输出?

标签: python dictionary musicbrainz


【解决方案1】:

使用这个:

id_of_first_artist = result['artist-list'][0]['id']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多