Author Topic: UPnP 2025 - Continuation of the original UPnP/DLNA plugin  (Read 46341 times)

BoringName

  • Sr. Member
  • ****
  • Posts: 959
New version - mb_UPnP2025_2.1.1

Changes
- Possible fix for Home Assistant when browsing content.

LiamH can you try this new version and see how that goes.

How are you planning on using Home Assistant with Musicbee?

If you are going to use Musicbee as the Renderer in Home Assistant you may have further problems when attempting to play a track but if the fix above works I should be able to sort it out.

If you are planning to use Musicbee just as a media server using something else as the Renderer, hopefully the fix above is enough to get you going.

LiamH

  • Newbie
  • *
  • Posts: 2
Thanks BoringName, that was quick!  The good news is that the error is gone, the bad news is that there are "No items" displayed.  To be specific, when clicking on the server in HA, instead of seeing the Albums, Playlists, etc. folders, it says "No items".  Like this.  The MusicBee icon is still missing too.

Here are some logs, the timeline (New York time):
2025-06-29 16:27:03 MusicBee startup
2025-06-29 16:27:25 Detecting in HA
2025-06-29 16:27:32 Add server in HA
2025-06-29 16:27:47 to 2025-06-29 16:27:55 Trying to browse

The UPnPError.dat:
Code
0; 1 Initialise - 6/29/2025 4:27:09 PM
38; 2 GetNetworkAddresses - 10.0.0.232,dns=True,name=Ethernet,speed=1000000000
39; 3 GetNetworkAddresses - 169.254.214.134,dns=False,name=Npcap Loopback Adapter,speed=1215752192
39; 4 GetNetworkAddresses - 127.0.0.1,dns=False,name=Loopback Pseudo-Interface 1,speed=1073741824
39; 5 GetNetworkAddresses - http://10.0.0.232:49382
25328; 6 Profile - Generic Device, useragent=HomeAssistant/2025.5.3 aiohttp/3.11.18 Python/3.13
31591; 7 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31596; 8 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31598; 9 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31599; 10 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31599; 11 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31600; 12 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31600; 13 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31600; 14 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31608; 15 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31608; 16 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31608; 17 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31609; 18 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31609; 19 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31655; 20 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31678; 21 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31679; 22 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31679; 23 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
31679; 24 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
32599; 25 Profile - Generic Device, useragent=DAFUPnP
33598; 26 Profile - Generic Device, useragent=Microsoft-Windows/10.0 UPnP/1.0
34610; 27 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
40605; 28 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
40609; 29 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
40611; 30 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
41645; 31 ProcessRequest:Exception - Length cannot be less than zero.
Parameter name: length
   at System.String.Substring(Int32 startIndex, Int32 length)
   at MusicBeePlugin.Plugin.HttpRequest.ParseHeaders()
   at MusicBeePlugin.Plugin.HttpServer.ProcessRequest(Object parameters)
42603; 32 ProcessRequest:Exception - Index was outside the bounds of the array.
   at MusicBeePlugin.Plugin.HttpRequest.ParseHeaders()
   at MusicBeePlugin.Plugin.HttpServer.ProcessRequest(Object parameters)
42604; 33 Profile - Generic Device, useragent=HomeAssistant/2025.5.3 aiohttp/3.11.18 Python/3.13
42611; 34 Browse - 0,BrowseMetadata,0,0,sort=
43597; 35 ProcessRequest:Exception - Index was outside the bounds of the array.
   at MusicBeePlugin.Plugin.HttpRequest.ParseHeaders()
   at MusicBeePlugin.Plugin.HttpServer.ProcessRequest(Object parameters)
43598; 36 Profile - Generic Device, useragent=HomeAssistant/2025.5.3 aiohttp/3.11.18 Python/3.13
43599; 37 Browse - 0,BrowseDirectChildren,0,0,sort=
43607; 40 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
43610; 42 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
43611; 43 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
46604; 48 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
52609; 49 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25
52612; 50 Profile - Generic Device, useragent=Linux/5.10.103-v7+, UPnP/1.0, Portable SDK for UPnP devices/1.6.25

While I was doing this, I noticed HA has debug log option as well, so I turned that on at the same time:
Code
2025-06-29 16:27:29.965 DEBUG (MainThread) [homeassistant.components.dlna_dms.config_flow] async_step_user: user_input: None
2025-06-29 16:27:35.769 DEBUG (MainThread) [homeassistant.components.dlna_dms.config_flow] async_step_user: user_input: {'host': '10.0.0.232'}
2025-06-29 16:27:35.770 DEBUG (MainThread) [homeassistant.components.dlna_dms.config_flow] _async_parse_discovery: location: http://10.0.0.232:49382/description.xml, USN: uuid:c1665f14-c093-47bc-bade-ae9252160777::urn:schemas-upnp-org:device:MediaServer:1
2025-06-29 16:27:35.771 DEBUG (MainThread) [homeassistant.components.dlna_dms.config_flow] _create_entry: name: MusicBee Media Library, location: http://10.0.0.232:49382/description.xml, USN: uuid:c1665f14-c093-47bc-bade-ae9252160777::urn:schemas-upnp-org:device:MediaServer:1
2025-06-29 16:27:35.783 DEBUG (MainThread) [homeassistant.components.dlna_dms] Setting up config entry: uuid:c1665f14-c093-47bc-bade-ae9252160777::urn:schemas-upnp-org:device:MediaServer:1
2025-06-29 16:27:35.784 DEBUG (MainThread) [homeassistant.components.dlna_dms] Connecting to device at http://10.0.0.232:49382/description.xml
2025-06-29 16:27:35.932 DEBUG (MainThread) [homeassistant.components.dlna_dms] SSDP SsdpChange.ALIVE notification of device uuid:c1665f14-c093-47bc-bade-ae9252160777::urn:schemas-upnp-org:device:MediaServer:1 at http://10.0.0.232:49382/description.xml
2025-06-29 16:27:51.493 DEBUG (MainThread) [homeassistant.components.dlna_dms] Browsing for None / None
2025-06-29 16:27:52.246 DEBUG (MainThread) [homeassistant.components.dlna_dms] Browsing for musicbee_media_library / :0
2025-06-29 16:27:52.247 DEBUG (MainThread) [homeassistant.components.dlna_dms] async_browse_media(:0)
2025-06-29 16:28:14.405 DEBUG (MainThread) [homeassistant.components.dlna_dms] SSDP SsdpChange.BYEBYE notification of device uuid:c1665f14-c093-47bc-bade-ae9252160777::upnp:rootdevice at http://10.0.0.232:49382/description.xml
2025-06-29 16:28:14.406 DEBUG (MainThread) [homeassistant.components.dlna_dms] Disconnecting from MusicBee Media Library

And I took a pcap while this was happening also:
https://send.vis.ee/download/1e643793463ad849/#FVnSM6lImt-aUx1X_q9T0A

I attached Visual Studio to the MusicBee process and tried to debug the Length cannot be less than zero exception.  It occurs when HA tries to enumerate the devices (i.e. clicking Media and then browsing the servers). The full message is "Length cannot be less than zero.\r\nParameter name: length".  Here is the dump you can analyze:
https://send.vis.ee/download/db812fa4719453a0/#RqBEaUGQygnzFyuyT7ECuQ

Note there were other Web/Socket exceptions during this, which I ignored, but they seemed unrelated (connecting to 169.* IPs).

BoringName

  • Sr. Member
  • ****
  • Posts: 959
Thanks BoringName, that was quick!  The good news is that the error is gone,

Progress!!

I've sent you a PM with a link to a test version. If you could run that and give me the logs it should help figure out what's going on. It seems to be an issue with the HTTP header that Home Assistant is sending through.

Thanks.