Python 第一次通过last.fm API播放曲目的最有效方式是什么
我正在尝试获取从last.fm API播放的第一首曲目。我能弄清楚如何在第一次播放给定曲目时获取的唯一方法是迭代user.getRecentTracks方法的所有实例。这是非常低效的。还有其他人有其他建议吗?API允许您获取此数据的唯一其他方式是使用资源,它允许您获取用户的所有曲目播放,并由特定艺术家过滤 API返回一个曲目列表,您可以解析和筛选这些曲目以获得所需的曲目,并且可以检索该曲目的scrobbles历史记录 下面是一个使用的示例:Python 第一次通过last.fm API播放曲目的最有效方式是什么,python,api,last.fm,Python,Api,Last.fm,我正在尝试获取从last.fm API播放的第一首曲目。我能弄清楚如何在第一次播放给定曲目时获取的唯一方法是迭代user.getRecentTracks方法的所有实例。这是非常低效的。还有其他人有其他建议吗?API允许您获取此数据的唯一其他方式是使用资源,它允许您获取用户的所有曲目播放,并由特定艺术家过滤 API返回一个曲目列表,您可以解析和筛选这些曲目以获得所需的曲目,并且可以检索该曲目的scrobbles历史记录 下面是一个使用的示例: from __future__ import prin
from __future__ import print_function
import pylast
API_KEY = 'API-KEY-HERE'
API_SECRET = 'API-SECRET-HERE'
username = 'your-user-to-authenticate'
password_hash = pylast.md5('your-password')
# Specfy artist and track name here
artist_name = 'Saori@destiny'
track_name = 'GAMBA JAPAN'
# Authenticate and get a session to last.fm (we're using standalone auth)
client = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET,
username = username, password_hash = password_hash)
# Get an object representing a specific user
user = client.get_user(username)
# Call get_artist_tracks to retrieve all tracks a user
# has played from a specific artist and filter out all
# playbacks that aren't your track
track_scrobbles = [x for x in user.get_artist_tracks(artist_name)
if x.track.title.lower() == track_name.lower()]
# It just so happens that the API returns things in reverse chronological order
# of playtimes (most recent plays first), so you can just take the last item
# in the scrobbled list for the track you want
first_played = track_scrobbles[-1]
# first_played is of type PlayedTrack, which is a named tuple in the lastpy lib
print("You first played {0} by artist {1} on {2}".format(first_played.track.title,
first_played.track.artist,
first_played.playback_date))