Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
60755938
Y
Yt Dlp
项目概览
XianxinMao
/
Yt Dlp
12 个月 前同步成功
通知
27
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
Yt Dlp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
60755938
编写于
7月 07, 2021
作者:
P
pukkandan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[extractor] Prevent unnecessary download of hls manifests
and refactor `hls_split_discontinuity` code
上级
723d44b9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
112 deletion
+48
-112
yt_dlp/extractor/common.py
yt_dlp/extractor/common.py
+48
-112
未找到文件。
yt_dlp/extractor/common.py
浏览文件 @
60755938
...
@@ -1979,24 +1979,33 @@ def _parse_m3u8_formats_and_subtitles(
...
@@ -1979,24 +1979,33 @@ def _parse_m3u8_formats_and_subtitles(
preference
=
None
,
quality
=
None
,
m3u8_id
=
None
,
live
=
False
,
note
=
None
,
preference
=
None
,
quality
=
None
,
m3u8_id
=
None
,
live
=
False
,
note
=
None
,
errnote
=
None
,
fatal
=
True
,
data
=
None
,
headers
=
{},
query
=
{},
errnote
=
None
,
fatal
=
True
,
data
=
None
,
headers
=
{},
query
=
{},
video_id
=
None
):
video_id
=
None
):
formats
,
subtitles
=
[],
{}
if
'#EXT-X-FAXS-CM:'
in
m3u8_doc
:
# Adobe Flash Access
if
'#EXT-X-FAXS-CM:'
in
m3u8_doc
:
# Adobe Flash Access
return
[],
{}
return
formats
,
subtitles
if
(
not
self
.
get_param
(
'allow_unplayable_formats'
)
if
(
not
self
.
get_param
(
'allow_unplayable_formats'
)
and
re
.
search
(
r
'#EXT-X-SESSION-KEY:.*?URI="skd://'
,
m3u8_doc
)):
# Apple FairPlay
and
re
.
search
(
r
'#EXT-X-SESSION-KEY:.*?URI="skd://'
,
m3u8_doc
)):
# Apple FairPlay
return
[],
{}
return
formats
,
subtitles
formats
=
[]
subtitles
=
{}
format_url
=
lambda
u
:
(
def
format_url
(
url
):
u
return
url
if
re
.
match
(
r
'^https?://'
,
url
)
else
compat_urlparse
.
urljoin
(
m3u8_url
,
url
)
if
re
.
match
(
r
'^https?://'
,
u
)
else
compat_urlparse
.
urljoin
(
m3u8_url
,
u
))
if
self
.
get_param
(
'hls_split_discontinuity'
,
False
):
def
_extract_m3u8_playlist_indices
(
manifest_url
=
None
,
m3u8_doc
=
None
):
if
not
m3u8_doc
:
if
not
manifest_url
:
return
[]
m3u8_doc
=
self
.
_download_webpage
(
manifest_url
,
video_id
,
fatal
=
fatal
,
data
=
data
,
headers
=
headers
,
note
=
False
,
errnote
=
'Failed to download m3u8 playlist information'
)
if
m3u8_doc
is
False
:
return
[]
return
range
(
1
+
sum
(
line
.
startswith
(
'#EXT-X-DISCONTINUITY'
)
for
line
in
m3u8_doc
.
splitlines
()))
split_discontinuity
=
self
.
get_param
(
'hls_split_discontinuity'
,
False
)
else
:
def
_extract_m3u8_playlist_indices
(
*
args
,
**
kwargs
):
return
[
None
]
# References:
# References:
# 1. https://tools.ietf.org/html/draft-pantos-http-live-streaming-21
# 1. https://tools.ietf.org/html/draft-pantos-http-live-streaming-21
...
@@ -2014,68 +2023,16 @@ def _parse_m3u8_formats_and_subtitles(
...
@@ -2014,68 +2023,16 @@ def _parse_m3u8_formats_and_subtitles(
# media playlist and MUST NOT appear in master playlist thus we can
# media playlist and MUST NOT appear in master playlist thus we can
# clearly detect media playlist with this criterion.
# clearly detect media playlist with this criterion.
def
_extract_m3u8_playlist_formats
(
format_url
=
None
,
m3u8_doc
=
None
,
video_id
=
None
,
fatal
=
True
,
data
=
None
,
headers
=
{}):
if
not
m3u8_doc
:
if
not
format_url
:
return
[]
res
=
self
.
_download_webpage_handle
(
format_url
,
video_id
,
note
=
False
,
errnote
=
'Failed to download m3u8 playlist information'
,
fatal
=
fatal
,
data
=
data
,
headers
=
headers
)
if
res
is
False
:
return
[]
m3u8_doc
,
urlh
=
res
format_url
=
urlh
.
geturl
()
playlist_formats
=
[]
i
=
(
0
if
split_discontinuity
else
None
)
format_info
=
{
'index'
:
i
,
'key_data'
:
None
,
'files'
:
[],
}
for
line
in
m3u8_doc
.
splitlines
():
if
not
line
.
startswith
(
'#'
):
format_info
[
'files'
].
append
(
line
)
elif
split_discontinuity
and
line
.
startswith
(
'#EXT-X-DISCONTINUITY'
):
i
+=
1
playlist_formats
.
append
(
format_info
)
format_info
=
{
'index'
:
i
,
'url'
:
format_url
,
'files'
:
[],
}
playlist_formats
.
append
(
format_info
)
return
playlist_formats
if
'#EXT-X-TARGETDURATION'
in
m3u8_doc
:
# media playlist, return as is
if
'#EXT-X-TARGETDURATION'
in
m3u8_doc
:
# media playlist, return as is
formats
=
[{
playlist_formats
=
_extract_m3u8_playlist_formats
(
m3u8_doc
=
m3u8_doc
)
'format_id'
:
'-'
.
join
(
map
(
str
,
filter
(
None
,
[
m3u8_id
,
idx
]))),
'format_index'
:
idx
,
for
format
in
playlist_formats
:
'url'
:
m3u8_url
,
format_id
=
[]
'ext'
:
ext
,
if
m3u8_id
:
'protocol'
:
entry_protocol
,
format_id
.
append
(
m3u8_id
)
'preference'
:
preference
,
format_index
=
format
.
get
(
'index'
)
'quality'
:
quality
,
if
format_index
:
}
for
idx
in
_extract_m3u8_playlist_indices
(
m3u8_doc
=
m3u8_doc
)]
format_id
.
append
(
str
(
format_index
))
f
=
{
'format_id'
:
'-'
.
join
(
format_id
),
'format_index'
:
format_index
,
'url'
:
m3u8_url
,
'ext'
:
ext
,
'protocol'
:
entry_protocol
,
'preference'
:
preference
,
'quality'
:
quality
,
}
formats
.
append
(
f
)
return
formats
,
subtitles
return
formats
,
subtitles
...
@@ -2115,32 +2072,19 @@ def extract_media(x_media_line):
...
@@ -2115,32 +2072,19 @@ def extract_media(x_media_line):
media_url
=
media
.
get
(
'URI'
)
media_url
=
media
.
get
(
'URI'
)
if
media_url
:
if
media_url
:
manifest_url
=
format_url
(
media_url
)
manifest_url
=
format_url
(
media_url
)
format_id
=
[]
formats
.
extend
({
playlist_formats
=
_extract_m3u8_playlist_formats
(
manifest_url
,
video_id
=
video_id
,
'format_id'
:
'-'
.
join
(
map
(
str
,
filter
(
None
,
(
m3u8_id
,
group_id
,
name
,
idx
)))),
fatal
=
fatal
,
data
=
data
,
headers
=
headers
)
'format_note'
:
name
,
'format_index'
:
idx
,
for
format
in
playlist_formats
:
'url'
:
manifest_url
,
format_index
=
format
.
get
(
'index'
)
'manifest_url'
:
m3u8_url
,
for
v
in
(
m3u8_id
,
group_id
,
name
):
'language'
:
media
.
get
(
'LANGUAGE'
),
if
v
:
'ext'
:
ext
,
format_id
.
append
(
v
)
'protocol'
:
entry_protocol
,
if
format_index
:
'preference'
:
preference
,
format_id
.
append
(
str
(
format_index
))
'quality'
:
quality
,
f
=
{
'vcodec'
:
'none'
if
media_type
==
'AUDIO'
else
None
,
'format_id'
:
'-'
.
join
(
format_id
),
}
for
idx
in
_extract_m3u8_playlist_indices
(
manifest_url
))
'format_note'
:
name
,
'format_index'
:
format_index
,
'url'
:
manifest_url
,
'manifest_url'
:
m3u8_url
,
'language'
:
media
.
get
(
'LANGUAGE'
),
'ext'
:
ext
,
'protocol'
:
entry_protocol
,
'preference'
:
preference
,
'quality'
:
quality
,
}
if
media_type
==
'AUDIO'
:
f
[
'vcodec'
]
=
'none'
formats
.
append
(
f
)
def
build_stream_name
():
def
build_stream_name
():
# Despite specification does not mention NAME attribute for
# Despite specification does not mention NAME attribute for
...
@@ -2179,25 +2123,17 @@ def build_stream_name():
...
@@ -2179,25 +2123,17 @@ def build_stream_name():
or
last_stream_inf
.
get
(
'BANDWIDTH'
),
scale
=
1000
)
or
last_stream_inf
.
get
(
'BANDWIDTH'
),
scale
=
1000
)
manifest_url
=
format_url
(
line
.
strip
())
manifest_url
=
format_url
(
line
.
strip
())
playlist_formats
=
_extract_m3u8_playlist_formats
(
manifest_url
,
video_id
=
video_id
,
for
idx
in
_extract_m3u8_playlist_indices
(
manifest_url
):
fatal
=
fatal
,
data
=
data
,
headers
=
headers
)
format_id
=
[
m3u8_id
,
None
,
idx
]
for
frmt
in
playlist_formats
:
format_id
=
[]
if
m3u8_id
:
format_id
.
append
(
m3u8_id
)
format_index
=
frmt
.
get
(
'index'
)
stream_name
=
build_stream_name
()
# Bandwidth of live streams may differ over time thus making
# Bandwidth of live streams may differ over time thus making
# format_id unpredictable. So it's better to keep provided
# format_id unpredictable. So it's better to keep provided
# format_id intact.
# format_id intact.
if
not
live
:
if
not
live
:
format_id
.
append
(
stream_name
if
stream_name
else
'%d'
%
(
tbr
if
tbr
else
len
(
formats
)))
stream_name
=
build_stream_name
()
if
format_index
:
format_id
[
1
]
=
stream_name
if
stream_name
else
'%d'
%
(
tbr
if
tbr
else
len
(
formats
))
format_id
.
append
(
str
(
format_index
))
f
=
{
f
=
{
'format_id'
:
'-'
.
join
(
format_id
),
'format_id'
:
'-'
.
join
(
map
(
str
,
filter
(
None
,
format_id
))
),
'format_index'
:
format_inde
x
,
'format_index'
:
id
x
,
'url'
:
manifest_url
,
'url'
:
manifest_url
,
'manifest_url'
:
m3u8_url
,
'manifest_url'
:
m3u8_url
,
'tbr'
:
tbr
,
'tbr'
:
tbr
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录