tfmart / ScrobbleKit

A Swift library for interacting with the Last.fm API on Apple platforms

Home Page:https://tfmart.github.io/ScrobbleKit/documentation/scrobblekit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SimilarTracks

ridmaur opened this issue · comments

When asking for similar tracks using getSimilarTracks(_:autoCorrect:limit:) I see a lot of JSON output in my Xcode console (which I did not ask for btw) showing me an array of similarTracks with this structure:

{
    "similartracks": {
        "track": [
            {
                "name": "exes",
                "playcount": 2673662,
                "match": 1.0,
                "url": "https://www.last.fm/music/Tate+McRae/_/exes",
                "streamable": {
                    "#text": "0",
                    "fulltrack": "0"
                },
                "artist": {
                    "name": "Tate McRae",
                    "url": "https://www.last.fm/music/Tate+McRae"
                },
                "image": [
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": "small"
                    },
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": "medium"
                    },
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": "large"
                    },
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": "extralarge"
                    },
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": "mega"
                    },
                    {
                        "#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png",
                        "size": ""
                    }
                ]
            },
            ...
} 

I looks like the [SBTrack] info returned by the API call is different than the track info in the JSON. I miss for example the match attribute and there is no listeners attribute in the JSON, so when using the listeners attribute of the returned track it returns nothing.

Is this on purpose?

Hi @ridmaur, thanks for taking the time to write this issue. My apologies for the logging; I plan to remove it in an upcoming patch.

Regarding the match property, I've omitted it for now as I honestly could not find any information on Last.fm API docs or somewhere else about what that value is supposed to mean. However, if you have any information about what the match property purpose is or if you would find it interesting to return it, I could provide.

As for the listeners attribute, not all Last.fm API methods return this field, so in these cases this field is a nil value. The SBKTrack is used in various methods that ScrobbleKit provides, such as search(track:) and getArtistTopTracks(_:), so it consolidates all fields that may be returned in these different methods, which some omit some data while other do not.

If you have any feedback on how to improve the response for this method, feel free to comment on this thread.

I think the match attribute gives a number ranging from 0 ... 1 on how well the tracks match with the original one. It looks like the API call returns the matches in descending order (starting with 1.0 ...).

I see. From my tests, I remember seeing results that were greater than 10.0, but they were quite uncommon. I'll see if I can replace this weird results, but I suppose it should be safe to assume that is the intent and it could be useful to ScrobbleKit to have it returned as well. I'll make sure to include this change on a future update

I've just released a new version which fixes the issues described in this thread. Thanks for opening this issue!