home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.42k stars 30.66k forks source link

Jellyfin Duplicate Chromecast Media Players #108276

Open crazystick opened 9 months ago

crazystick commented 9 months ago

The problem

Jellyfin creates a new Chromecast device/entity every time you play something using the native Jellyfin app on Android.

This seems to be the same as issue #105000 but since I don't use AppleTV I don't know what Swiftfin is so not sure what the resolution might be.

What version of Home Assistant Core has the issue?

core-2023.11.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Jellyfin

Link to integration documentation on our website

No response

Diagnostics information

config_entry-jellyfin-787b9eb6dd7dfe73d109348717be4c1b.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 9 months ago

Hey there @j-stienstra, @ctalkington, mind taking a look at this issue as it has been labeled with an integration (jellyfin) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `jellyfin` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign jellyfin` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


jellyfin documentation jellyfin source (message by IssueLinks)

tim-hitchins-ekkosense commented 8 months ago

@crazystick On your Jellyfin server do you have DLNA "Play To" enabled?

  1. Login as an admin user
  2. Open the hamburger menu
  3. Under Administration click Dashboard
  4. Under Devices click DLNA

It's the top checkbox under "Settings". I have a misbehaving Toshiba TV which was showing up as 200 separate DLNA cast targets. Turning that off has stopped it from happening, with the downside I can't use the DLNA Cast feature.

crazystick commented 7 months ago

@tim-hitchins-ekkosense I tried your suggestion but it doesn't seem to have improved matters. I removed and readded the integration which got rid of most of the entities, but they are still going up.

ctalkington commented 7 months ago

the common issue is that devices are created based on the reporting that the session device supports persistent identifier. The client applications report this to the server but they usually use some method on the client device as the identifier and its expected to be persistent.

However, client devices can regenerate identifier to improve privacy that can cause the identifier to be less persistent than thought. Think of it like resetting Google advertising IDs on Android devices.

ctalkington commented 7 months ago

for chromecast, it's deriving deviceId by base64 the name of receiver or first sender ID or time. This likely leads to the growing list of devices.

https://github.com/jellyfin/jellyfin-chromecast/blob/66a21d2df36ed7d3d69cfec44ec8e8180d858f34/src/components/jellyfinApi.ts#L33-L49

https://github.com/jellyfin/jellyfin-chromecast/blob/66a21d2df36ed7d3d69cfec44ec8e8180d858f34/src/components/maincontroller.ts#L310

so it's actually not creating persistent identifier and properly reports SupportsPersistentIdentifier: false so you see the media players still because its generating new playback session ids

However, in your diagnostics, most your chromecast seem to report SupportsPersistentIdentifier: true which is intriguing

ctalkington commented 7 months ago

I'm wondering if we should just ignore sessions where the deviceid starts with "chromecast" as it seems like these are transient sessions and keeping them around as entities wouldn't have any benefit

golles commented 5 months ago

I don't think this issue is only related to Chromecast devices. also to iPhone apps (Finamp and the regular app) and the LG Smart TV app.

For the record, there is only one actual iPhone and LG Smart TV device.

Entities (x watching sensor I kept out of the screenshot):

Scherm­afbeelding 2024-05-20 om 15 32 32

Devices:

Scherm­afbeelding 2024-05-20 om 15 33 32

In the past, I've deleted these duplicate media_player entities several times but they are coming back

Bluey-Speaker commented 4 months ago

I get basically the same issue. I play a video file using Jellyfin Andriod app and cast to Chromecast . I pause playback, disconnect chromecast & close jellyfin. New entries show up. I currently have 196. image image

Edit: Is it possible to mass delete entries?

ThatJRadGuy commented 4 months ago

I’m having the same issue with multiple devices appearing several times, not limited to chromecast devices only either. IMG_9474

rwjack commented 4 months ago

I'm the OP from https://github.com/home-assistant/core/issues/105000 ( <- nice number )

Just to confirm this is still an issue, but in my case, there are only duplicate Apple TV Swiftfin entries, no duplicates for my phone nor desktops, but then again, I don't remember when is the last time I actually played something on a player other than my TV, so there's that.

Binvention commented 2 months ago

I'm having a similar issue but it's hard to tell how much of it is actually that in jellyfin itself each user account on each device and in the case of phones each client app (like if you use both the jellyfin app and finamp app like I do) all show up as separate entities. So maybe before fixing this more details about the media session should be displayed such as the user account and the client app the session represents. That would be a helpful feature in its own right in addition to being useful in debugging this issue.

alanpaone commented 2 months ago

I'm curious why every app or player that interacts with Jellyfin generates a media player entity in Home Assistant in the first place. Generating 245 different media players is either funny or annoying, depending on your perspective, but what problem does generating even one solve?

rwjack commented 2 months ago

Probably if users are watching on their TV / Phone / Desktop, each one of those is a "separate media player", but tbh I don't remember when I last watched something other than on my TV.

rwjack commented 1 month ago

So to recap, if we're seeing this on both AppleTV Swiftfin and other Jellyfin players, phones/desktops, wouldn't it make more sense to implement the fix in the integration here?

Something along the lines of: If the player name is the same, even if the ID changed, don't create a new entity?

I just went through the process of deleting 30 media players (again).