Skip to content

Commit afe3280

Browse files
authored
Fix DLNA local file playback for Sony TA-AN1000 by returning content type for HEAD requests (home-assistant#165807)
1 parent fc573a0 commit afe3280

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

homeassistant/components/media_source/local_source.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,17 @@ async def _validate_media_path(self, source_dir_id: str, location: str) -> Path:
314314

315315
async def head(
316316
self, request: web.Request, source_dir_id: str, location: str
317-
) -> None:
317+
) -> web.Response:
318318
"""Handle a HEAD request.
319319
320320
This is sent by some DLNA renderers, like Samsung ones, prior to sending
321321
the GET request.
322322
323323
Check whether the location exists or not.
324324
"""
325-
await self._validate_media_path(source_dir_id, location)
325+
media_path = await self._validate_media_path(source_dir_id, location)
326+
mime_type, _ = mimetypes.guess_type(str(media_path))
327+
return web.Response(content_type=mime_type)
326328

327329
async def get(
328330
self, request: web.Request, source_dir_id: str, location: str

tests/components/media_source/test_local_source.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,15 @@ async def test_media_view(
132132
# Fetch available media
133133
resp = await client.head("/media/local/test.mp3")
134134
assert resp.status == HTTPStatus.OK
135+
assert resp.content_type == "audio/mpeg"
135136

136137
resp = await client.get("/media/local/test.mp3")
137138
assert resp.status == HTTPStatus.OK
138139

140+
resp = await client.head("/media/local/Epic Sax Guy 10 Hours.mp4")
141+
assert resp.status == HTTPStatus.OK
142+
assert resp.content_type == "video/mp4"
143+
139144
resp = await client.get("/media/local/Epic Sax Guy 10 Hours.mp4")
140145
assert resp.status == HTTPStatus.OK
141146

0 commit comments

Comments
 (0)