Skip to content

Commit

Permalink
Get Icy metadata for UPnP
Browse files Browse the repository at this point in the history
  • Loading branch information
fwestenberg committed Dec 26, 2024
1 parent ae65b00 commit 473ec45
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions devialet/devialet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ async def async_update(self) -> bool | None:
self._night_mode = await self._async_get_request(UrlSuffix.GET_NIGHT_MODE)
self._equalizer = await self._async_get_request(UrlSuffix.GET_EQUALIZER)

if self.source == "upnp":
return True

try:
self._media_duration = self._source_state["metadata"]["duration"]
except (KeyError, TypeError):
Expand Down Expand Up @@ -574,6 +577,7 @@ async def async_play_url_source(self, media_url: str, media_title: str, meta_dat
LOGGER.error("Error playing %s %s", media_title, x.text)

await self.async_upnp_play()
await self._async_get_upnp_metadata(media_url) # Devialet does not support UPnP metadata

async def async_upnp_play(self) -> None:
"""Send the play command over UPnP."""
Expand All @@ -591,3 +595,26 @@ async def async_upnp_play(self) -> None:
return
except UpnpXmlParseError:
return

async def _async_get_upnp_metadata(self, url: str) -> any | None:
"""Call the media URL with the HEAD method to get ICY metadata."""
try:
async with self._session.head(
url=url, allow_redirects=False, timeout=2, headers={"Icy-MetaData": 1}
) as response:
LOGGER.debug(
"Host %s: HTTP Response data: %s",
self._host,
response.headers,
)
title:str = response.headers.get("icy-name")
self._source_state = { "metadata": { "title": title } }

except aiohttp.ClientConnectorError:
return None
except asyncio.TimeoutError:
return None
except TypeError:
return None
except Exception: # pylint: disable=bare-except
return None
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='devialet',
packages=['devialet'],
version='1.5.2',
version='1.5.3',
license='MIT',
description='Devialet API',
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 473ec45

Please sign in to comment.