Spotipy-从曲目名称获取曲目ID [英] Spotipy - get track ids from track names

查看:262
本文介绍了Spotipy-从曲目名称获取曲目ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,spotipy需要使用轨道ID作为要传递的参数,以便返回轨道名称.

Usually, spotipy requires track IDs as parameters to be passed, in order to return track names.

说我有两个列表,不是是从Spotify API获得的:

Say I have two lists, not obtained from the Spotify API:

  1. 艺术家

  1. artists

[u'Moses Sumney', u'Cherry Glazerr', u'Danny Brown', u'NxWorries']

及其各自的歌曲:

曲目

[u'Lonely World', u"Told You I'd Be With the Guys", u'Really Doe [ft. Kendrick Lamar, Ab-Soul, and Earl Sweatshirt]', u'Lyk Dis']

是否可以反过来获取轨道ID?

Is it possible to do it the other way around and get track IDs?

推荐答案

Spotipy.search()是您要寻找的东西.

Spotipy.search() is what you are looking for.

import spotipy
sp = spotipy.Spotify()

artist= 'Moses Sumney'
track= 'Lonely World'

track_id = sp.search(q='artist:' + artist + ' track:' + track, type='track')

这将返回与查询匹配的歌曲列表,这取决于搜索的精确程度取决于返回的结果.

This will return a list of songs that match the query, depending on how precise your search is will depend on how many results are returned.

这篇关于Spotipy-从曲目名称获取曲目ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆