8000 Reolink fallback to download command for playback (#145842) · home-assistant/core@9687a34 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9687a34

Browse files
authored
Reolink fallback to download command for playback (#145842)
1 parent 5ba0ceb commit 9687a34

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

homeassistant/components/reolink/views.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(self, hass: HomeAssistant) -> None:
5252
verify_ssl=False,
5353
ssl_cipher=SSLCipherList.INSECURE,
5454
)
55+
self._vod_type: str | None = None
5556

5657
async def get(
5758
self,
@@ -68,6 +69,8 @@ async def get(
6869

6970
filename_decoded = urlsafe_b64decode(filename.encode("utf-8")).decode("utf-8")
7071
ch = int(channel)
72+
if self._vod_type is not None:
73+
vod_type = self._vod_type
7174
try:
7275
host = get_host(self.hass, config_entry_id)
7376
except Unresolvable:
@@ -127,6 +130,25 @@ async def get(
127130
"apolication/octet-stream",
128131
]:
129132
err_str = f"Reolink playback expected video/mp4 but got {reolink_response.content_type}"
133+
if (
134+
reolink_response.content_type == "video/x-flv"
135+
and vod_type == VodRequestType.PLAYBACK.value
136+
):
137+
# next time use DOWNLOAD immediately
138+
self._vod_type = VodRequestType.DOWNLOAD.value
139+
_LOGGER.debug(
140+
"%s, retrying using download instead of playback cmd", err_str
141+
)
142+
return await self.get(
143+
request,
144+
config_entry_id,
145+
channel,
146+
stream_res,
147+
self._vod_type,
148+
filename,
149+
retry,
150+
)
151+
130152
_LOGGER.error(err_str)
131153
if reolink_response.content_type == "text/html":
132154
text = await reolink_response.text()
@@ -140,7 +162,10 @@ async def get(
140162
reolink_response.reason,
141163
response_headers,
142164
)
143-
response_headers["Content-Type"] = "video/mp4"
165+
if "Content-Type" not in response_headers:
166+
response_headers["Content-Type"] = reolink_response.content_type
167+
if response_headers["Content-Type"] == "apolication/octet-stream":
168+
response_headers["Content-Type"] = "application/octet-stream"
144169

145170
response = web.StreamResponse(
146171
status=reolink_response.status,

tests/components/reolink/test_views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,22 @@ def get_mock_session(
5858
return mock_session
5959

6060

61+
@pytest.mark.parametrize(
62+
("content_type"),
63+
[("video/mp4"), ("application/octet-stream"), ("apolication/octet-stream")],
64+
)
6165
async def test_playback_proxy(
6266
hass: HomeAssistant,
6367
reolink_connect: MagicMock,
6468
config_entry: MockConfigEntry,
6569
hass_client: ClientSessionGenerator,
6670
caplog: pytest.LogCaptureFixture,
71+
content_type: str,
6772
) -> None:
6873
"""Test successful playback proxy URL."""
6974
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
7075

71-
mock_session = get_mock_session()
76+
mock_session = get_mock_session(content_type=content_type)
7277

7378
with patch(
7479
"homeassistant.components.reolink.views.async_get_clientsession",

0 commit comments

Comments
 (0)
0