Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
182b6ae8
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,发现更多精彩内容 >>
未验证
提交
182b6ae8
编写于
7月 14, 2021
作者:
F
Felix S
提交者:
GitHub
7月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[RTP] Fix extraction and add subtitles (#497)
Authored by: fstirlitz
上级
c843e685
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
27 deletion
+61
-27
yt_dlp/extractor/rtp.py
yt_dlp/extractor/rtp.py
+61
-27
未找到文件。
yt_dlp/extractor/rtp.py
浏览文件 @
182b6ae8
...
...
@@ -2,10 +2,11 @@
from
__future__
import
unicode_literals
from
.common
import
InfoExtractor
from
..utils
import
(
determine_ext
,
js_to_json
,
)
from
..utils
import
js_to_json
import
re
import
json
import
urllib.parse
import
base64
class
RTPIE
(
InfoExtractor
):
...
...
@@ -25,6 +26,22 @@ class RTPIE(InfoExtractor):
'only_matching'
:
True
,
}]
_RX_OBFUSCATION
=
re
.
compile
(
r
'''(?xs)
atob\s*\(\s*decodeURIComponent\s*\(\s*
(\[[0-9A-Za-z%,'"]*\])
\s*\.\s*join\(\s*(?:""|'')\s*\)\s*\)\s*\)
'''
)
def
__unobfuscate
(
self
,
data
,
*
,
video_id
):
if
data
.
startswith
(
'{'
):
data
=
self
.
_RX_OBFUSCATION
.
sub
(
lambda
m
:
json
.
dumps
(
base64
.
b64decode
(
urllib
.
parse
.
unquote
(
''
.
join
(
self
.
_parse_json
(
m
.
group
(
1
),
video_id
))
)).
decode
(
'iso-8859-1'
)),
data
)
return
js_to_json
(
data
)
def
_real_extract
(
self
,
url
):
video_id
=
self
.
_match_id
(
url
)
...
...
@@ -32,30 +49,46 @@ def _real_extract(self, url):
title
=
self
.
_html_search_meta
(
'twitter:title'
,
webpage
,
display_name
=
'title'
,
fatal
=
True
)
config
=
self
.
_parse_json
(
self
.
_search_regex
(
r
'(?s)RTPPlayer\(({.+?})\);'
,
webpage
,
'player config'
),
video_id
,
js_to_json
)
file_url
=
config
[
'file'
]
ext
=
determine_ext
(
file_url
)
if
ext
==
'm3u8'
:
file_key
=
config
.
get
(
'fileKey'
)
formats
=
self
.
_extract_m3u8_formats
(
file_url
,
video_id
,
'mp4'
,
'm3u8_native'
,
m3u8_id
=
'hls'
,
fatal
=
file_key
)
if
file_key
:
formats
.
append
({
'url'
:
'https://cdn-ondemand.rtp.pt'
+
file_key
,
'quality'
:
1
,
})
self
.
_sort_formats
(
formats
)
f
,
config
=
self
.
_search_regex
(
r
'''(?sx)
var\s+f\s*=\s*(?P<f>".*?"|{[^;]+?});\s*
var\s+player1\s+=\s+new\s+RTPPlayer\s*\((?P<config>{(?:(?!\*/).)+?})\);(?!\s*\*/)
'''
,
webpage
,
'player config'
,
group
=
(
'f'
,
'config'
))
f
=
self
.
_parse_json
(
f
,
video_id
,
lambda
data
:
self
.
__unobfuscate
(
data
,
video_id
=
video_id
))
config
=
self
.
_parse_json
(
config
,
video_id
,
lambda
data
:
self
.
__unobfuscate
(
data
,
video_id
=
video_id
))
formats
=
[]
if
isinstance
(
f
,
dict
):
f_hls
=
f
.
get
(
'hls'
)
if
f_hls
is
not
None
:
formats
.
extend
(
self
.
_extract_m3u8_formats
(
f_hls
,
video_id
,
'mp4'
,
'm3u8_native'
,
m3u8_id
=
'hls'
))
f_dash
=
f
.
get
(
'dash'
)
if
f_dash
is
not
None
:
formats
.
extend
(
self
.
_extract_mpd_formats
(
f_dash
,
video_id
,
mpd_id
=
'dash'
))
else
:
formats
=
[{
'url'
:
file_url
,
'ext'
:
ext
,
}]
if
config
.
get
(
'mediaType'
)
==
'audio'
:
for
f
in
formats
:
f
[
'vcodec'
]
=
'none'
formats
.
append
({
'format_id'
:
'f'
,
'url'
:
f
,
'vcodec'
:
'none'
if
config
.
get
(
'mediaType'
)
==
'audio'
else
None
,
})
subtitles
=
{}
vtt
=
config
.
get
(
'vtt'
)
if
vtt
is
not
None
:
for
lcode
,
lname
,
url
in
vtt
:
subtitles
.
setdefault
(
lcode
,
[]).
append
({
'name'
:
lname
,
'url'
:
url
,
})
return
{
'id'
:
video_id
,
...
...
@@ -63,4 +96,5 @@ def _real_extract(self, url):
'formats'
:
formats
,
'description'
:
self
.
_html_search_meta
([
'description'
,
'twitter:description'
],
webpage
),
'thumbnail'
:
config
.
get
(
'poster'
)
or
self
.
_og_search_thumbnail
(
webpage
),
'subtitles'
:
subtitles
,
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录