Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
无聊人士张
you-get
提交
cdb0d3d1
Y
you-get
项目概览
无聊人士张
/
you-get
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
you-get
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cdb0d3d1
编写于
2月 18, 2019
作者:
M
Mort Yao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bilibili] get alternative qualities for bangumi
上级
17d1597c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
56 addition
and
39 deletion
+56
-39
src/you_get/extractors/bilibili.py
src/you_get/extractors/bilibili.py
+56
-39
未找到文件。
src/you_get/extractors/bilibili.py
浏览文件 @
cdb0d3d1
...
@@ -208,39 +208,56 @@ class Bilibili(VideoExtractor):
...
@@ -208,39 +208,56 @@ class Bilibili(VideoExtractor):
initial_state_text
=
match1
(
html_content
,
r
'__INITIAL_STATE__=(.*?);\(function\(\)'
)
# FIXME
initial_state_text
=
match1
(
html_content
,
r
'__INITIAL_STATE__=(.*?);\(function\(\)'
)
# FIXME
initial_state
=
json
.
loads
(
initial_state_text
)
initial_state
=
json
.
loads
(
initial_state_text
)
# set video title
self
.
title
=
initial_state
[
'h1Title'
]
# warn if this bangumi has more than 1 video
# warn if this bangumi has more than 1 video
epn
=
len
(
initial_state
[
'epList'
])
epn
=
len
(
initial_state
[
'epList'
])
if
epn
>
1
and
not
kwargs
.
get
(
'playlist'
):
if
epn
>
1
and
not
kwargs
.
get
(
'playlist'
):
log
.
w
(
'This bangumi currently has %s videos. (use --playlist to download all videos.)'
%
epn
)
log
.
w
(
'This bangumi currently has %s videos. (use --playlist to download all videos.)'
%
epn
)
# set video title
self
.
title
=
initial_state
[
'h1Title'
]
# construct playinfos
ep_id
=
initial_state
[
'epInfo'
][
'id'
]
ep_id
=
initial_state
[
'epInfo'
][
'id'
]
avid
=
initial_state
[
'epInfo'
][
'aid'
]
avid
=
initial_state
[
'epInfo'
][
'aid'
]
cid
=
initial_state
[
'epInfo'
][
'cid'
]
cid
=
initial_state
[
'epInfo'
][
'cid'
]
playinfos
=
[]
api_url
=
self
.
bilibili_bangumi_api
(
avid
,
cid
,
ep_id
)
api_url
=
self
.
bilibili_bangumi_api
(
avid
,
cid
,
ep_id
)
api_content
=
get_content
(
api_url
,
headers
=
self
.
bilibili_headers
())
api_content
=
get_content
(
api_url
,
headers
=
self
.
bilibili_headers
())
data
=
json
.
loads
(
api_content
)
api_playinfo
=
json
.
loads
(
api_content
)
if
data
[
'code'
]
<
0
:
# error
if
api_playinfo
[
'code'
]
==
0
:
# success
log
.
e
(
data
[
'message'
])
playinfos
.
append
(
api_playinfo
)
else
:
log
.
e
(
api_playinfo
[
'message'
])
return
return
current_quality
=
api_playinfo
[
'result'
][
'quality'
]
# get alternative formats from API
for
qn
in
[
80
,
64
,
32
,
16
]:
# automatic format for durl: qn=0
# for dash, qn does not matter
if
qn
!=
current_quality
:
api_url
=
self
.
bilibili_bangumi_api
(
avid
,
cid
,
ep_id
,
qn
=
qn
)
api_content
=
get_content
(
api_url
,
headers
=
self
.
bilibili_headers
())
api_playinfo
=
json
.
loads
(
api_content
)
if
api_playinfo
[
'code'
]
==
0
:
# success
playinfos
.
append
(
api_playinfo
)
if
'durl'
in
data
[
'result'
]:
for
playinfo
in
playinfos
:
quality
=
data
[
'result'
][
'quality'
]
if
'durl'
in
playinfo
[
'result'
]:
quality
=
playinfo
[
'result'
][
'quality'
]
format_id
=
self
.
stream_qualities
[
quality
][
'id'
]
format_id
=
self
.
stream_qualities
[
quality
][
'id'
]
container
=
self
.
stream_qualities
[
quality
][
'container'
].
lower
()
container
=
self
.
stream_qualities
[
quality
][
'container'
].
lower
()
desc
=
self
.
stream_qualities
[
quality
][
'desc'
]
desc
=
self
.
stream_qualities
[
quality
][
'desc'
]
src
,
size
=
[],
0
src
,
size
=
[],
0
for
durl
in
data
[
'result'
][
'durl'
]:
for
durl
in
playinfo
[
'result'
][
'durl'
]:
src
.
append
(
durl
[
'url'
])
src
.
append
(
durl
[
'url'
])
size
+=
durl
[
'size'
]
size
+=
durl
[
'size'
]
self
.
streams
[
format_id
]
=
{
'container'
:
container
,
'quality'
:
desc
,
'size'
:
size
,
'src'
:
src
}
self
.
streams
[
format_id
]
=
{
'container'
:
container
,
'quality'
:
desc
,
'size'
:
size
,
'src'
:
src
}
# DASH formats
# DASH formats
if
'dash'
in
data
[
'result'
]:
if
'dash'
in
playinfo
[
'result'
]:
for
video
in
data
[
'result'
][
'dash'
][
'video'
]:
for
video
in
playinfo
[
'result'
][
'dash'
][
'video'
]:
# playinfo['result']['quality'] does not reflect the correct quality of DASH stream
quality
=
self
.
height_to_quality
(
video
[
'height'
])
# convert height to quality code
quality
=
self
.
height_to_quality
(
video
[
'height'
])
# convert height to quality code
s
=
self
.
stream_qualities
[
quality
]
s
=
self
.
stream_qualities
[
quality
]
format_id
=
'dash-'
+
s
[
'id'
]
# prefix
format_id
=
'dash-'
+
s
[
'id'
]
# prefix
...
@@ -251,8 +268,8 @@ class Bilibili(VideoExtractor):
...
@@ -251,8 +268,8 @@ class Bilibili(VideoExtractor):
size
=
url_size
(
baseurl
,
headers
=
self
.
bilibili_headers
(
referer
=
self
.
url
))
size
=
url_size
(
baseurl
,
headers
=
self
.
bilibili_headers
(
referer
=
self
.
url
))
# find matching audio track
# find matching audio track
audio_baseurl
=
data
[
'result'
][
'dash'
][
'audio'
][
0
][
'baseUrl'
]
audio_baseurl
=
playinfo
[
'result'
][
'dash'
][
'audio'
][
0
][
'baseUrl'
]
for
audio
in
data
[
'result'
][
'dash'
][
'audio'
]:
for
audio
in
playinfo
[
'result'
][
'dash'
][
'audio'
]:
if
int
(
audio
[
'id'
])
==
audio_quality
:
if
int
(
audio
[
'id'
])
==
audio_quality
:
audio_baseurl
=
audio
[
'baseUrl'
]
audio_baseurl
=
audio
[
'baseUrl'
]
break
break
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录