Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
c2603313
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,发现更多精彩内容 >>
未验证
提交
c2603313
编写于
6月 27, 2021
作者:
S
siikamiika
提交者:
GitHub
6月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[youtube_live_chat] use `clickTrackingParams` (#449)
Authored by: siikamiika
上级
1e79316e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
18 deletion
+29
-18
yt_dlp/downloader/youtube_live_chat.py
yt_dlp/downloader/youtube_live_chat.py
+29
-18
未找到文件。
yt_dlp/downloader/youtube_live_chat.py
浏览文件 @
c2603313
...
...
@@ -44,7 +44,7 @@ def dl_fragment(url, data=None, headers=None):
return
self
.
_download_fragment
(
ctx
,
url
,
info_dict
,
http_headers
,
data
)
def
parse_actions_replay
(
live_chat_continuation
):
offset
=
continuation_id
=
None
offset
=
continuation_id
=
click_tracking_params
=
None
processed_fragment
=
bytearray
()
for
action
in
live_chat_continuation
.
get
(
'actions'
,
[]):
if
'replayChatItemAction'
in
action
:
...
...
@@ -53,28 +53,34 @@ def parse_actions_replay(live_chat_continuation):
processed_fragment
.
extend
(
json
.
dumps
(
action
,
ensure_ascii
=
False
).
encode
(
'utf-8'
)
+
b
'
\n
'
)
if
offset
is
not
None
:
continuation
_id
=
try_get
(
continuation
=
try_get
(
live_chat_continuation
,
lambda
x
:
x
[
'continuations'
][
0
][
'liveChatReplayContinuationData'
][
'continuation'
])
lambda
x
:
x
[
'continuations'
][
0
][
'liveChatReplayContinuationData'
],
dict
)
if
continuation
:
continuation_id
=
continuation
.
get
(
'continuation'
)
click_tracking_params
=
continuation
.
get
(
'clickTrackingParams'
)
self
.
_append_fragment
(
ctx
,
processed_fragment
)
return
continuation_id
,
offset
return
continuation_id
,
offset
,
click_tracking_params
def
try_refresh_replay_beginning
(
live_chat_continuation
):
# choose the second option that contains the unfiltered live chat replay
refresh_continuation
_id
=
try_get
(
refresh_continuation
=
try_get
(
live_chat_continuation
,
lambda
x
:
x
[
'header'
][
'liveChatHeaderRenderer'
][
'viewSelector'
][
'sortFilterSubMenuRenderer'
][
'subMenuItems'
][
1
][
'continuation'
][
'reloadContinuationData'
]
[
'continuation'
],
str
)
if
refresh_continuation
_id
:
lambda
x
:
x
[
'header'
][
'liveChatHeaderRenderer'
][
'viewSelector'
][
'sortFilterSubMenuRenderer'
][
'subMenuItems'
][
1
][
'continuation'
][
'reloadContinuationData'
]
,
dict
)
if
refresh_continuation
:
# no data yet but required to call _append_fragment
self
.
_append_fragment
(
ctx
,
b
''
)
return
refresh_continuation_id
,
0
refresh_continuation_id
=
refresh_continuation
.
get
(
'continuation'
)
offset
=
0
click_tracking_params
=
refresh_continuation
.
get
(
'trackingParams'
)
return
refresh_continuation_id
,
offset
,
click_tracking_params
return
parse_actions_replay
(
live_chat_continuation
)
live_offset
=
0
def
parse_actions_live
(
live_chat_continuation
):
nonlocal
live_offset
continuation_id
=
None
continuation_id
=
click_tracking_params
=
None
processed_fragment
=
bytearray
()
for
action
in
live_chat_continuation
.
get
(
'actions'
,
[]):
timestamp
=
self
.
parse_live_timestamp
(
action
)
...
...
@@ -95,11 +101,12 @@ def parse_actions_live(live_chat_continuation):
continuation_data
=
try_get
(
live_chat_continuation
,
continuation_data_getters
,
dict
)
if
continuation_data
:
continuation_id
=
continuation_data
.
get
(
'continuation'
)
click_tracking_params
=
continuation_data
.
get
(
'clickTrackingParams'
)
timeout_ms
=
int_or_none
(
continuation_data
.
get
(
'timeoutMs'
))
if
timeout_ms
is
not
None
:
time
.
sleep
(
timeout_ms
/
1000
)
self
.
_append_fragment
(
ctx
,
processed_fragment
)
return
continuation_id
,
live_offset
return
continuation_id
,
live_offset
,
click_tracking_params
def
download_and_parse_fragment
(
url
,
frag_index
,
request_data
=
None
,
headers
=
None
):
count
=
0
...
...
@@ -107,7 +114,7 @@ def download_and_parse_fragment(url, frag_index, request_data=None, headers=None
try
:
success
,
raw_fragment
=
dl_fragment
(
url
,
request_data
,
headers
)
if
not
success
:
return
False
,
None
,
None
return
False
,
None
,
None
,
None
try
:
data
=
ie
.
_extract_yt_initial_data
(
video_id
,
raw_fragment
.
decode
(
'utf-8'
,
'replace'
))
except
RegexNotFoundError
:
...
...
@@ -119,19 +126,19 @@ def download_and_parse_fragment(url, frag_index, request_data=None, headers=None
lambda
x
:
x
[
'continuationContents'
][
'liveChatContinuation'
],
dict
)
or
{}
if
info_dict
[
'protocol'
]
==
'youtube_live_chat_replay'
:
if
frag_index
==
1
:
continuation_id
,
offset
=
try_refresh_replay_beginning
(
live_chat_continuation
)
continuation_id
,
offset
,
click_tracking_params
=
try_refresh_replay_beginning
(
live_chat_continuation
)
else
:
continuation_id
,
offset
=
parse_actions_replay
(
live_chat_continuation
)
continuation_id
,
offset
,
click_tracking_params
=
parse_actions_replay
(
live_chat_continuation
)
elif
info_dict
[
'protocol'
]
==
'youtube_live_chat'
:
continuation_id
,
offset
=
parse_actions_live
(
live_chat_continuation
)
return
True
,
continuation_id
,
offset
continuation_id
,
offset
,
click_tracking_params
=
parse_actions_live
(
live_chat_continuation
)
return
True
,
continuation_id
,
offset
,
click_tracking_params
except
compat_urllib_error
.
HTTPError
as
err
:
count
+=
1
if
count
<=
fragment_retries
:
self
.
report_retry_fragment
(
err
,
frag_index
,
count
,
fragment_retries
)
if
count
>
fragment_retries
:
self
.
report_error
(
'giving up after %s fragment retries'
%
fragment_retries
)
return
False
,
None
,
None
return
False
,
None
,
None
,
None
self
.
_prepare_and_start_frag_download
(
ctx
)
...
...
@@ -165,6 +172,7 @@ def download_and_parse_fragment(url, frag_index, request_data=None, headers=None
chat_page_url
=
'https://www.youtube.com/live_chat?continuation='
+
continuation_id
frag_index
=
offset
=
0
click_tracking_params
=
None
while
continuation_id
is
not
None
:
frag_index
+=
1
request_data
=
{
...
...
@@ -173,13 +181,16 @@ def download_and_parse_fragment(url, frag_index, request_data=None, headers=None
}
if
frag_index
>
1
:
request_data
[
'currentPlayerState'
]
=
{
'playerOffsetMs'
:
str
(
max
(
offset
-
5000
,
0
))}
if
click_tracking_params
:
request_data
[
'context'
][
'clickTracking'
]
=
{
'clickTrackingParams'
:
click_tracking_params
}
headers
=
ie
.
_generate_api_headers
(
ytcfg
,
visitor_data
=
visitor_data
)
headers
.
update
({
'content-type'
:
'application/json'
})
fragment_request_data
=
json
.
dumps
(
request_data
,
ensure_ascii
=
False
).
encode
(
'utf-8'
)
+
b
'
\n
'
success
,
continuation_id
,
offset
=
download_and_parse_fragment
(
success
,
continuation_id
,
offset
,
click_tracking_params
=
download_and_parse_fragment
(
url
,
frag_index
,
fragment_request_data
,
headers
)
else
:
success
,
continuation_id
,
offset
=
download_and_parse_fragment
(
chat_page_url
,
frag_index
)
success
,
continuation_id
,
offset
,
click_tracking_params
=
download_and_parse_fragment
(
chat_page_url
,
frag_index
)
if
not
success
:
return
False
if
test
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录