@jkw@phreaq I don’t think I ever got the shuffle mode working the way I intended.
If it does work the same, here what you can try
In gmusic_player, I needed to reload the playlist after changing this.
media_player.shuffle_set
This accepts a boolean so you can only turn shuffle off/on. Tracks are shuffled when the playlist is loaded.
Default is True and shuffle_mode: 1 so playback is similar to the switch. You’ll need to reload the playlist (stop/play) for this to take effect.
Shuffle Mode
This can only be set in the package configuration file which means for now having to reboot in order to change this.
I’ll use the term “track queue” to refer to the list playing songs. This could be a “playlist” or a “station” from your music library. There are three modes:
shuffle_mode: 1 - Shuffle (Default setting)
This is the default. Tracks are shuffled first then load to the “track queue”
The shuffled queue is played in order from top to bottom. Songs only repeat when the queue has reached the end and starts over.
shuffle_mode: 2 - Random
This loads the playlist songs is the same order they are saved in your library. Tracks are then randomly selected from anywhere in the queue. Since the queue itself is not being reordered, turning shuffle off/on has immediate effect. The downside here is when playing queues with small numbers of tracks it can seem like the same songs always repeat while others hardly get played.
shuffle_mode: 3 - Shuffle Random
Tracks are shuffled first then load to the “track queue”. Tracks are then randomly selected from anywhere in the queue.
I like the way it’s working but I can see that it could be simplify. Maybe another drop down select entry that has “direct/shuffle/random/random_shuffle” in it? + Default value in case the list doesn’t exist?
Jkw
@JKW - I’m sure see you lots of room for improvement I have made several attempts to rewrite the gmusic_player following along with the developer docs (and trying to learn Python at the same time). While I was never successful I did mange to gain some understanding of how (I think) gmusic_player should have been re-written.
For example, I have some unpublished versions started (somewhere) that is based using a config_flow.
These shuffle setting (along with the default number of playlist retrieved) are a perfect candidates to be added to options_flow portion of config_flow
Hmmm isn’t this something that one would want to change dynamical?
I’m pretty much only running playlist radio on my “thumbs up” list with radon activated. So it will start with a radon song from my list and continue with something “new”.
But I’ve also added the drop-down for the playlist selection to other dashboard, so I CAN switch the playlist. My “thumbs up” list is fairly Rock-Music-filled and for breakfast I switch via an automation to a “easy listen” playlist before starting the player.
The same would be possible with the shuffle. One could have a default setting and a drop-down to switch the mode without rebooting or reconfiguration via config flow. @phreaq what’s your opinion?
I like were that is going… In that case I resubmit,
Can you adapt it into something similar to this?
Click here to show
From gmusic_player, here is an example of how I ideally start playback. This media_player shown is usually accessed from a wall mounted tablet
Click here to show
Edit: I should add it is possible to store these values using the options_flow and still set them dynamically. The idea is that you set your own defaults using the options_flow. Then in your automations, you would provide a new value form any setting you want to over ride. If you do not include a value in the automation - the value store using options_flow would be used instead.
I have some questions about how the logic works, and I think it’s somewhere between the add in, and the API itself.
Assume I have a playlist with 20 songs from 20 different artists.
If I select that playlist as the ‘playlist’ option, and set ‘source’ to ‘playlist’, it will play the 20 songs from 20 different artists in order (unless you change you’re media_player to be random).
Whereas, if I change the 'source to ‘playlist radio’, it will randomly grab one song/artist, and base a new radio station based on that one song/artist?
Is that correct thinking?
The reason I ask is, when I play a certain playlist, with many, many songs in it (1000+), and have ‘source’ set as ‘playlist’, I only hear the more ‘recent’ songs added to the playlist, and not some of the songs that have been there for quite some time. It’s almost like it’s grabbing the last 25-35 songs only.
I took a look at the code, around the self._tracks = self._api.get_watch_playlist(videoId=r_track['videoId']), and the API has an option to pass a count, perhaps it can be used?
Hi, so first up: your explanation of “playlist” / “playlist radio” is spot on. And you’re also very likely right about the 25 song limit. I’ve created a ticket on GitHub https://github.com/KoljaWindeler/ytube_music_player/issues/10 so I won’t forget to work on this. Thanks
By Settings do you mean “Configuration” within Home Assistant? If so, when I click on “Add integration”, YouTube Music Player isn’t listed. Is there another way to add an integration that I’m missing?
Many thanks for all the effort in getting this working!
@JKW I just tried the latest build, and it seems to be hung up on ‘loading’ under the ‘playlist’ drop down. none of my playlist are coming up. tried two reboots, same issue.
@nameswilson good, the same thing happened to me … I’d assume that you didn’t hit “refresh” after the installation of the component, right? It seams to be necessary … I’ve added that to the docu now. And yes “settings” -> “configuration”. Thanks for pointing out
After you’ve installed this component and restarted Home Assistant please REFRESH the page, otherwise it might not show up in the list of integrations
Open Configuration -> Integrations -> “add integration” -> “YouTube Music Player”
@phreaq any log messages? I’ve just updated my main system without issues … The changes shouldn’t have affected the wait the playlists are loaded … could you try a “reinstall” of the component in hacs?
JKW
edit: excuse me, i was not really clear. I am referring to the issue that @phreaq mentioned.
I have not installed this component before, it’s a fresh install.
Playlist and Speaeker input selects stay “loading”.
Error in the log is:
2020-11-30 11:59:08 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up ytube_music_player platform for media_player
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/pi/.homeassistant/custom_components/ytube_music_player/media_player.py", line 39, in setup_platform
add_entities([yTubeMusicComponent(hass, config)], True)
File "/home/pi/.homeassistant/custom_components/ytube_music_player/media_player.py", line 71, in __init__
self._api = YTMusic(config.get(CONF_HEADER_PATH, default_header_file))
File "/srv/homeassistant/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 96, in __init__
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
AttributeError: 'YTMusic' object has no attribute 'headers'
I pasted the token through the integration flow.
I also see a file in /.homeassistant/.storage called ytube_header.json with some of the contents i pasted.
ok, so the integration can’t find the file. If you’ve created it with the config flow then I’d assume that the cookie should be stored in the .storage folder.
Did you provide the /config/header_auth.json path somewhere explicitly? (might be wrong in the docu)
JKW
edit: just to be clear. It WAS a mandatory input for the component and needed to be written down explicitly. but that changed a while back. now this parameter is optional. if not provided the component will simply look in the default location (which is the .storage folder) and the configuration flow will also store it there … so unless you HAVE TO move it, leave it in the .storage folder and forget about the configuration key header_path