mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Prefer mp4 playback in Reolink (#119630)
* If possible use PLAYBACK of mp4 files * bring test_coverage back to 100% * Do not reasign the vod_type multiple times Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com> * fix indent * add white space * fix tests * Update homeassistant/components/reolink/media_source.py Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com> --------- Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com>
This commit is contained in:
parent
c2e31e9846
commit
2639336ab0
@ -59,19 +59,31 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
host = data[config_entry_id].host
|
host = data[config_entry_id].host
|
||||||
|
|
||||||
vod_type = VodRequestType.RTMP
|
def get_vod_type() -> VodRequestType:
|
||||||
if host.api.is_nvr:
|
if filename.endswith(".mp4"):
|
||||||
vod_type = VodRequestType.FLV
|
return VodRequestType.PLAYBACK
|
||||||
|
if host.api.is_nvr:
|
||||||
|
return VodRequestType.FLV
|
||||||
|
return VodRequestType.RTMP
|
||||||
|
|
||||||
|
vod_type = get_vod_type()
|
||||||
|
|
||||||
mime_type, url = await host.api.get_vod_source(
|
mime_type, url = await host.api.get_vod_source(
|
||||||
channel, filename, stream_res, vod_type
|
channel, filename, stream_res, vod_type
|
||||||
)
|
)
|
||||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
url_log = f"{url.split('&user=')[0]}&user=xxxxx&password=xxxxx"
|
url_log = url
|
||||||
|
if "&user=" in url_log:
|
||||||
|
url_log = f"{url_log.split('&user=')[0]}&user=xxxxx&password=xxxxx"
|
||||||
|
elif "&token=" in url_log:
|
||||||
|
url_log = f"{url_log.split('&token=')[0]}&token=xxxxx"
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Opening VOD stream from %s: %s", host.api.camera_name(channel), url_log
|
"Opening VOD stream from %s: %s", host.api.camera_name(channel), url_log
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if mime_type == "video/mp4":
|
||||||
|
return PlayMedia(url, mime_type)
|
||||||
|
|
||||||
stream = create_stream(self.hass, url, {}, DynamicStreamSettings())
|
stream = create_stream(self.hass, url, {}, DynamicStreamSettings())
|
||||||
stream.add_provider("hls", timeout=3600)
|
stream.add_provider("hls", timeout=3600)
|
||||||
stream_url: str = stream.endpoint_url("hls")
|
stream_url: str = stream.endpoint_url("hls")
|
||||||
|
@ -51,11 +51,14 @@ TEST_DAY2 = 15
|
|||||||
TEST_HOUR = 13
|
TEST_HOUR = 13
|
||||||
TEST_MINUTE = 12
|
TEST_MINUTE = 12
|
||||||
TEST_FILE_NAME = f"{TEST_YEAR}{TEST_MONTH}{TEST_DAY}{TEST_HOUR}{TEST_MINUTE}00"
|
TEST_FILE_NAME = f"{TEST_YEAR}{TEST_MONTH}{TEST_DAY}{TEST_HOUR}{TEST_MINUTE}00"
|
||||||
|
TEST_FILE_NAME_MP4 = f"{TEST_YEAR}{TEST_MONTH}{TEST_DAY}{TEST_HOUR}{TEST_MINUTE}00.mp4"
|
||||||
TEST_STREAM = "main"
|
TEST_STREAM = "main"
|
||||||
TEST_CHANNEL = "0"
|
TEST_CHANNEL = "0"
|
||||||
|
|
||||||
TEST_MIME_TYPE = "application/x-mpegURL"
|
TEST_MIME_TYPE = "application/x-mpegURL"
|
||||||
TEST_URL = "http:test_url"
|
TEST_MIME_TYPE_MP4 = "video/mp4"
|
||||||
|
TEST_URL = "http:test_url&user=admin&password=test"
|
||||||
|
TEST_URL2 = "http:test_url&token=test"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -85,18 +88,35 @@ async def test_resolve(
|
|||||||
"""Test resolving Reolink media items."""
|
"""Test resolving Reolink media items."""
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE, TEST_URL)
|
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
|
|
||||||
file_id = (
|
file_id = (
|
||||||
f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}"
|
f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}"
|
||||||
)
|
)
|
||||||
|
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE, TEST_URL)
|
||||||
|
|
||||||
play_media = await async_resolve_media(
|
play_media = await async_resolve_media(
|
||||||
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
|
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
|
||||||
)
|
)
|
||||||
|
assert play_media.mime_type == TEST_MIME_TYPE
|
||||||
|
|
||||||
|
file_id = f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME_MP4}"
|
||||||
|
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL2)
|
||||||
|
|
||||||
|
play_media = await async_resolve_media(
|
||||||
|
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
|
||||||
|
)
|
||||||
|
assert play_media.mime_type == TEST_MIME_TYPE_MP4
|
||||||
|
|
||||||
|
file_id = (
|
||||||
|
f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}"
|
||||||
|
)
|
||||||
|
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE, TEST_URL)
|
||||||
|
reolink_connect.is_nvr = False
|
||||||
|
|
||||||
|
play_media = await async_resolve_media(
|
||||||
|
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
|
||||||
|
)
|
||||||
assert play_media.mime_type == TEST_MIME_TYPE
|
assert play_media.mime_type == TEST_MIME_TYPE
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user