diff --git a/devialet/devialet_api.py b/devialet/devialet_api.py index fe3e69d..6ecb61e 100644 --- a/devialet/devialet_api.py +++ b/devialet/devialet_api.py @@ -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): @@ -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.""" @@ -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 diff --git a/setup.py b/setup.py index 31609c6..0fe6fc3 100644 --- a/setup.py +++ b/setup.py @@ -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",