Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
314ee305
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,发现更多精彩内容 >>
未验证
提交
314ee305
编写于
7月 18, 2021
作者:
C
coletdjnz
提交者:
GitHub
7月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[youtube] Fix session index extraction and headers for non-web player clients (#526)
Fixes #522
上级
34917076
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
9 deletion
+16
-9
yt_dlp/extractor/youtube.py
yt_dlp/extractor/youtube.py
+16
-9
未找到文件。
yt_dlp/extractor/youtube.py
浏览文件 @
314ee305
...
...
@@ -416,6 +416,10 @@ def _ytcfg_get_safe(self, ytcfg, getter, expected_type=None, default_client='WEB
def
_extract_client_name
(
self
,
ytcfg
,
default_client
=
'WEB'
):
return
self
.
_ytcfg_get_safe
(
ytcfg
,
lambda
x
:
x
[
'INNERTUBE_CLIENT_NAME'
],
compat_str
,
default_client
)
@
staticmethod
def
_extract_session_index
(
ytcfg
):
return
int_or_none
(
try_get
(
ytcfg
,
lambda
x
:
x
[
'SESSION_INDEX'
]))
def
_extract_client_version
(
self
,
ytcfg
,
default_client
=
'WEB'
):
return
self
.
_ytcfg_get_safe
(
ytcfg
,
lambda
x
:
x
[
'INNERTUBE_CLIENT_VERSION'
],
compat_str
,
default_client
)
...
...
@@ -518,7 +522,7 @@ def _extract_ytcfg(self, video_id, webpage):
default
=
'{}'
),
video_id
,
fatal
=
False
)
or
{}
def
_generate_api_headers
(
self
,
ytcfg
=
None
,
identity_token
=
None
,
account_syncid
=
None
,
visitor_data
=
None
,
api_hostname
=
None
,
client
=
'WEB'
):
visitor_data
=
None
,
api_hostname
=
None
,
client
=
'WEB'
,
session_index
=
None
):
origin
=
'https://'
+
(
api_hostname
if
api_hostname
else
self
.
_get_innertube_host
(
client
))
headers
=
{
'X-YouTube-Client-Name'
:
compat_str
(
...
...
@@ -533,9 +537,10 @@ def _generate_api_headers(self, ytcfg=None, identity_token=None, account_syncid=
headers
[
'X-Youtube-Identity-Token'
]
=
identity_token
if
account_syncid
:
headers
[
'X-Goog-PageId'
]
=
account_syncid
session_index
=
try_get
(
ytcfg
,
lambda
x
:
x
[
'SESSION_INDEX'
],
compat_str
)
if
account_syncid
or
session_index
:
headers
[
'X-Goog-AuthUser'
]
=
session_index
or
0
if
session_index
is
None
and
ytcfg
:
session_index
=
self
.
_extract_session_index
(
ytcfg
)
if
account_syncid
or
session_index
is
not
None
:
headers
[
'X-Goog-AuthUser'
]
=
session_index
if
session_index
is
not
None
else
0
if
visitor_data
:
headers
[
'X-Goog-Visitor-Id'
]
=
visitor_data
auth
=
self
.
_generate_sapisidhash_header
(
origin
)
...
...
@@ -2294,8 +2299,8 @@ def _real_extract(self, url):
ytcfg
=
self
.
_extract_ytcfg
(
video_id
,
webpage
)
or
self
.
_get_default_ytcfg
()
identity_token
=
self
.
_extract_identity_token
(
webpage
,
video_id
)
syncid
=
self
.
_extract_account_syncid
(
ytcfg
)
headers
=
self
.
_generate_api_headers
(
ytcfg
,
identity_token
,
syncid
)
session_index
=
self
.
_extract_session_index
(
ytcfg
)
headers
=
self
.
_generate_api_headers
(
ytcfg
,
identity_token
,
syncid
,
session_index
=
session_index
)
player_url
=
self
.
_extract_player_url
(
ytcfg
,
webpage
)
player_client
=
self
.
_configuration_arg
(
'player_client'
,
[
''
])[
0
]
...
...
@@ -2336,7 +2341,7 @@ def get_text(x):
ytm_headers
=
self
.
_generate_api_headers
(
ytm_cfg
,
identity_token
,
syncid
,
client
=
ytm_client
)
client
=
ytm_client
,
session_index
=
session_index
)
ytm_query
=
{
'videoId'
:
video_id
}
ytm_query
.
update
(
self
.
_generate_player_context
(
sts
))
...
...
@@ -2365,7 +2370,8 @@ def get_text(x):
self
.
report_warning
(
'Falling back to android client for player API.'
)
yt_client
=
'ANDROID'
ytpcfg
=
{}
ytp_headers
=
self
.
_generate_api_headers
(
ytpcfg
,
identity_token
,
syncid
,
yt_client
)
ytp_headers
=
self
.
_generate_api_headers
(
ytpcfg
,
identity_token
,
syncid
,
client
=
yt_client
,
session_index
=
session_index
)
yt_query
=
{
'videoId'
:
video_id
}
yt_query
.
update
(
self
.
_generate_player_context
(
sts
))
...
...
@@ -2418,7 +2424,8 @@ def get_text(x):
ytcfg_age
=
{}
ytage_headers
=
self
.
_generate_api_headers
(
ytcfg_age
,
identity_token
,
syncid
,
client
=
yt_client
)
ytcfg_age
,
identity_token
,
syncid
,
client
=
yt_client
,
session_index
=
session_index
)
yt_age_query
=
{
'videoId'
:
video_id
}
yt_age_query
.
update
(
self
.
_generate_player_context
(
sts
))
pr
=
self
.
_extract_response
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录