pylast
pylast copied to clipboard
Track fetched is not the most listened to/popular track on LastFM and therefore misses metadata
What did you do?
I tried reading metadata after retrieving a track with specific artist name and track title (eg. Khruangbin, Maria También).
What did you expect to happen?
I expected to receive the track object describing the most popular track available, and therefore with the highest probability of containing all the metadata.
What actually happened?
The track I got in the case described (and others) is a lower search result found (checked by comparing listeners and scrobbles in the metadata and on the website). As a result, the track object retrieved via the API usually miss useful metadata, such as mbid or album.
What versions are you using?
- OS: Ubuntu 20.04.4 LTS
- Python: Python 3.8.10
- pylast: 5.0.0
Please include code that reproduces the issue.
The best reproductions are self-contained scripts with minimal dependencies.
@get_network
def get_track_metadata(network: pylast.LastFMNetwork, artist: str, title: str) -> dict:
track = network.get_track("Khruangbin", "Maria También")
return {
"artist": track.get_artist(),
"title": track.get_title(),
"album": track.get_album(),
"mbid": track.get_mbid()
}
Let's see what's happening here.
network.get_track("Khruangbin", "Maria También") creates a Track object using those strings, with no network calls.
track.get_artist() returns an Artist object, created from those strings, no network calls.
track.get_title() returns the title string again, no network calls.
track. get_album() is the first network call, to track.getInfo and returns this, which doesn't contain any album info, so pylast returns None:
<lfm status="ok">
<track>
<name>Maria También</name>
<url>https://www.last.fm/music/Khruangbin/_/Maria+Tambie%CC%81n</url>
<duration>0</duration>
<streamable fulltrack="0">0</streamable>
<listeners>258</listeners>
<playcount>1314</playcount>
<artist>
<name>Khruangbin</name>
<mbid>aea4c9b9-9f8d-49dc-b2ca-57d6f26e8634</mbid>
<url>https://www.last.fm/music/Khruangbin</url>
</artist>
<toptags/>
</track>
</lfm>
track.get_mbid() also calls track.getInfo, and again there's no MBID data there, so pylast returns None.