Improve cast HLS detection (#72787)
parent
de0c672cc2
commit
8606447848
|
@ -266,10 +266,8 @@ async def parse_m3u(hass, url):
|
||||||
hls_content_types = (
|
hls_content_types = (
|
||||||
# https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
|
# https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
|
||||||
"application/vnd.apple.mpegurl",
|
"application/vnd.apple.mpegurl",
|
||||||
# Some sites serve these as the informal HLS m3u type.
|
# Additional informal types used by Mozilla gecko not included as they
|
||||||
"application/x-mpegurl",
|
# don't reliably indicate HLS streams
|
||||||
"audio/mpegurl",
|
|
||||||
"audio/x-mpegurl",
|
|
||||||
)
|
)
|
||||||
m3u_data = await _fetch_playlist(hass, url, hls_content_types)
|
m3u_data = await _fetch_playlist(hass, url, hls_content_types)
|
||||||
m3u_lines = m3u_data.splitlines()
|
m3u_lines = m3u_data.splitlines()
|
||||||
|
@ -292,6 +290,9 @@ async def parse_m3u(hass, url):
|
||||||
elif line.startswith("#EXT-X-VERSION:"):
|
elif line.startswith("#EXT-X-VERSION:"):
|
||||||
# HLS stream, supported by cast devices
|
# HLS stream, supported by cast devices
|
||||||
raise PlaylistSupported("HLS")
|
raise PlaylistSupported("HLS")
|
||||||
|
elif line.startswith("#EXT-X-STREAM-INF:"):
|
||||||
|
# HLS stream, supported by cast devices
|
||||||
|
raise PlaylistSupported("HLS")
|
||||||
elif line.startswith("#"):
|
elif line.startswith("#"):
|
||||||
# Ignore other extensions
|
# Ignore other extensions
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -27,6 +27,11 @@ from tests.common import load_fixture
|
||||||
"rthkaudio2.m3u8",
|
"rthkaudio2.m3u8",
|
||||||
"application/vnd.apple.mpegurl",
|
"application/vnd.apple.mpegurl",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"https://rthkaudio2-lh.akamaihd.net/i/radio2_1@355865/master.m3u8",
|
||||||
|
"rthkaudio2.m3u8",
|
||||||
|
None,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, content_type):
|
async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, content_type):
|
||||||
|
@ -38,11 +43,12 @@ async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, conten
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"url,fixture,expected_playlist",
|
"url,fixture,content_type,expected_playlist",
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
||||||
"209-hi-mp3.m3u",
|
"209-hi-mp3.m3u",
|
||||||
|
"audio/x-mpegurl",
|
||||||
[
|
[
|
||||||
PlaylistItem(
|
PlaylistItem(
|
||||||
length=["-1"],
|
length=["-1"],
|
||||||
|
@ -54,6 +60,7 @@ async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, conten
|
||||||
(
|
(
|
||||||
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
||||||
"209-hi-mp3_bad_extinf.m3u",
|
"209-hi-mp3_bad_extinf.m3u",
|
||||||
|
"audio/x-mpegurl",
|
||||||
[
|
[
|
||||||
PlaylistItem(
|
PlaylistItem(
|
||||||
length=None,
|
length=None,
|
||||||
|
@ -65,6 +72,7 @@ async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, conten
|
||||||
(
|
(
|
||||||
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
"https://sverigesradio.se/topsy/direkt/209-hi-mp3.m3u",
|
||||||
"209-hi-mp3_no_extinf.m3u",
|
"209-hi-mp3_no_extinf.m3u",
|
||||||
|
"audio/x-mpegurl",
|
||||||
[
|
[
|
||||||
PlaylistItem(
|
PlaylistItem(
|
||||||
length=None,
|
length=None,
|
||||||
|
@ -76,6 +84,7 @@ async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, conten
|
||||||
(
|
(
|
||||||
"http://sverigesradio.se/topsy/direkt/164-hi-aac.pls",
|
"http://sverigesradio.se/topsy/direkt/164-hi-aac.pls",
|
||||||
"164-hi-aac.pls",
|
"164-hi-aac.pls",
|
||||||
|
"audio/x-mpegurl",
|
||||||
[
|
[
|
||||||
PlaylistItem(
|
PlaylistItem(
|
||||||
length="-1",
|
length="-1",
|
||||||
|
@ -86,9 +95,12 @@ async def test_hls_playlist_supported(hass, aioclient_mock, url, fixture, conten
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_parse_playlist(hass, aioclient_mock, url, fixture, expected_playlist):
|
async def test_parse_playlist(
|
||||||
|
hass, aioclient_mock, url, fixture, content_type, expected_playlist
|
||||||
|
):
|
||||||
"""Test playlist parsing of HLS playlist."""
|
"""Test playlist parsing of HLS playlist."""
|
||||||
aioclient_mock.get(url, text=load_fixture(fixture, "cast"))
|
headers = {"content-type": content_type}
|
||||||
|
aioclient_mock.get(url, text=load_fixture(fixture, "cast"), headers=headers)
|
||||||
playlist = await parse_playlist(hass, url)
|
playlist = await parse_playlist(hass, url)
|
||||||
assert expected_playlist == playlist
|
assert expected_playlist == playlist
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue