Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search API provides full Album info but only SimpleAlbum is returned #15

Closed
zacwolfe opened this issue Apr 8, 2019 · 12 comments
Closed

Comments

@zacwolfe
Copy link

zacwolfe commented Apr 8, 2019

I don't know if the search api has changed recently or if this is true for only some queries but I'm seeing full album info being returned from track searches. The library should detect which type is returned and return the appropriate model rather than assuming AlbumSimple.

https://api.spotify.com/v1/search?q=track:sunny+artist:pat+martino&type=track returns (summarized):

    "tracks": {
        "href": "https://api.spotify.com/v1/search?query=track%3Asunny+artist%3Apat+martino&type=track&offset=0&limit=20",
        "items": [
            {
                "album": {
                    "album_type": "album",
                    "artists": [
                        {
                            "external_urls": {
                                "spotify": "https://open.spotify.com/artist/4DlMMgnldzX6OkCskmeGKz"
                            },
                            "href": "https://api.spotify.com/v1/artists/4DlMMgnldzX6OkCskmeGKz",
                            "id": "4DlMMgnldzX6OkCskmeGKz",
                            "name": "Pat Martino",
                            "type": "artist",
                            "uri": "spotify:artist:4DlMMgnldzX6OkCskmeGKz"
                        }
                    ],
                    "available_markets": [
                        ...
                    ],
                    "external_urls": {
                        "spotify": "https://open.spotify.com/album/6R8qLTLbNFxzfBoavYUCXy"
                    },
                    "href": "https://api.spotify.com/v1/albums/6R8qLTLbNFxzfBoavYUCXy",
                    "id": "6R8qLTLbNFxzfBoavYUCXy",
                    "images": [
                        {
                            "height": 640,
                            "url": "https://i.scdn.co/image/33e8507aca73dbac105ab66692166efa57ef5e93",
                            "width": 640
                        },
                        {
                            "height": 300,
                            "url": "https://i.scdn.co/image/2b0da092447fa0f56bb14c04846e81f1668d9a2d",
                            "width": 300
                        },
                        {
                            "height": 64,
                            "url": "https://i.scdn.co/image/41ca471da9baf47a7498b12d01c1784120894103",
                            "width": 64
                        }
                    ],
                    "name": "Cream",
                    "release_date": "1997-10-21",
                    "release_date_precision": "day",
                    "total_tracks": 10,
                    "type": "album",
                    "uri": "spotify:album:6R8qLTLbNFxzfBoavYUCXy"
                },
                "artists": [
                    {
                        "external_urls": {
                            "spotify": "https://open.spotify.com/artist/4DlMMgnldzX6OkCskmeGKz"
                        },
                        "href": "https://api.spotify.com/v1/artists/4DlMMgnldzX6OkCskmeGKz",
                        "id": "4DlMMgnldzX6OkCskmeGKz",
                        "name": "Pat Martino",
                        "type": "artist",
                        "uri": "spotify:artist:4DlMMgnldzX6OkCskmeGKz"
                    }
                ],
                "available_markets": [
                    ...
                ],
                "disc_number": 1,
                "duration_ms": 628186,
                "explicit": false,
                "external_ids": {
                    "isrc": "USSJ10904865"
                },
                "external_urls": {
                    "spotify": "https://open.spotify.com/track/6xHcMss02s14r2EdXLEqhk"
                },
                "href": "https://api.spotify.com/v1/tracks/6xHcMss02s14r2EdXLEqhk",
                "id": "6xHcMss02s14r2EdXLEqhk",
                "is_local": false,
                "name": "Sunny",
                "popularity": 35,
                "preview_url": null,
                "track_number": 2,
                "type": "track",
                "uri": "spotify:track:6xHcMss02s14r2EdXLEqhk"
            },
@rinukkusu
Copy link
Owner

Hmm, in the docs they still state they return a simplified version of the album object.
Also I'm not sure this actually is a full album object - it is missing the external_ids for instance. But it also has a total_tracks key which is not listed in the docs at all 🤔

@zacwolfe
Copy link
Author

zacwolfe commented Apr 8, 2019

Yes, good call. I'm not entirely sure how to differentiate the two but strangely release_date is there which, according to the docs, is only present in the full album object.

@rinukkusu
Copy link
Owner

I've added a switch for when release_date is present to deserialize as a full album instead of the simple one. Can you check if that works for you?

@zacwolfe
Copy link
Author

zacwolfe commented Apr 8, 2019

I think we need to have that check here, in order to populate the correct album object for track searches:

https://github.com/rinukkusu/spotify-dart/blob/master/lib/src/models/_models.g.dart#L272

Also I think it should be external_ids rather than external_idss

https://github.com/rinukkusu/spotify-dart/blob/master/lib/src/models/_models.g.dart#L282

Thanks again for your help!

@rinukkusu
Copy link
Owner

Uh yeah - idss definitely wasn't intended 😅

rinukkusu added a commit that referenced this issue Apr 8, 2019
rinukkusu added a commit that referenced this issue Apr 8, 2019
@rinukkusu
Copy link
Owner

I've published version 0.1.6+2 which includes the said switch for full or simplified album objects in the search and the fix for external_idss in the track object.

@zacwolfe
Copy link
Author

zacwolfe commented Apr 8, 2019

Awesome, thank you! The only issue I'm seeing now is that in the search track deserialization, SimpleAlbum is always returned (https://github.com/rinukkusu/spotify-dart/blob/master/lib/src/models/_models.g.dart#L272). I now realize that file wasn't coded by hand so I'm wondering how that case can be best handled.

Would it be possible/reasonable to do some Track post-processing in search.dart where you had added the album search switch and replace the SimpleAlbum with the full version if appropriate? I know that doesn't sound ideal either...

@rinukkusu
Copy link
Owner

Ah, I see - well to be fair we are spending most of the time waiting on the spotify api anyway. I don't think it would hurt to add it there as well.

rinukkusu added a commit that referenced this issue Apr 8, 2019
rinukkusu added a commit that referenced this issue Apr 8, 2019
@rinukkusu
Copy link
Owner

rinukkusu commented Apr 8, 2019

@zacwolfe I've moved the check to the AlbumSimple.fromJson method - so there it actually returns a full Album if need be. With this we cover all occurances of AlbumSimple and not just in the tracks search with no overhead. What do you think?

@zacwolfe
Copy link
Author

zacwolfe commented Apr 8, 2019

Great solution, I'll be testing it shortly!

@zacwolfe
Copy link
Author

zacwolfe commented Apr 9, 2019

looking good, thanks again

@rinukkusu
Copy link
Owner

Okay, perfect! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants