bushvin / hass-integrations

My custom Home Assistant integrations
Apache License 2.0
61 stars 11 forks source link

playlist-attribute doesn't show up sometimes when a playlist is playing #55

Closed Switch123456789 closed 10 months ago

Switch123456789 commented 10 months ago

On rare occasions it shows up but usually it doesn't. I only use a single m3u8-playlist with over 500 local tracks, it takes quite some time to load (10+ seconds) whenever chosen (just in case that matters). Here are some example lines from the mentioned playlist:

local:track:Haute%20-%20Shut%20Me%20Down%20%5BVanucci%5D.opus
local:track:Brijs%20-%20Shy%20%5BOriginal%5D.flac
local:track:Hook%20N%20Sling%20-%20Silver%20Service%20%5BOriginal%5D.mp3
Switch123456789 commented 10 months ago

Oh damn, while doing some testing my Home Assistant web interface became unavailable (timeout), when loading a playlist through Iris. With the Integration disabled this doesn't happen.

When I start a playlist, mopidy/iris is adding every song one by one, maybe with the async stuff you implemented it is flooding the integration with update requests or something? because Iris shows the progress and with every added file the progress keeps slowing down.

bushvin commented 10 months ago

There is indeed an event triggered on tracklist change... but I would expect it to be called only once, as I huse the mopidy API to add a bunch of tracks Will need to investigate

bushvin commented 10 months ago

What doe sthe tracklist_changed event do:

TracklistController.add can add a bunch of tracks to the queue.

It turns out Iris actually adds all tracks by enumerating the playlist. One by one. This is causing the tracklist_changed event to get kicked off at each and every track added. And the more tracks that get added, the more time the event takes. There is probably a clever decision behind this, especially since Mopidy doesn't support playing playlists as media, but I fail to see what. See if I can make a workaround to either queue the tracklist_changed events or just skip it when one's already running.

bushvin commented 10 months ago

I believe I have found a working functional solution to the playlist not showing up in the entity issue. I do not recommend using iris to add a playlist to your mopidy player, for the abovementioned reasons. Of course, all will depend on your hardware and the size of your playlist how long it will take.

I have a RPI4 where it takes about 30 seconds to add a 600 track playlist without a problem.

Switch123456789 commented 10 months ago

I believe I have found a working functional solution

Awesome, I will give it a try today!

I do not recommend using iris to add a playlist

For me personal that's okay, since I don't plan to use Iris for that purpose at me moment. Do you think it is worth asking the Iris devs to look into this?

Of course, all will depend on your hardware and the size of your playlist how long it will take.

It seems like the memory usage is the main problem on my end. I have 1GB of RAM in my Pi 3B+ and the container restarts when the swap-file exceeds roughly 1GB. So I am wondering why a bunch of strings (track id's or whatever it is) can cause such memory consumption that it crashes my homeassistant-container. Maybe it is loading all cover-pictures into memory at the same time or something? Most of them have a very high resolution in my library. (Just a random guess)

Again, thank you :)

Switch123456789 commented 10 months ago

Unfortunately the playlist still doesn't show for me :/

While checking I noticed something else... I am not sure if it is supposed to be like this but the string of entity_picture keeps changing on every update, see: Screencast from 2023-11-11 19-32-54.webm

EDIT: Maybe that's the reason why the cover-picture flickers on every entity-update in the media-player-card & maybe it is related to my flooded swap-file when I load a playlist from within Iris?

bushvin commented 10 months ago

It is strange you do not see the playlist name.

One word of caution, though: playlist names do not persist across HA restarts, as that information is in-memory.

I was planning on raising an issue with Iris about this, yes. When I have time.

I do not know what mopidy does on loading the tracks, but I do not think it is caching the images itself. The image_url, yes.

I do not see the flickering, but I do believe I know why. I wrote a method to complete urls with the mopidy hostname and port when missing, as when your mopidy instance doesn't share IP addresses with your HA instance, you do not get the images.

I also add a timestamp in the query, to force browsers to reload the image. I believe this is the issue. I will remove it in my next release.

Switch123456789 commented 10 months ago

I did some tests with the HA-dev-tools and noticed something interesting. If I start the playlist with enqueue: play I get an error and nothing happens: image If I start the playlist with enqueue: replace I get an error again BUT the playlist starts playing nevertheless. image In both cases, the playlist-attribute does not appear.

Is it really expected behavior that the URL in the picture-attribute changes 100 times within the same track? Here are some URL's from the same song.

https://192.168.0.2:8123/api/media_player_proxy/media_player.server_mopidy?token=5028bce2ccb3905de36941fd4bb019e4130680ecbffc889159ec72868b7146ef&cache=1be027f8e75c0fff
https://192.168.0.2:8123/api/media_player_proxy/media_player.server_mopidy?token=5028bce2ccb3905de36941fd4bb019e4130680ecbffc889159ec72868b7146ef&cache=23063b28826637e5
https://192.168.0.2:8123/api/media_player_proxy/media_player.server_mopidy?token=5028bce2ccb3905de36941fd4bb019e4130680ecbffc889159ec72868b7146ef&cache=0df42d0e6b4973d7
https://192.168.0.2:8123/api/media_player_proxy/media_player.server_mopidy?token=5028bce2ccb3905de36941fd4bb019e4130680ecbffc889159ec72868b7146ef&cache=7cc3b9ee0388d153

By the way, I can't reproduce that issue with adding playlists within Iris anymore. I am not sure if it is related to some settings or something but it works fine now, even after adding 1000+ songs. It takes less than 10 seconds and nothing crashes or freezes :)

bushvin commented 10 months ago

There is indeed an issue with the integration, as I was able to reproduce the problem

Switch123456789 commented 9 months ago

Hey, nice! Thank you! The freezes are gone, the cover-flickering is gone and the playlist gets shown! Awesome!

bushvin commented 9 months ago

I'm glad all your issues are solved!

Thanks for your feedback and patience!

A la prochaime!