Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XianxinMao
Yt Dlp
提交
145bd631
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,发现更多精彩内容 >>
未验证
提交
145bd631
编写于
7月 21, 2021
作者:
H
Henrik Heimbuerger
提交者:
GitHub
7月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[nebula] Authentication via tokens from cookie jar (#537)
Closes #496 Co-authored-by: hheimbuerger, TpmKranz
上级
b35496d8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
14 deletion
+51
-14
yt_dlp/extractor/nebula.py
yt_dlp/extractor/nebula.py
+51
-14
未找到文件。
yt_dlp/extractor/nebula.py
浏览文件 @
145bd631
...
...
@@ -2,9 +2,11 @@
from
__future__
import
unicode_literals
import
json
import
time
from
urllib.error
import
HTTPError
from
.common
import
InfoExtractor
from
..compat
import
compat_str
from
..compat
import
compat_str
,
compat_urllib_parse_unquote
,
compat_urllib_parse_quote
from
..utils
import
(
ExtractorError
,
parse_iso8601
,
...
...
@@ -78,7 +80,9 @@ class NebulaIE(InfoExtractor):
]
_NETRC_MACHINE
=
'watchnebula'
def
_retrieve_nebula_auth
(
self
,
video_id
):
_nebula_token
=
None
def
_retrieve_nebula_auth
(
self
):
"""
Log in to Nebula, and returns a Nebula API token
"""
...
...
@@ -91,7 +95,7 @@ def _retrieve_nebula_auth(self, video_id):
data
=
json
.
dumps
({
'email'
:
username
,
'password'
:
password
}).
encode
(
'utf8'
)
response
=
self
.
_download_json
(
'https://api.watchnebula.com/api/v1/auth/login/'
,
data
=
data
,
fatal
=
False
,
video_id
=
video_id
,
data
=
data
,
fatal
=
False
,
video_id
=
None
,
headers
=
{
'content-type'
:
'application/json'
,
# Submitting the 'sessionid' cookie always causes a 403 on auth endpoint
...
...
@@ -101,6 +105,19 @@ def _retrieve_nebula_auth(self, video_id):
errnote
=
'Authentication failed or rejected'
)
if
not
response
or
not
response
.
get
(
'key'
):
self
.
raise_login_required
()
# save nebula token as cookie
self
.
_set_cookie
(
'nebula.app'
,
'nebula-auth'
,
compat_urllib_parse_quote
(
json
.
dumps
({
"apiToken"
:
response
[
"key"
],
"isLoggingIn"
:
False
,
"isLoggingOut"
:
False
,
},
separators
=
(
","
,
":"
))),
expire_time
=
int
(
time
.
time
())
+
86400
*
365
,
)
return
response
[
'key'
]
def
_retrieve_zype_api_key
(
self
,
page_url
,
display_id
):
...
...
@@ -139,8 +156,17 @@ def _call_nebula_api(self, path, video_id, access_token, note):
'Authorization'
:
'Token {access_token}'
.
format
(
access_token
=
access_token
)
},
note
=
note
)
def
_fetch_zype_access_token
(
self
,
video_id
,
nebula_token
):
user_object
=
self
.
_call_nebula_api
(
'/auth/user/'
,
video_id
,
nebula_token
,
note
=
'Retrieving Zype access token'
)
def
_fetch_zype_access_token
(
self
,
video_id
):
try
:
user_object
=
self
.
_call_nebula_api
(
'/auth/user/'
,
video_id
,
self
.
_nebula_token
,
note
=
'Retrieving Zype access token'
)
except
ExtractorError
as
exc
:
# if 401, attempt credential auth and retry
if
exc
.
cause
and
isinstance
(
exc
.
cause
,
HTTPError
)
and
exc
.
cause
.
code
==
401
:
self
.
_nebula_token
=
self
.
_retrieve_nebula_auth
()
user_object
=
self
.
_call_nebula_api
(
'/auth/user/'
,
video_id
,
self
.
_nebula_token
,
note
=
'Retrieving Zype access token'
)
else
:
raise
access_token
=
try_get
(
user_object
,
lambda
x
:
x
[
'zype_auth_info'
][
'access_token'
],
compat_str
)
if
not
access_token
:
if
try_get
(
user_object
,
lambda
x
:
x
[
'is_subscribed'
],
bool
):
...
...
@@ -162,9 +188,21 @@ def _extract_channel_title(self, video_meta):
if
category
.
get
(
'value'
):
return
category
[
'value'
][
0
]
def
_real_initialize
(
self
):
# check cookie jar for valid token
nebula_cookies
=
self
.
_get_cookies
(
'https://nebula.app'
)
nebula_cookie
=
nebula_cookies
.
get
(
'nebula-auth'
)
if
nebula_cookie
:
self
.
to_screen
(
'Authenticating to Nebula with token from cookie jar'
)
nebula_cookie_value
=
compat_urllib_parse_unquote
(
nebula_cookie
.
value
)
self
.
_nebula_token
=
self
.
_parse_json
(
nebula_cookie_value
,
None
).
get
(
'apiToken'
)
# try to authenticate using credentials if no valid token has been found
if
not
self
.
_nebula_token
:
self
.
_nebula_token
=
self
.
_retrieve_nebula_auth
()
def
_real_extract
(
self
,
url
):
display_id
=
self
.
_match_id
(
url
)
nebula_token
=
self
.
_retrieve_nebula_auth
(
display_id
)
api_key
=
self
.
_retrieve_zype_api_key
(
url
,
display_id
)
response
=
self
.
_call_zype_api
(
'/videos'
,
{
'friendly_title'
:
display_id
},
...
...
@@ -174,7 +212,7 @@ def _real_extract(self, url):
video_meta
=
response
[
'response'
][
0
]
video_id
=
video_meta
[
'_id'
]
zype_access_token
=
self
.
_fetch_zype_access_token
(
display_id
,
nebula_token
=
nebula_token
)
zype_access_token
=
self
.
_fetch_zype_access_token
(
display_id
)
channel_title
=
self
.
_extract_channel_title
(
video_meta
)
...
...
@@ -187,13 +225,12 @@ def _real_extract(self, url):
'title'
:
video_meta
.
get
(
'title'
),
'description'
:
video_meta
.
get
(
'description'
),
'timestamp'
:
parse_iso8601
(
video_meta
.
get
(
'published_at'
)),
'thumbnails'
:
[
{
'id'
:
tn
.
get
(
'name'
),
# this appears to be null
'url'
:
tn
[
'url'
],
'width'
:
tn
.
get
(
'width'
),
'height'
:
tn
.
get
(
'height'
),
}
for
tn
in
video_meta
.
get
(
'thumbnails'
,
[])],
'thumbnails'
:
[{
'id'
:
tn
.
get
(
'name'
),
# this appears to be null
'url'
:
tn
[
'url'
],
'width'
:
tn
.
get
(
'width'
),
'height'
:
tn
.
get
(
'height'
),
}
for
tn
in
video_meta
.
get
(
'thumbnails'
,
[])],
'duration'
:
video_meta
.
get
(
'duration'
),
'channel'
:
channel_title
,
'uploader'
:
channel_title
,
# we chose uploader = channel name
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录