Skip to content

Commit

Permalink
Get metadata and set async_play_url_source response
Browse files Browse the repository at this point in the history
  • Loading branch information
fwestenberg committed Dec 28, 2024
1 parent e63c44d commit 9207242
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions devialet/devialet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import datetime
import json
import re
from typing import Mapping, Union

import aiohttp
from async_upnp_client.aiohttp import AiohttpRequester
Expand Down Expand Up @@ -559,24 +558,35 @@ async def async_discover_upnp_device(self) -> None:
source=("0.0.0.0", 0))
LOGGER.debug("Discovering UPnP device for %s", self._host)

async def async_play_url_source(self, media_url: str, media_title: str, meta_data: Union[None, str, Mapping] = None):
async def async_play_url_source(self, media_id: str, mime_type: str, media_title: str, default_title: bool=False) -> bool:
"""Play media uri over UPnP."""
if not self.upnp_available:
LOGGER.error("No UPnP location discovered")
return

if default_title:
media_title = await self.async_get_upnp_media_title(media_id) or media_title

metadata = (
await self.dmr_device.construct_play_media_metadata(
media_url=media_id,
media_title=media_title,
mime_type=mime_type
)
)

service = self._upnp_device.service(AV_TRANSPORT)
set_uri = service.action("SetAVTransportURI")

try:
result = await set_uri.async_call(InstanceID=0, CurrentURI=media_url, CurrentURIMetaData=meta_data)
result = await set_uri.async_call(InstanceID=0, CurrentURI=media_id, CurrentURIMetaData=metadata)
LOGGER.debug("Action result: %s", str(result))
except UpnpActionResponseError as a:
LOGGER.error("Error playing %s: %s", media_title, a.error_desc)
return
return False
except UpnpXmlParseError as x:
LOGGER.error("Error playing %s %s", media_title, x.text)
return
return False

await self.async_upnp_play()

Expand Down Expand Up @@ -608,7 +618,7 @@ async def async_get_upnp_media_title(self, url: str) -> str | None:
self._host,
response.headers,
)
title:str = response.headers.get("icy-name")
title:str = response.headers.get("icy-description") or response.headers.get("icy-name")
return title

except aiohttp.ClientConnectorError:
Expand Down
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.4',
version='1.5.5',
license='MIT',
description='Devialet API',
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 9207242

Please sign in to comment.