mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Exclude manifest files from youtube media extraction (#100771)
* Exclude manifest files from youtube media extraction * Simplify * Fix
This commit is contained in:
parent
03827bda1e
commit
7cb555739f
@ -135,11 +135,10 @@ class MediaExtractor:
|
||||
raise MEQueryException() from err
|
||||
|
||||
if "formats" in requested_stream:
|
||||
best_stream = requested_stream["formats"][
|
||||
len(requested_stream["formats"]) - 1
|
||||
]
|
||||
return str(best_stream["url"])
|
||||
return str(requested_stream["url"])
|
||||
if requested_stream["extractor"] == "youtube":
|
||||
return get_best_stream_youtube(requested_stream["formats"])
|
||||
return get_best_stream(requested_stream["formats"])
|
||||
return cast(str, requested_stream["url"])
|
||||
|
||||
return stream_selector
|
||||
|
||||
@ -181,3 +180,22 @@ class MediaExtractor:
|
||||
)
|
||||
|
||||
return default_stream_query
|
||||
|
||||
|
||||
def get_best_stream(formats: list[dict[str, Any]]) -> str:
|
||||
"""Return the best quality stream.
|
||||
|
||||
As per
|
||||
https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/common.py#L128.
|
||||
"""
|
||||
|
||||
return cast(str, formats[len(formats) - 1]["url"])
|
||||
|
||||
|
||||
def get_best_stream_youtube(formats: list[dict[str, Any]]) -> str:
|
||||
"""YouTube requests also include manifest files.
|
||||
|
||||
They don't have a filesize so we skip all formats without filesize.
|
||||
"""
|
||||
|
||||
return get_best_stream([format for format in formats if "filesize" in format])
|
||||
|
@ -6,7 +6,7 @@
|
||||
]),
|
||||
'extra': dict({
|
||||
}),
|
||||
'media_content_id': 'https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1694805294/ei/zlgEZcCPFpqOx_APj42f2Ao/ip/45.93.75.130/id/750c38c3d5a05dc4/itag/616/source/youtube/requiressl/yes/ratebypass/yes/pfa/1/wft/1/sgovp/clen%3D99471214%3Bdur%3D212.040%3Bgir%3Dyes%3Bitag%3D356%3Blmt%3D1694043438471036/hls_chunk_host/rr3---sn-5hne6nzy.googlevideo.com/mh/7c/mm/31,26/mn/sn-5hne6nzy,sn-aigzrnld/ms/au,onr/mv/m/mvi/3/pl/22/initcwndbps/2095000/vprv/1/playlist_type/DVR/dover/13/txp/4532434/mt/1694783390/fvip/1/short_key/1/keepalive/yes/fexp/24007246,24362685/beids/24350017/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,wft,sgovp,vprv,playlist_type/sig/AOq0QJ8wRgIhANCPwWNfq6wBp1Xo1L8bRJpDrzOyv7kfH_J65cZ_PRZLAiEAwo-0wQgeIjPe7OgyAAvMCx_A9wd1h8Qyh7VntKwGJUs%3D/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pl,initcwndbps/lsig/AG3C_xAwRQIgIqS9Ub_6L9ScKXr0T9bkeu6TZsEsyNApYfF_MqeukqECIQCMSeJ1sSEw5QGMgHAW8Fhsir4TYHEK5KVg-PzJbrT6hw%3D%3D/playlist/index.m3u8',
|
||||
'media_content_id': 'https://rr3---sn-5hne6nzy.googlevideo.com/videoplayback?expire=1694805294&ei=zlgEZcCPFpqOx_APj42f2Ao&ip=45.93.75.130&id=o-AJK-SE-1BW0w1_4zhkyevHLKWnD0vrRBPNot5eVH0ogM&itag=248&source=youtube&requiressl=yes&mh=7c&mm=31%2C26&mn=sn-5hne6nzy%2Csn-aigzrnld&ms=au%2Conr&mv=m&mvi=3&pl=22&initcwndbps=2095000&vprv=1&svpuc=1&mime=video%2Fwebm&gir=yes&clen=40874930&dur=212.040&lmt=1694044655610179&mt=1694783390&fvip=1&keepalive=yes&fexp=24007246%2C24362685&beids=24350017&c=IOS&txp=4535434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAJ-5AjGgFTR1w-qObfMtwCvs07CU5OUDG7bsNqAXrZMxAiEA4pJO9wj-ZQTqFHg5OP2_XZIJbog8NvY8BVSwENMwJfM%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgMFD0fR8NqzBiP481IpIhnKJjW4Z2fLVfgKt5-OsWbxICICLr46c0ycoE_Ngo3heXuwdOWXs0nyZXegtnP5uHLJSb',
|
||||
'media_content_type': 'VIDEO',
|
||||
})
|
||||
# ---
|
||||
@ -87,7 +87,7 @@
|
||||
'entity_id': 'media_player.bedroom',
|
||||
'extra': dict({
|
||||
}),
|
||||
'media_content_id': 'https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1694805268/ei/tFgEZcu0DoOD-gaqg47wBA/ip/45.93.75.130/id/750c38c3d5a05dc4/itag/616/source/youtube/requiressl/yes/ratebypass/yes/pfa/1/wft/1/sgovp/clen%3D99471214%3Bdur%3D212.040%3Bgir%3Dyes%3Bitag%3D356%3Blmt%3D1694043438471036/hls_chunk_host/rr3---sn-5hne6nzy.googlevideo.com/mh/7c/mm/31,29/mn/sn-5hne6nzy,sn-5hnekn7k/ms/au,rdu/mv/m/mvi/3/pl/22/initcwndbps/1957500/vprv/1/playlist_type/DVR/dover/13/txp/4532434/mt/1694783146/fvip/2/short_key/1/keepalive/yes/fexp/24007246/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,wft,sgovp,vprv,playlist_type/sig/AOq0QJ8wRQIhALAASH0_ZDQQoMA82qWNCXSHPZ0bb9TQldIs7AAxktiiAiASA5bQy7IAa6NwdGIOpfye5OgcY_BNuo0WgSdh84tosw%3D%3D/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pl,initcwndbps/lsig/AG3C_xAwRgIhAIsDcLGH8KJpQpBgyJ5VWlDxfr75HyO8hMSVS9v7nRu4AiEA2xjtLZOzeNFoJlxwCsH3YqsUQt-BF_4gikhi_P4FbBc%3D/playlist/index.m3u8',
|
||||
'media_content_id': 'https://rr3---sn-5hne6nzy.googlevideo.com/videoplayback?expire=1694805268&ei=tFgEZcu0DoOD-gaqg47wBA&ip=45.93.75.130&id=o-ALADwM6dkuCPsPIQiQ_ygvtMcP-xvew7ntgwcwtzWc4N&itag=248&source=youtube&requiressl=yes&mh=7c&mm=31%2C29&mn=sn-5hne6nzy%2Csn-5hnekn7k&ms=au%2Crdu&mv=m&mvi=3&pl=22&initcwndbps=1957500&vprv=1&svpuc=1&mime=video%2Fwebm&gir=yes&clen=40874930&dur=212.040&lmt=1694044655610179&mt=1694783146&fvip=2&keepalive=yes&fexp=24007246&c=IOS&txp=4535434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIgT7VwysCFd3nXvaSSiJoVxkNj5jfMPSeitLsQmy_S1b4CIQDWFiZSIH3tV4hQRtHa9DbzdYL8RQpbKD_6aeNZ7t-3IA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgHX4-RXGLMMOGBkRk1sGy7XnQ3wkahwF60RoxGmOabF0CIBpQjZOMeQQeqZX8JccDZAypFCP3chfxrtgzsfWCJJ0l',
|
||||
'media_content_type': 'VIDEO',
|
||||
})
|
||||
# ---
|
||||
@ -105,7 +105,7 @@
|
||||
'entity_id': 'media_player.bedroom',
|
||||
'extra': dict({
|
||||
}),
|
||||
'media_content_id': 'https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1694805294/ei/zlgEZcCPFpqOx_APj42f2Ao/ip/45.93.75.130/id/750c38c3d5a05dc4/itag/616/source/youtube/requiressl/yes/ratebypass/yes/pfa/1/wft/1/sgovp/clen%3D99471214%3Bdur%3D212.040%3Bgir%3Dyes%3Bitag%3D356%3Blmt%3D1694043438471036/hls_chunk_host/rr3---sn-5hne6nzy.googlevideo.com/mh/7c/mm/31,26/mn/sn-5hne6nzy,sn-aigzrnld/ms/au,onr/mv/m/mvi/3/pl/22/initcwndbps/2095000/vprv/1/playlist_type/DVR/dover/13/txp/4532434/mt/1694783390/fvip/1/short_key/1/keepalive/yes/fexp/24007246,24362685/beids/24350017/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,pfa,wft,sgovp,vprv,playlist_type/sig/AOq0QJ8wRgIhANCPwWNfq6wBp1Xo1L8bRJpDrzOyv7kfH_J65cZ_PRZLAiEAwo-0wQgeIjPe7OgyAAvMCx_A9wd1h8Qyh7VntKwGJUs%3D/lsparams/hls_chunk_host,mh,mm,mn,ms,mv,mvi,pl,initcwndbps/lsig/AG3C_xAwRQIgIqS9Ub_6L9ScKXr0T9bkeu6TZsEsyNApYfF_MqeukqECIQCMSeJ1sSEw5QGMgHAW8Fhsir4TYHEK5KVg-PzJbrT6hw%3D%3D/playlist/index.m3u8',
|
||||
'media_content_id': 'https://rr3---sn-5hne6nzy.googlevideo.com/videoplayback?expire=1694805294&ei=zlgEZcCPFpqOx_APj42f2Ao&ip=45.93.75.130&id=o-AJK-SE-1BW0w1_4zhkyevHLKWnD0vrRBPNot5eVH0ogM&itag=248&source=youtube&requiressl=yes&mh=7c&mm=31%2C26&mn=sn-5hne6nzy%2Csn-aigzrnld&ms=au%2Conr&mv=m&mvi=3&pl=22&initcwndbps=2095000&vprv=1&svpuc=1&mime=video%2Fwebm&gir=yes&clen=40874930&dur=212.040&lmt=1694044655610179&mt=1694783390&fvip=1&keepalive=yes&fexp=24007246%2C24362685&beids=24350017&c=IOS&txp=4535434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAJ-5AjGgFTR1w-qObfMtwCvs07CU5OUDG7bsNqAXrZMxAiEA4pJO9wj-ZQTqFHg5OP2_XZIJbog8NvY8BVSwENMwJfM%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgMFD0fR8NqzBiP481IpIhnKJjW4Z2fLVfgKt5-OsWbxICICLr46c0ycoE_Ngo3heXuwdOWXs0nyZXegtnP5uHLJSb',
|
||||
'media_content_type': 'VIDEO',
|
||||
})
|
||||
# ---
|
||||
|
Loading…
x
Reference in New Issue
Block a user