我可以正确调用Spotify API的音频分析方法吗?

时间:2019-07-31 12:35:00

标签: python api spotify

为什么我的API调用会给出多次重复的长输出,这是代码的预期结果还是我做错了什么?

(1)以下是我用来调用audio_analysis方法的方法,如文档中所述。

analysis = sp.audio_analysis('Your_Track_ID_Here')
print(analysis)

(2)以前,我遇到过“超出iopub数据速率”的问题。我更改了配置,并尝试仅在参数中输入1首歌曲ID,该问题最终得以解决。

但是,即使对于单首歌曲进行分析,输出仍然非常长。我想知道我做错了什么。

(3)我以前尝试了API中的audio_features方法,并且输出是这样的完美:

    [{'danceability': 0.674, 'energy': 0.618, 'key': 8, 'loudness': -7.368, 'mode': 1, 'speechiness': 0.0241, 'acousticness': 0.932, 'instrumentalness': 0, 'liveness': 0.132, 'valence': 0.331, 'tempo': 100.015, 'type': 'audio_features', 'id': '1atjghnkmdsiexphBSF4Yc', 'uri': 'spotify:track:1atjghnkmdsiexphBSF4Yc', 'track_href': 'https://api.spotify.com/v1/tracks/1atjghnkmdsiexphBSF4Yc', 'analysis_url': 'https://api.spotify.com/v1/audio-analysis/1atjghnkmdsiexphBSF4Yc', 'duration_ms': 191975, 'time_signature': 4}])

但是,在我使用了音频分析方法之后。直到这部分跨越多行为止,输出正常。

"codestring":eJxdmgu2KykOBLfiJfBH7H9jL0LY167Xc3r6gl0UoFQqE3x2r7FPG6_yqrWVc0YfrxZBq7YZs8Vr7vU6-b264xWLz0errcXkW2M3mnWUOHy1lSjvZuv81Vf8NhfjRjl71cJT_JfRohf-Wa_eGHicOqPOul89GJhPdymHp8Zg4Ki1nz1tbga2OepyhiU-zbn7a_Yc-ZTa26S5PiO3VvtrtcfIzOl35F0fI-9B35wsvu392puB2y4z1mqHpTDwjBNjFsboYasch_b9vub0M0ct48XuFHfxzDrZijN5zVkn-uwj_8oZ8_LS24t5RX657U5o2K3iPu7OShaBKr1nSHpjDYv2cCJtth6zbNrbqcxFAH2SUDoDHm-VBdHuq9wg9haN9voLm1GsNdf5FzdiPX0Lz4OMzheamNirV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3oedProytVAaatGSUXFeJeFMIEt-fj4HDbDnPVtfv6JCX_g-hbuqotb2PPGWhh5-lE_Kw5D........."

对于多个变量,例如持续时间,置信度,响度,音高等,也有多次重复,这些变量跨越几页长(对于一首歌曲)。

我的输出的最小可复制代码如下:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
cid ="Your_id_here" 
secret = "Your_secret_key_here"
client_credentials_manager = SpotifyClientCredentials(client_id=cid, 
client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
analysis = sp.audio_analysis('YOUR_TRACK_ID_HERE')
print(analysis)

感谢您的帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

根据Get Audio Analysis for a Track API和我自己对API的了解,“代码字符串”是该API响应对象的有效部分,但是如果不需要,则可以忽略其值-在我自己的C#中,我已经做完了,然后才忽略该值。

如果您使用API​​控制台,则应该找到返回的JSON部分。

但是,如果您需要该值,那么我认为它是某物的基数64编码值,但是如果您需要该值,则可能需要获取更深入的信息,但它可能只是返回的柱形图,基准图等在通话的其余部分