Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
352d63fd
Y
Yt Dlp
项目概览
XianxinMao
/
Yt Dlp
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
352d63fd
编写于
7月 21, 2021
作者:
P
pukkandan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[utils] Improve `traverse_obj`
上级
11f9be09
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
11 deletion
+20
-11
yt_dlp/extractor/youtube.py
yt_dlp/extractor/youtube.py
+5
-5
yt_dlp/utils.py
yt_dlp/utils.py
+15
-6
未找到文件。
yt_dlp/extractor/youtube.py
浏览文件 @
352d63fd
...
...
@@ -1929,10 +1929,11 @@ def _extract_signature_timestamp(self, video_id, player_url, ytcfg=None, fatal=F
return
sts
def
_mark_watched
(
self
,
video_id
,
player_responses
):
playback_url
=
url_or_none
((
traverse_obj
(
player_responses
,
(
'playbackTracking'
,
'videostatsPlaybackUrl'
,
'baseUrl'
),
expected_type
=
str
)
or
[
None
])[
0
]
)
playback_url
=
traverse_obj
(
player_responses
,
(
...,
'playbackTracking'
,
'videostatsPlaybackUrl'
,
'baseUrl'
),
expected_type
=
url_or_none
,
get_all
=
False
)
if
not
playback_url
:
self
.
report_warning
(
'Unable to mark watched'
)
return
parsed_playback_url
=
compat_urlparse
.
urlparse
(
playback_url
)
qs
=
compat_urlparse
.
parse_qs
(
parsed_playback_url
.
query
)
...
...
@@ -2606,8 +2607,7 @@ def _real_extract(self, url):
self
.
_get_requested_clients
(
url
,
smuggled_data
),
video_id
,
webpage
,
master_ytcfg
,
player_url
,
identity_token
))
get_first
=
lambda
obj
,
keys
,
**
kwargs
:
(
traverse_obj
(
obj
,
(...,
*
variadic
(
keys
)),
**
kwargs
)
or
[
None
])[
0
]
get_first
=
lambda
obj
,
keys
,
**
kwargs
:
traverse_obj
(
obj
,
(...,
*
variadic
(
keys
)),
**
kwargs
,
get_all
=
False
)
playability_statuses
=
traverse_obj
(
player_responses
,
(...,
'playabilityStatus'
),
expected_type
=
dict
,
default
=
[])
...
...
yt_dlp/utils.py
浏览文件 @
352d63fd
...
...
@@ -6225,7 +6225,7 @@ def load_plugins(name, suffix, namespace):
def
traverse_obj
(
obj
,
*
path_list
,
default
=
None
,
expected_type
=
None
,
obj
,
*
path_list
,
default
=
None
,
expected_type
=
None
,
get_all
=
True
,
casesense
=
True
,
is_user_input
=
False
,
traverse_string
=
False
):
''' Traverse nested list/dict/tuple
@param path_list A list of paths which are checked one by one.
...
...
@@ -6234,7 +6234,8 @@ def traverse_obj(
all the keys given in the tuple are traversed, and
"..." traverses all the keys in the object
@param default Default value to return
@param expected_type Only accept final value of this type
@param expected_type Only accept final value of this type (Can also be any callable)
@param get_all Return all the values obtained from a path or only the first one
@param casesense Whether to consider dictionary keys as case sensitive
@param is_user_input Whether the keys are generated from user input. If True,
strings are converted to int/slice if necessary
...
...
@@ -6281,6 +6282,13 @@ def _traverse_obj(obj, path, _current_depth=0):
return
None
return
obj
if
isinstance
(
expected_type
,
type
):
type_test
=
lambda
val
:
val
if
isinstance
(
val
,
expected_type
)
else
None
elif
expected_type
is
not
None
:
type_test
=
expected_type
else
:
type_test
=
lambda
val
:
val
for
path
in
path_list
:
depth
=
0
val
=
_traverse_obj
(
obj
,
path
)
...
...
@@ -6288,12 +6296,13 @@ def _traverse_obj(obj, path, _current_depth=0):
if
depth
:
for
_
in
range
(
depth
-
1
):
val
=
itertools
.
chain
.
from_iterable
(
v
for
v
in
val
if
v
is
not
None
)
val
=
([
v
for
v
in
val
if
v
is
not
None
]
if
expected_type
is
None
else
[
v
for
v
in
val
if
isinstance
(
v
,
expected_type
)])
val
=
[
v
for
v
in
map
(
type_test
,
val
)
if
v
is
not
None
]
if
val
:
return
val
if
get_all
else
val
[
0
]
else
:
val
=
type_test
(
val
)
if
val
is
not
None
:
return
val
elif
expected_type
is
None
or
isinstance
(
val
,
expected_type
):
return
val
return
default
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录