How do I get the Home Assistant streaming URL for media?

I am trying to figure out how to calculate the streaming URL to provide to an ESPHome device in order to play media off from the Home Assistant’s local media collection. Does anyone have any pointers?

When I play media via the Home Assistant built in Play Media feature, it send the ESPHome device a URL that looks like:

https://[my HA machine]:8123/media/local/Alarm.mp3?authSig=[authkey]

But when I use the Media Selector in HA to choose a piece of media, it give me a media_content_id that contains a something like:


I am trying to write a service on the ESPHome device that takes in the media URL as a parameter the same way the media_player.start would, but I can’t figure out how to get the local media_source URL converted into a remote URL with an auth token on it for the ESPHome device.

Is this buried within the HA code in a way that one can’t get at it? Or does the conversion happen within the ESPHome layer? Or is there another way to get this accomplished?