question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random song won't work with albums

See original GitHub issue

When using the random_song parameter the current implementation will always call user_playlist_tracks(uri) regardless if a playlist or an album was provided using uri. Consequently the call will fail for album uris like 'spotify:album:5wuthq3XXmrpwlowdNxsBf' and execution will stop.

Quick fix I did for myself:

           if random_song:
                if uri.find('album') > 0:
                    results = client.album_tracks(uri)
                if uri.find('playlist') > 0:
                    results = client.playlist_tracks(uri)
                position = random.randint(0, results['total'] - 1)
                _LOGGER.debug('Start playback at random position: %s', position)
                kwargs['offset'] = {'position': position}

Btw, user_playlist_tracks() is deprecated, that’s why I changed it to playlist_tracks().

Thank’s for your great component!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
kleinc80commented, Feb 22, 2020

Thank’s for pointing me into the right direction! I’ll have a look, however, after your explanation it seems pretty clear anyway…

0reactions
fondbergcommented, Feb 22, 2020

First, the flow that HA is using doesn’t matter as all flows can get you a token with the selected scopes (list available on the spotify developer site, this list lacks the one that is needed to start chromecast on an idle cast device. The name of this scope is gone from my memory but I have it somewhere)

The token you receive using any of the flows lacks a scope to start chromecast on an idle chromecast device. It will be powerful enough for connect devices as well as play something on an already started spotify app on chromecast given the app was started in the same account (by for instance an official spotify app)

You can try this yourself if you want by using your token you received and a standalone pychromecast checkout. In pychromcast there is a spotify example. Modify it so it takes your token instead of the scraped token and make sure your chromecast device doesn’t have spotify running.

You will hear the bloink when spotify starts on the device but it will fail after the token is sent to the device.

When I spoke with the team responsible for cast at spotify they were clear that they only let themselves and google have this capability and did not plan to let API users have access to this capability. Since then there are a few more commercial integrations that has been granted this bit they are still a very select few.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Random songs won't sync to iTunes - Apple Community
Why won't some songs sync to my phone? It's always random and about ~10% of my library, from random albums. Syncing again shuffles...
Read more >
Can't listen to an album in order, random songs ke...
I open an album, start with the first song, and the second one is some random **bleep** that has nothing to do with...
Read more >
What to do if a song is “not currently available in your country ...
Apple Music and iTunes users keep getting alerts that "This song is not currently available in your country or region." We can fix...
Read more >
Does anyone else constantly get “This song is not currently ...
Random songs from random artists and albums will randomly become unavailable and I'm not sure why. It can't be because artists remove it ......
Read more >
Plays incorrect song, playlist, artist or album - Google Nest Help
If you're trying to play a specific song, playlist, artist or album from a ... Important: Some voice commands below may not work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found