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

Error on retrieving playback when a local file is playing #200

Closed
allerter opened this issue Aug 1, 2020 · 6 comments
Closed

Error on retrieving playback when a local file is playing #200

allerter opened this issue Aug 1, 2020 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@allerter
Copy link
Contributor

allerter commented Aug 1, 2020

Issue

If I try to get the user's playback using playback() or playback_currently_playing(), and the useris playing a local file at that moment, I get the following error:
TypeError: __init__() missing 1 required positional argument: 'total_tracks'

Expected behavior

If the user is playing a local file, the fetched result should contain the track's name and artist, but the album should be empty.

Steps to reproduce

cred = tk.RefreshingCredentials(SPOTIFY_CLIENT_ID,
                                SPOITFY_CLIENT_SECRET)
token = cred.refresh_user_token(SPOTIFY_REFRESH_TOKEN)
spotify = tk.Spotify(token)
spotify.playback_currently_playing()  # or spotify.playback()
@allerter allerter added the bug Something isn't working label Aug 1, 2020
@allerter allerter changed the title Error on retrieving playback when a local track is playing Error on retrieving playback when a local file is playing Aug 1, 2020
@felix-hilden
Copy link
Owner

Thank you for the report! Since it's a local track, it might be better off with similar "empty" artists as other members already are. Not sure yet. I'll take a look tomorrow and get back to you!

@allerter
Copy link
Contributor Author

allerter commented Aug 2, 2020

Manually requesting the playback returned the following result for a local file:

{
  "timestamp" : 1596383702885,
  "context" : null,
  "progress_ms" : 2270,
  "item" : {
    "album" : {
      "album_type" : null,
      "artists" : [ ],
      "available_markets" : [ ],
      "external_urls" : { },
      "href" : null,
      "id" : null,
      "images" : [ ],
      "name" : "Manic (Deluxe)",
      "release_date" : null,
      "release_date_precision" : null,
      "type" : "album",
      "uri" : null
    },
    "artists" : [ {
      "external_urls" : { },
      "href" : null,
      "id" : null,
      "name" : "Halsey",
      "type" : "artist",
      "uri" : null
    } ],
    "available_markets" : [ ],
    "disc_number" : 0,
    "duration_ms" : 174000,
    "explicit" : false,
    "external_ids" : { },
    "external_urls" : { },
    "href" : null,
    "id" : null,
    "is_local" : true,
    "name" : "929",
    "popularity" : 0,
    "preview_url" : null,
    "track_number" : 0,
    "type" : "track",
    "uri" : "spotify:local:Halsey:Manic+%28Deluxe%29:929:174"
  },
  "currently_playing_type" : "track",
  "actions" : {
    "disallows" : {
      "pausing" : true,
      "skipping_prev" : true
    }
  },
  "is_playing" : false
}

Although many of the files are empty and have no data, that's not the case for all of them. For example item.artist[0].name, item.name and item.album.name (as they'd be accessed using Tekore) are provided and could be useful (for example Discord displays any of the three fields I mentioned if they are present). And whenever those fields weren't present, the request returned an empty string for their value.

@felix-hilden
Copy link
Owner

Thanks a lot! This info helps a ton already 😄

@felix-hilden
Copy link
Owner

Okay, so most likely we'll need to introduce similar "local" versions of objects to playback endpoints as we have for playlist items already. I managed to parse the response using the same LocalTrack as we already have, but I'll validate and test more thouroughly, we could even manage to make the very loose None attributes a bit more strict overall.

@felix-hilden felix-hilden self-assigned this Aug 3, 2020
@felix-hilden
Copy link
Owner

Our test coverage will take a hit, as we have no way of testing this automatically by starting playback of a local track. But I'm A-OK with that. Also turns out that the local objects are already quite strict meaning they don't allow any missing attributes. So we're good to go.

@felix-hilden
Copy link
Owner

@allerter This fix is now released with the new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants