spotify 有提供 API 接口,Python 也有官方的库可以调用:
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
# 设置你的Spotify API凭证
client_id = '你的Client ID'
client_secret = '你的Client Secret'
# 认证
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=client_id, client_secret=client_secret))
# 搜索歌曲
song_name = "你的歌曲名"
artist_name = "你的艺术家名"
results = sp.search(q=f"track:{song_name} artist:{artist_name}", type='track')
# 获取第一个结果的专辑链接
if results['tracks']['items']:
album_url = results['tracks']['items'][0]['album']['external_urls']['spotify']
print(f"专辑链接: {album_url}")
else:
print("未找到结果")
|