Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
fd7cfb64
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,发现更多精彩内容 >>
未验证
提交
fd7cfb64
编写于
6月 20, 2021
作者:
P
pukkandan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cleanup] Refactor fixup
上级
4e6767b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
100 deletion
+63
-100
yt_dlp/YoutubeDL.py
yt_dlp/YoutubeDL.py
+43
-65
yt_dlp/options.py
yt_dlp/options.py
+1
-0
yt_dlp/postprocessor/ffmpeg.py
yt_dlp/postprocessor/ffmpeg.py
+19
-35
未找到文件。
yt_dlp/YoutubeDL.py
浏览文件 @
fd7cfb64
...
...
@@ -570,14 +570,9 @@ def preload_download_archive(fn):
self
.
add_default_info_extractors
()
for
pp_def_raw
in
self
.
params
.
get
(
'postprocessors'
,
[]):
pp_class
=
get_postprocessor
(
pp_def_raw
[
'key'
])
pp_def
=
dict
(
pp_def_raw
)
del
pp_def
[
'key'
]
if
'when'
in
pp_def
:
when
=
pp_def
[
'when'
]
del
pp_def
[
'when'
]
else
:
when
=
'post_process'
when
=
pp_def
.
pop
(
'when'
,
'post_process'
)
pp_class
=
get_postprocessor
(
pp_def
.
pop
(
'key'
))
pp
=
pp_class
(
self
,
**
compat_kwargs
(
pp_def
))
self
.
add_post_processor
(
pp
,
when
=
when
)
...
...
@@ -2685,65 +2680,48 @@ def correct_ext(filename):
return
if
success
and
full_filename
!=
'-'
:
# Fixup content
fixup_policy
=
self
.
params
.
get
(
'fixup'
)
if
fixup_policy
is
None
:
fixup_policy
=
'detect_or_warn'
INSTALL_FFMPEG_MESSAGE
=
'Install ffmpeg to fix this automatically.'
stretched_ratio
=
info_dict
.
get
(
'stretched_ratio'
)
if
stretched_ratio
is
not
None
and
stretched_ratio
!=
1
:
if
fixup_policy
==
'warn'
:
self
.
report_warning
(
'%s: Non-uniform pixel ratio (%s)'
%
(
info_dict
[
'id'
],
stretched_ratio
))
elif
fixup_policy
==
'detect_or_warn'
:
stretched_pp
=
FFmpegFixupStretchedPP
(
self
)
if
stretched_pp
.
available
:
info_dict
[
'__postprocessors'
].
append
(
stretched_pp
)
else
:
self
.
report_warning
(
'%s: Non-uniform pixel ratio (%s). %s'
%
(
info_dict
[
'id'
],
stretched_ratio
,
INSTALL_FFMPEG_MESSAGE
))
else
:
assert
fixup_policy
in
(
'ignore'
,
'never'
)
if
(
info_dict
.
get
(
'requested_formats'
)
is
None
and
info_dict
.
get
(
'container'
)
==
'm4a_dash'
and
info_dict
.
get
(
'ext'
)
==
'm4a'
):
if
fixup_policy
==
'warn'
:
self
.
report_warning
(
'%s: writing DASH m4a. '
'Only some players support this container.'
%
info_dict
[
'id'
])
elif
fixup_policy
==
'detect_or_warn'
:
fixup_pp
=
FFmpegFixupM4aPP
(
self
)
if
fixup_pp
.
available
:
info_dict
[
'__postprocessors'
].
append
(
fixup_pp
)
else
:
self
.
report_warning
(
'%s: writing DASH m4a. '
'Only some players support this container. %s'
%
(
info_dict
[
'id'
],
INSTALL_FFMPEG_MESSAGE
))
else
:
assert
fixup_policy
in
(
'ignore'
,
'never'
)
if
(
'protocol'
in
info_dict
and
get_suitable_downloader
(
info_dict
,
self
.
params
).
__name__
==
'HlsFD'
):
if
fixup_policy
==
'warn'
:
self
.
report_warning
(
'%s: malformed AAC bitstream detected.'
%
(
info_dict
[
'id'
]))
elif
fixup_policy
==
'detect_or_warn'
:
fixup_pp
=
FFmpegFixupM3u8PP
(
self
)
if
fixup_pp
.
available
:
info_dict
[
'__postprocessors'
].
append
(
fixup_pp
)
else
:
self
.
report_warning
(
'%s: malformed AAC bitstream detected. %s'
%
(
info_dict
[
'id'
],
INSTALL_FFMPEG_MESSAGE
))
else
:
assert
fixup_policy
in
(
'ignore'
,
'never'
)
def
fixup
():
do_fixup
=
True
fixup_policy
=
self
.
params
.
get
(
'fixup'
)
vid
=
info_dict
[
'id'
]
if
fixup_policy
in
(
'ignore'
,
'never'
):
return
elif
fixup_policy
==
'warn'
:
do_fixup
=
False
assert
fixup_policy
in
(
'detect_or_warn'
,
None
)
def
ffmpeg_fixup
(
cndn
,
msg
,
cls
):
if
not
cndn
:
return
if
not
do_fixup
:
self
.
report_warning
(
f
'
{
vid
}
:
{
msg
}
'
)
return
pp
=
cls
(
self
)
if
pp
.
available
:
info_dict
[
'__postprocessors'
].
append
(
pp
)
else
:
self
.
report_warning
(
f
'
{
vid
}
:
{
msg
}
. Install ffmpeg to fix this automatically'
)
stretched_ratio
=
info_dict
.
get
(
'stretched_ratio'
)
ffmpeg_fixup
(
stretched_ratio
not
in
(
1
,
None
),
f
'Non-uniform pixel ratio
{
stretched_ratio
}
'
,
FFmpegFixupStretchedPP
)
ffmpeg_fixup
(
(
info_dict
.
get
(
'requested_formats'
)
is
None
and
info_dict
.
get
(
'container'
)
==
'm4a_dash'
and
info_dict
.
get
(
'ext'
)
==
'm4a'
),
'writing DASH m4a. Only some players support this container'
,
FFmpegFixupM4aPP
)
downloader
=
(
get_suitable_downloader
(
info_dict
,
self
.
params
).
__name__
if
'protocol'
in
info_dict
else
None
)
ffmpeg_fixup
(
downloader
==
'HlsFD'
,
'malformed AAC bitstream detected'
,
FFmpegFixupM3u8PP
)
fixup
()
try
:
info_dict
=
self
.
post_process
(
dl_filename
,
info_dict
,
files_to_move
)
except
PostProcessingError
as
err
:
...
...
yt_dlp/options.py
浏览文件 @
fd7cfb64
...
...
@@ -1230,6 +1230,7 @@ def _dict_from_options_callback(
postproc
.
add_option
(
'--fixup'
,
metavar
=
'POLICY'
,
dest
=
'fixup'
,
default
=
None
,
choices
=
(
'never'
,
'ignore'
,
'warn'
,
'detect_or_warn'
),
help
=
(
'Automatically correct known faults of the file. '
'One of never (do nothing), warn (only emit a warning), '
...
...
yt_dlp/postprocessor/ffmpeg.py
浏览文件 @
fd7cfb64
...
...
@@ -661,58 +661,42 @@ def can_merge(self):
return
True
class
FFmpegFixupStretchedPP
(
FFmpegPostProcessor
):
@
PostProcessor
.
_restrict_to
(
images
=
False
,
audio
=
False
)
def
run
(
self
,
info
):
stretched_ratio
=
info
.
get
(
'stretched_ratio'
)
if
stretched_ratio
is
None
or
stretched_ratio
==
1
:
return
[],
info
filename
=
info
[
'filepath'
]
class
FFmpegFixupPostProcessor
(
FFmpegPostProcessor
):
def
_fixup
(
self
,
msg
,
filename
,
options
):
temp_filename
=
prepend_extension
(
filename
,
'temp'
)
options
=
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-aspect'
,
'%f'
%
stretched_ratio
]
self
.
to_screen
(
'Fixing aspect ratio in "%s"'
%
filename
)
self
.
to_screen
(
'{msg} of "{filename}"'
)
self
.
run_ffmpeg
(
filename
,
temp_filename
,
options
)
os
.
remove
(
encodeFilename
(
filename
))
os
.
rename
(
encodeFilename
(
temp_filename
),
encodeFilename
(
filename
))
class
FFmpegFixupStretchedPP
(
FFmpegFixupPostProcessor
):
@
PostProcessor
.
_restrict_to
(
images
=
False
,
audio
=
False
)
def
run
(
self
,
info
):
stretched_ratio
=
info
.
get
(
'stretched_ratio'
)
if
stretched_ratio
not
in
(
None
,
1
):
self
.
_fixup
(
'Fixing aspect ratio'
,
info
[
'filepath'
],
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-aspect'
,
'%f'
%
stretched_ratio
])
return
[],
info
class
FFmpegFixupM4aPP
(
FFmpegPostProcessor
):
class
FFmpegFixupM4aPP
(
FFmpeg
Fixup
PostProcessor
):
@
PostProcessor
.
_restrict_to
(
images
=
False
,
video
=
False
)
def
run
(
self
,
info
):
if
info
.
get
(
'container'
)
!=
'm4a_dash'
:
return
[],
info
filename
=
info
[
'filepath'
]
temp_filename
=
prepend_extension
(
filename
,
'temp'
)
options
=
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-f'
,
'mp4'
]
self
.
to_screen
(
'Correcting container in "%s"'
%
filename
)
self
.
run_ffmpeg
(
filename
,
temp_filename
,
options
)
os
.
remove
(
encodeFilename
(
filename
))
os
.
rename
(
encodeFilename
(
temp_filename
),
encodeFilename
(
filename
))
if
info
.
get
(
'container'
)
==
'm4a_dash'
:
self
.
_fixup
(
'Correcting container'
,
info
[
'filepath'
],
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-f'
,
'mp4'
])
return
[],
info
class
FFmpegFixupM3u8PP
(
FFmpegPostProcessor
):
class
FFmpegFixupM3u8PP
(
FFmpeg
Fixup
PostProcessor
):
@
PostProcessor
.
_restrict_to
(
images
=
False
)
def
run
(
self
,
info
):
filename
=
info
[
'filepath'
]
if
self
.
get_audio_codec
(
filename
)
==
'aac'
:
temp_filename
=
prepend_extension
(
filename
,
'temp'
)
options
=
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-f'
,
'mp4'
,
'-bsf:a'
,
'aac_adtstoasc'
]
self
.
to_screen
(
'Fixing malformed AAC bitstream in "%s"'
%
filename
)
self
.
run_ffmpeg
(
filename
,
temp_filename
,
options
)
os
.
remove
(
encodeFilename
(
filename
))
os
.
rename
(
encodeFilename
(
temp_filename
),
encodeFilename
(
filename
))
if
self
.
get_audio_codec
(
info
[
'filepath'
])
==
'aac'
:
self
.
_fixup
(
'Fixing malformed AAC bitstream'
,
info
[
'filepath'
],
[
'-c'
,
'copy'
,
'-map'
,
'0'
,
'-dn'
,
'-f'
,
'mp4'
,
'-bsf:a'
,
'aac_adtstoasc'
])
return
[],
info
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录