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

Spotify: Missing random_song: true #31607

Closed
starkillerOG opened this issue Feb 7, 2020 · 23 comments
Closed

Spotify: Missing random_song: true #31607

starkillerOG opened this issue Feb 7, 2020 · 23 comments
Assignees

Comments

@starkillerOG
Copy link
Contributor

starkillerOG commented Feb 7, 2020

The problem

First of all thank you for the improvements to the new sportify integration!

The new Spotify integration has depricated the spotify.play_playlist service.
That service supported "random_song: true" to start your playlist at a random song instead of always the first one. I do not think this is possible to do using the media_player.play_media service.
It is really annoying to always have to listen to the same first song of a playlist using shortcut buttons in HomeAssistant. Therefore I really loved the "random_song: true" option.
Can this option be re-added to the media_player.play_media service to get this functionallity back?

Or how can this be done using the media_player.play_media service?

Environment

  • Home Assistant release with the issue: 0.105.2
  • Last working Home Assistant release (if known): 0.104.x
  • Operating environment (Hass.io/Docker/Windows/etc.): Linux, python_version 3.7.3
  • Integration causing this issue: Spotify
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/spotify/

Problem-relevant configuration.yaml

Traceback/Error logs

Additional information

@probot-home-assistant
Copy link

Hey there @frenck, mind taking a look at this issue as its been labeled with a integration (spotify) you are listed as a codeowner for? Thanks!

@whattheschnell
Copy link

Curious about the same thing...

@frenck
Copy link
Member

frenck commented Feb 10, 2020

The shuffle service is available for enabling shuffle play on media players.

@starkillerOG
Copy link
Contributor Author

@frenck the shuffle service will only make the next songs random and not follow the playlist. However even if the shuffle service is enabled, when you call media_player.play_media with a playlist URI it will always start at the first song of the playlist and if shuffle is on it will then pick a random second song.

the random_song: true made that first song random, if then shuffle was disabled it would then continue the playlist in order from that first random song, if shuffle was enabled it would then go on by picking random songs for the 2nd 3th etc song.

@frenck
Copy link
Member

frenck commented Feb 10, 2020

So, to fix this, we need to push out the current shuffle state when starting a playlist, right?

That way, you can enable shuffle, and start a playlist. Any playlist started when shuffle is enabled on the media player, will start a playlist at random.

How does that sound?

@starkillerOG
Copy link
Contributor Author

@frenck yes that sounds good.
For me that would be perfectly fine.

Although I could image use cases where people would like to start a playlist at a random song and then continue in order of the playlist.

Therefore we could also opt for a extra attribute to the media_player.play_media service called something like "shuffle_start" or "random_start" or something like that. This attribute would control if the first song was random or not, and the shuffle service would control what happens for all next songs.

I don't have a strong prefrence, but I think a extra attribute would provide for a bit more flexibility.

@frenck
Copy link
Member

frenck commented Feb 10, 2020

Although I could image use cases where people would like to start a playlist at a random song and then continue in order of the playlist.

Turn off shuffle again 😉

automation: set shuffle on, start playlist, set shuffle off.

I don't think actual new features to the system are needed for implementing that kind of logic.

Besides, adding new features to core parts of the system, need good general uses cases and need to be approved as an architectural proposal.

@starkillerOG
Copy link
Contributor Author

@frenck so obvious, how could I have missed that.
You are absolutely right!

So then indeed just making sure the playlist starts random if shuffle is turned on using the shuffle service would fix this!

@whattheschnell
Copy link

shuffle function isn't accessible to the frontend like it used to be. Am i missing something?

@ghost

This comment has been minimized.

@frenck
Copy link
Member

frenck commented Feb 11, 2020

@artaxx81 I marked your post hidden, I really suggest you change your attitude quite a bit since your tone could get you banned. You are violating our Code of Conduct.

As for the issue, it is being discussed here, in this issue, how we can resolve this in a way that is more fitting for Home Assistant compared to the previous implementation. We all work towards a better piece of software, your comment doesn't really help with that.

@ghost
Copy link

ghost commented Feb 11, 2020

Hi Frenck, I've just deleted the post. Sorry for that but I am really depressed because of that. I was working very hard on a very important project which is broken now.

I promise that I will clear up myself!

@ghost
Copy link

ghost commented Feb 11, 2020

OK, I found a workaround (not pretty but it does the trick):

I am starting the whole thing with an input_boolean, then I select the playing device with a

media_player.select_source

with entity_id and source.

Then I start the playlist with

media_player.play_media

and

{
    "media_content_id": "spotify:playlist:xxx",
    "media_content_type": "playlist"
}

After that I set shuffle on with

media_player.shuffle_set

And after this I force the playing device (!) to jump one song forward with

media_player.media_next_track

As I mentioned: Not pretty but It works. The delay between trying to play the first song and skipping to the next is so low that you will only mention it because it's showing up for a split second.

The curious thing is that when I do a media_player.media_next_track on the spotify player it plays always the same NEXT song. It only works when I am doing a media_player.media_next_track on the real playing device.

I am using Volumio. I am not able to say if this works on other playing devices as well!

I think the problem is that you cannot set shuffle before starting the playlist (only after). The random_song: true attribute of the play_playlist service was apparently able to do that or it used another API call for start playing a playlist with a random song.

For now that shown workflow above does the trick for me!

I hope this will help someone and I would like to apologize for the first hidden and now deleted post of mine. I am working hard on myself to fit into here as I am very new to github!

Thank you all!

@whattheschnell

This comment has been minimized.

@ghost
Copy link

ghost commented Feb 11, 2020

Just found an error in my solution.

The right order is:

1. Start playing the playlist
2. Set the playing device
3. Set Shuffle
4. Skip one track

If you first set the playing device and start the playlist after that it will arbitrary play the playlists first song obstinately!

@lealoureiro
Copy link
Contributor

The file services.yaml needs to cleaned as the custom service spotify.play_playlist is not available anymore.

@lealoureiro
Copy link
Contributor

I don't think it works setting shuffle on before start playing a playlist. The service media_player.play_media resets the shuffle i guess.

for me it always starts first music with shuffle off

script:

play_afrobeats_livingroom:
  alias: Play Afrobeats
  sequence:
  - service: script.set_spotify_amplifier_denon
  - wait_template: "{{ is_state('media_player.amplifier_denon', 'on') }}"
  - service: media_player.shuffle_set
    data_template:
      entity_id: media_player.spotify
      shuffle: true
  - service: media_player.play_media
    entity_id: media_player.spotify
    data_template:
      media_content_id: 'spotify:playlist:5PIqR8HgJrfeHy0gL9Ih0G'
      media_content_type: playlist
  - service: script.turn_off
    entity_id: script.play_afrobeats_livingroom

starkillerOG added a commit to starkillerOG/home-assistant that referenced this issue Feb 17, 2020
This adds a solution to the missing random_song:true attribute that was in the spotify.play_playlist service.
This fixes issue: home-assistant#31607
@starkillerOG
Copy link
Contributor Author

@frenck I just made a PR that schould fix this issue, based on the constructive discussion we had.
Could you take a look at it and merge it if you think it is okay?

@frenck
Copy link
Member

frenck commented Feb 22, 2020

This was discussed in PR #31933, and will add a summary to this issue for future reference.

So here I made a test case, with the currently released code, as in available in 0.105.

This is the official Spotify client, connected with my Premium account. I have used Home Assistant 0.106.0b1 for this recording (which has the same code as 0.105).

ℹ️ Please note the recording below shows the intended working of starting randomly in a playlist, but without any modification to the code base.

2020-02-22 16 10 17

Verified in the above recording:

  • Shuffle mode on/of visible in the client
  • Playlist starts at first item, when shuffle is off.
  • Playlist starts at random positions, when shuffle is on (each time at a new position when play_media service is called).
  • Shuffle keeps turned on after starting playing a playlist, while shuffle is on, pushing the next song button picks a next random song from the currently active playlist.

Lovelace configuration used for this demo

  - title: lab
    path: lab
    badges: []
    cards:
      - type: media-control
        entity: media_player.spotify_frenck_nl
      - type: button
        name: Shuffle off
        tap_action:
          action: call-service
          service: media_player.shuffle_set
          service_data:
            entity_id: media_player.spotify_frenck_nl
            shuffle: false
      - type: button
        name: Shuffle on
        tap_action:
          action: call-service
          service: media_player.shuffle_set
          service_data:
            entity_id: media_player.spotify_frenck_nl
            shuffle: true
      - type: button
        name: Start Hackers playlist
        tap_action:
          action: call-service
          service: media_player.play_media
          service_data:
            entity_id: media_player.spotify_frenck_nl
            media_content_type: playlist
            media_content_id: 'spotify:playlist:5PyDUMge81u29mYxQV949t'
        icon: 'mdi:planet'

The current implementation follows the API specs, as concluded, there may be clients out there that don't follow the spec.

As figured out by @starkillerOG in this comment: #31933 (comment)

@frenck frenck closed this as completed Feb 22, 2020
@realthk
Copy link
Contributor

realthk commented Mar 1, 2020

Unfortunately it is also broken on the Logitech Media Server Spotify client: that is also reseted to non-shuffle mode by play_media service call... :(

For example I have morning alarm with a Spotify playlist started on LMS by Home Assistant, and ever since the old Spotify component is gone, this always starts with the first song. Not too convenient.

I understand it is not the fault of Home Assistant, but the point is we used to have a working solution with the old Spotify component, but not anymore.

@starkillerOG
Copy link
Contributor Author

@realthk you can use spotcast, a custom component available on HACS.
That provided a single service with wich you can start Spotify playlist with aditional options and that also works if the player is in standby.
It provides the old random_song attribute

@realthk
Copy link
Contributor

realthk commented Mar 4, 2020

@starkillerOG Thanks, but I don't use cast (apart from Google Home Hub as TTS annoncement).
Currently I've collected several alarm playlists and choose randomly from those, it is somewhat better this way - but after a while it will be still boring to wake up on the same set of first songs, so I'll probably use your patch and have Spotify media player as custom component.

@floodwayprintco
Copy link

I think I am having similar issues with my Raspotify integration. Spotify is set to shuffle, Forked-Daapd is set to shuffle. I can see it enabled in Spotify. But starting a playlist adds it to the queue and plays in that order. I cannot replicate the screenshot above. It plays the same starting song every time and can't shuffle because the queue is filled with the playlist.

Really not sure what the issue is. I am calling the playlist the same way as above, but keep getting the same song and my queue filled with the ordered list.

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

Successfully merging a pull request may close this issue.

7 participants