Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
muziyicn
dr_py
提交
ecdcad64
dr_py
项目概览
muziyicn
/
dr_py
与 Fork 源项目一致
Fork自
晚风拂柳颜 / dr_py
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dr_py
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ecdcad64
编写于
9月 21, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新py的阿里
上级
da6b7104
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
417 addition
and
397 deletion
+417
-397
txt/py/py_ali.py
txt/py/py_ali.py
+417
-397
未找到文件。
txt/py/py_ali.py
浏览文件 @
ecdcad64
#coding=utf-8
#!/usr/bin/python
#
coding=utf-8
#
!/usr/bin/python
import
sys
sys
.
path
.
append
(
'..'
)
from
base.spider
import
Spider
import
json
...
...
@@ -8,81 +9,96 @@ import requests
import
time
import
re
class
Spider
(
Spider
):
# 元类 默认的元类 type
def
getName
(
self
):
return
"阿里云盘"
def
init
(
self
,
extend
=
""
):
def
init
(
self
,
extend
=
""
):
print
(
"============{0}============"
.
format
(
extend
))
pass
def
homeContent
(
self
,
filter
):
def
homeContent
(
self
,
filter
):
result
=
{}
return
result
def
homeVideoContent
(
self
):
result
=
{}
return
result
def
categoryContent
(
self
,
tid
,
pg
,
filter
,
extend
):
def
categoryContent
(
self
,
tid
,
pg
,
filter
,
extend
):
result
=
{}
return
result
def
searchContent
(
self
,
key
,
quick
):
def
searchContent
(
self
,
key
,
quick
):
result
=
{}
return
result
def
isVideoFormat
(
self
,
url
):
def
isVideoFormat
(
self
,
url
):
pass
def
manualVideoCheck
(
self
):
pass
def
playerContent
(
self
,
flag
,
id
,
vipFlags
):
erro
=
0
def
playerContent
(
self
,
flag
,
id
,
vipFlags
):
if
flag
==
'AliYun'
:
return
self
.
originContent
(
flag
,
id
,
vipFlags
)
return
self
.
originContent
(
flag
,
id
,
vipFlags
)
elif
flag
==
'AliYun原画'
:
return
self
.
fhdContent
(
flag
,
id
,
vipFlags
)
return
self
.
fhdContent
(
flag
,
id
,
vipFlags
)
else
:
return
{}
def
fhdContent
(
self
,
flag
,
id
,
vipFlags
):
def
fhdContent
(
self
,
flag
,
id
,
vipFlags
):
self
.
login
()
if
self
.
erro
!=
1
:
ids
=
id
.
split
(
'+'
)
shareId
=
ids
[
0
]
shareToken
=
ids
[
1
]
fileId
=
ids
[
2
]
category
=
ids
[
3
]
url
=
self
.
getDownloadUrl
(
shareId
,
shareToken
,
fileId
,
category
)
url
=
self
.
getDownloadUrl
(
shareId
,
shareToken
,
fileId
,
category
)
print
(
url
)
noRsp
=
requests
.
get
(
url
,
headers
=
self
.
header
,
allow_redirects
=
False
,
verify
=
False
)
noRsp
=
requests
.
get
(
url
,
headers
=
self
.
header
,
allow_redirects
=
False
,
verify
=
False
)
realUrl
=
''
if
'Location'
in
noRsp
.
headers
:
realUrl
=
noRsp
.
headers
[
'Location'
]
if
'location'
in
noRsp
.
headers
and
len
(
realUrl
)
==
0
:
if
'location'
in
noRsp
.
headers
and
len
(
realUrl
)
==
0
:
realUrl
=
noRsp
.
headers
[
'location'
]
else
:
realUrl
=
''
newHeader
=
{
"user-agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"
,
"referer"
:
"https://www.aliyundrive.com/"
,
"user-agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"
,
"referer"
:
"https://www.aliyundrive.com/"
,
}
result
=
{
'parse'
:
'0'
,
'playUrl'
:
''
,
'url'
:
realUrl
,
'header'
:
newHeader
'parse'
:
'0'
,
'playUrl'
:
''
,
'url'
:
realUrl
,
'header'
:
newHeader
}
return
result
def
originContent
(
self
,
flag
,
id
,
vipFlags
):
def
originContent
(
self
,
flag
,
id
,
vipFlags
):
self
.
login
()
if
self
.
erro
!=
1
:
ids
=
id
.
split
(
'+'
)
shareId
=
ids
[
0
]
shareToken
=
ids
[
1
]
fileId
=
ids
[
2
]
url
=
'{0}?do=push_agent&api=python&type=m3u8&share_id={1}&file_id={2}'
.
format
(
self
.
localProxyUrl
,
shareId
,
fileId
)
url
=
'{0}?do=push_agent&api=python&type=m3u8&share_id={1}&file_id={2}'
.
format
(
self
.
localProxyUrl
,
shareId
,
fileId
)
else
:
url
=
''
result
=
{
'parse'
:
'0'
,
'playUrl'
:
''
,
'url'
:
url
,
'header'
:
''
'parse'
:
'0'
,
'playUrl'
:
''
,
'url'
:
url
,
'header'
:
''
}
# shareToken = self.getToken(shareId,'')
# self.getMediaSlice(shareId,shareToken,fileId)
# map = {
# 'share_id':'p1GJYEqgeb2',
# 'file_id':'62ed1b95b1048d60ffc246669f5e0999e90b8c2f',
...
...
@@ -93,7 +109,7 @@ class Spider(Spider): # 元类 默认的元类 type
return
result
def
detailContent
(
self
,
array
):
def
detailContent
(
self
,
array
):
tid
=
array
[
0
]
# shareId = self.regStr(href,'www.aliyundrive.com\\/s\\/([^\\/]+)(\\/folder\\/([^\\/]+))?')
# todo =========================================================================================
...
...
@@ -104,14 +120,14 @@ class Spider(Spider): # 元类 默认的元类 type
infoUrl
=
'https://api.aliyundrive.com/adrive/v3/share_link/get_share_by_anonymous'
infoForm
=
{
'share_id'
:
shareId
}
infoRsp
=
requests
.
post
(
infoUrl
,
json
=
infoForm
,
headers
=
self
.
header
)
infoForm
=
{
'share_id'
:
shareId
}
infoRsp
=
requests
.
post
(
infoUrl
,
json
=
infoForm
,
headers
=
self
.
header
)
infoJo
=
json
.
loads
(
infoRsp
.
text
)
infoJa
=
[]
if
'file_infos'
in
infoJo
:
infoJa
=
infoJo
[
'file_infos'
]
if
len
(
infoJa
)
<=
0
:
if
len
(
infoJa
)
<=
0
:
return
''
fileInfo
=
{}
# todo
...
...
@@ -121,11 +137,11 @@ class Spider(Spider): # 元类 默认的元类 type
fileId
=
fileInfo
[
'file_id'
]
vodList
=
{
'vod_id'
:
tid
,
'vod_name'
:
infoJo
[
'share_name'
],
'vod_pic'
:
infoJo
[
'avatar'
],
'vod_content'
:
tid
,
'vod_play_from'
:
'AliYun$$$AliYun原画'
'vod_id'
:
tid
,
'vod_name'
:
infoJo
[
'share_name'
],
'vod_pic'
:
infoJo
[
'avatar'
],
'vod_content'
:
tid
,
'vod_play_from'
:
'AliYun$$$AliYun原画'
}
fileType
=
fileInfo
[
'type'
]
if
fileType
!=
'folder'
:
...
...
@@ -133,22 +149,22 @@ class Spider(Spider): # 元类 默认的元类 type
return
''
fileId
=
'root'
shareToken
=
self
.
getToken
(
shareId
,
''
)
shareToken
=
self
.
getToken
(
shareId
,
''
)
hashMap
=
{}
self
.
listFiles
(
hashMap
,
shareId
,
shareToken
,
fileId
)
self
.
listFiles
(
hashMap
,
shareId
,
shareToken
,
fileId
)
sortedMap
=
sorted
(
hashMap
.
items
(),
key
=
lambda
x
:
x
[
0
])
arrayList
=
[]
playList
=
[]
for
sm
in
sortedMap
:
arrayList
.
append
(
sm
[
0
]
+
'$'
+
sm
[
1
])
arrayList
.
append
(
sm
[
0
]
+
'$'
+
sm
[
1
])
playList
.
append
(
'#'
.
join
(
arrayList
))
playList
.
append
(
'#'
.
join
(
arrayList
))
vodList
[
'vod_play_url'
]
=
'$$$'
.
join
(
playList
)
result
=
{
'list'
:
[
vodList
]
'list'
:
[
vodList
]
}
return
result
...
...
@@ -160,19 +176,19 @@ class Spider(Spider): # 元类 默认的元类 type
expiresMap
=
{}
localMedia
=
{}
header
=
{
"Referer"
:
"https://www.aliyundrive.com/"
,
"User-Agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"
"Referer"
:
"https://www.aliyundrive.com/"
,
"User-Agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36"
}
localProxyUrl
=
'http://127.0.0.1:UndCover/proxy'
def
redirectResponse
(
tUrl
):
rsp
=
requests
.
get
(
tUrl
,
allow_redirects
=
False
,
verify
=
False
)
rsp
=
requests
.
get
(
tUrl
,
allow_redirects
=
False
,
verify
=
False
)
if
'Location'
in
rsp
.
headers
:
return
redirectResponse
(
rsp
.
headers
[
'Location'
])
else
:
return
rsp
def
getDownloadUrl
(
self
,
shareId
,
token
,
fileId
,
category
):
def
getDownloadUrl
(
self
,
shareId
,
token
,
fileId
,
category
):
lShareId
=
shareId
lFileId
=
fileId
params
=
{
...
...
@@ -186,7 +202,7 @@ class Spider(Spider): # 元类 默认的元类 type
customHeader
[
'authorization'
]
=
self
.
authorization
url
=
'https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info'
if
category
==
'video'
:
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
customHeader
)
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
customHeader
)
rspJo
=
json
.
loads
(
rsp
.
text
)
lShareId
=
rspJo
[
'share_id'
]
lFileId
=
rspJo
[
'file_id'
]
...
...
@@ -202,11 +218,11 @@ class Spider(Spider): # 元类 默认的元类 type
jo
[
'file_id'
]
=
lFileId
jo
[
'get_audio_play_info'
]
=
True
downloadUrl
=
'https://api.aliyundrive.com/v2/file/get_share_link_download_url'
downloadRsp
=
requests
.
post
(
downloadUrl
,
json
=
jo
,
headers
=
customHeader
)
downloadRsp
=
requests
.
post
(
downloadUrl
,
json
=
jo
,
headers
=
customHeader
)
resultJo
=
json
.
loads
(
downloadRsp
.
text
)
return
resultJo
[
'download_url'
]
def
getMediaSlice
(
self
,
shareId
,
token
,
fileId
):
def
getMediaSlice
(
self
,
shareId
,
token
,
fileId
):
params
=
{
"share_id"
:
shareId
,
"category"
:
"live_transcoding"
,
...
...
@@ -218,29 +234,29 @@ class Spider(Spider): # 元类 默认的元类 type
customHeader
[
'authorization'
]
=
self
.
authorization
url
=
'https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info'
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
customHeader
)
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
customHeader
)
rspJo
=
json
.
loads
(
rsp
.
text
)
quality
=
[
'FHD'
,
'HD'
,
'SD'
]
quality
=
[
'FHD'
,
'HD'
,
'SD'
]
videoList
=
rspJo
[
'video_preview_play_info'
][
'live_transcoding_task_list'
]
highUrl
=
''
for
q
in
quality
:
if
len
(
highUrl
)
>
0
:
break
for
video
in
videoList
:
if
(
video
[
'template_id'
]
==
q
):
if
(
video
[
'template_id'
]
==
q
):
highUrl
=
video
[
'url'
]
break
if
len
(
highUrl
)
==
0
:
highUrl
=
videoList
[
0
][
'url'
]
noRsp
=
requests
.
get
(
highUrl
,
headers
=
self
.
header
,
allow_redirects
=
False
,
verify
=
False
)
noRsp
=
requests
.
get
(
highUrl
,
headers
=
self
.
header
,
allow_redirects
=
False
,
verify
=
False
)
m3u8Url
=
''
if
'Location'
in
noRsp
.
headers
:
m3u8Url
=
noRsp
.
headers
[
'Location'
]
if
'location'
in
noRsp
.
headers
and
len
(
m3u8Url
)
==
0
:
if
'location'
in
noRsp
.
headers
and
len
(
m3u8Url
)
==
0
:
m3u8Url
=
noRsp
.
headers
[
'location'
]
m3u8Rsp
=
requests
.
get
(
m3u8Url
,
headers
=
self
.
header
)
m3u8Rsp
=
requests
.
get
(
m3u8Url
,
headers
=
self
.
header
)
m3u8Content
=
m3u8Rsp
.
text
tmpArray
=
m3u8Url
.
split
(
'/'
)[
0
:
-
1
]
...
...
@@ -254,20 +270,21 @@ class Spider(Spider): # 元类 默认的元类 type
tmpSlice
=
slice
if
'x-oss-expires'
in
tmpSlice
:
count
=
count
+
1
mediaMap
[
str
(
count
)]
=
host
+
tmpSlice
mediaMap
[
str
(
count
)]
=
host
+
tmpSlice
tmpSlice
=
"{0}?do=push_agent&api=python&type=media&share_id={1}&file_id={2}&media_id={3}"
.
format
(
self
.
localProxyUrl
,
shareId
,
fileId
,
count
)
tmpSlice
=
"{0}?do=push_agent&api=python&type=media&share_id={1}&file_id={2}&media_id={3}"
.
format
(
self
.
localProxyUrl
,
shareId
,
fileId
,
count
)
m3u8List
.
append
(
tmpSlice
)
self
.
localMedia
[
fileId
]
=
mediaMap
return
'
\n
'
.
join
(
m3u8List
)
def
proxyMedia
(
self
,
map
):
def
proxyMedia
(
self
,
map
):
shareId
=
map
[
'share_id'
]
fileId
=
map
[
'file_id'
]
mediaId
=
map
[
'media_id'
]
shareToken
=
self
.
getToken
(
shareId
,
''
)
shareToken
=
self
.
getToken
(
shareId
,
''
)
refresh
=
False
url
=
''
...
...
@@ -277,7 +294,7 @@ class Spider(Spider): # 元类 默认的元类 type
if
mediaId
in
fileMap
:
url
=
fileMap
[
mediaId
]
if
len
(
url
)
>
0
:
ts
=
int
(
self
.
regStr
(
url
,
"x-oss-expires=(
\\
d+)&"
))
ts
=
int
(
self
.
regStr
(
url
,
"x-oss-expires=(
\\
d+)&"
))
# url = self.localMedia[fileId][mediaId]
...
...
@@ -286,37 +303,37 @@ class Spider(Spider): # 元类 默认的元类 type
self
.
localTime
=
int
(
time
.
time
())
if
ts
-
self
.
localTime
<=
60
:
self
.
getMediaSlice
(
shareId
,
shareToken
,
fileId
)
self
.
getMediaSlice
(
shareId
,
shareToken
,
fileId
)
url
=
self
.
localMedia
[
fileId
][
mediaId
]
action
=
{
'url'
:
url
,
'header'
:
self
.
header
,
'param'
:
''
,
'type'
:
'stream'
,
'after'
:
''
'url'
:
url
,
'header'
:
self
.
header
,
'param'
:
''
,
'type'
:
'stream'
,
'after'
:
''
}
print
(
action
)
return
[
200
,
"video/MP2T"
,
action
,
""
]
def
proxyM3U8
(
self
,
map
):
def
proxyM3U8
(
self
,
map
):
shareId
=
map
[
'share_id'
]
fileId
=
map
[
'file_id'
]
shareToken
=
self
.
getToken
(
shareId
,
''
)
content
=
self
.
getMediaSlice
(
shareId
,
shareToken
,
fileId
)
shareToken
=
self
.
getToken
(
shareId
,
''
)
content
=
self
.
getMediaSlice
(
shareId
,
shareToken
,
fileId
)
action
=
{
'url'
:
''
,
'header'
:
''
,
'param'
:
''
,
'type'
:
'string'
,
'after'
:
''
'url'
:
''
,
'header'
:
''
,
'param'
:
''
,
'type'
:
'string'
,
'after'
:
''
}
return
[
200
,
"application/octet-stream"
,
action
,
content
]
def
localProxy
(
self
,
param
):
def
localProxy
(
self
,
param
):
typ
=
param
[
'type'
]
if
typ
==
"m3u8"
:
return
self
.
proxyM3U8
(
param
)
...
...
@@ -324,7 +341,7 @@ class Spider(Spider): # 元类 默认的元类 type
return
self
.
proxyMedia
(
param
)
return
None
def
getToken
(
self
,
shareId
,
sharePwd
):
def
getToken
(
self
,
shareId
,
sharePwd
):
self
.
localTime
=
int
(
time
.
time
())
shareToken
=
''
if
shareId
in
self
.
shareTokenMap
:
...
...
@@ -334,11 +351,11 @@ class Spider(Spider): # 元类 默认的元类 type
if
len
(
shareToken
)
>
0
and
expire
-
self
.
localTime
>
600
:
return
shareToken
params
=
{
'share_id'
:
shareId
,
'share_pwd'
:
sharePwd
'share_id'
:
shareId
,
'share_pwd'
:
sharePwd
}
url
=
'https://api.aliyundrive.com/v2/share_link/get_share_token'
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
self
.
header
)
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
self
.
header
)
jo
=
json
.
loads
(
rsp
.
text
)
newShareToken
=
jo
[
'share_token'
]
self
.
expiresMap
[
shareId
]
=
self
.
localTime
+
int
(
jo
[
'expires_in'
])
...
...
@@ -349,27 +366,27 @@ class Spider(Spider): # 元类 默认的元类 type
return
newShareToken
def
listFiles
(
self
,
map
,
shareId
,
shareToken
,
fileId
):
def
listFiles
(
self
,
map
,
shareId
,
shareToken
,
fileId
):
url
=
'https://api.aliyundrive.com/adrive/v3/file/list'
newHeader
=
self
.
header
.
copy
()
newHeader
[
'x-share-token'
]
=
shareToken
params
=
{
'image_thumbnail_process'
:
'image/resize,w_160/format,jpeg'
,
'image_url_process'
:
'image/resize,w_1920/format,jpeg'
,
'limit'
:
200
,
'order_by'
:
'updated_at'
,
'order_direction'
:
'DESC'
,
'parent_file_id'
:
fileId
,
'share_id'
:
shareId
,
'video_thumbnail_process'
:
'video/snapshot,t_1000,f_jpg,ar_auto,w_300'
'image_thumbnail_process'
:
'image/resize,w_160/format,jpeg'
,
'image_url_process'
:
'image/resize,w_1920/format,jpeg'
,
'limit'
:
200
,
'order_by'
:
'updated_at'
,
'order_direction'
:
'DESC'
,
'parent_file_id'
:
fileId
,
'share_id'
:
shareId
,
'video_thumbnail_process'
:
'video/snapshot,t_1000,f_jpg,ar_auto,w_300'
}
maker
=
''
arrayList
=
[]
for
i
in
range
(
1
,
51
):
for
i
in
range
(
1
,
51
):
if
i
>=
2
and
len
(
maker
)
==
0
:
break
params
[
'marker'
]
=
maker
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
newHeader
)
rsp
=
requests
.
post
(
url
,
json
=
params
,
headers
=
newHeader
)
jo
=
json
.
loads
(
rsp
.
text
)
ja
=
jo
[
'items'
]
for
jt
in
ja
:
...
...
@@ -384,20 +401,23 @@ class Spider(Spider): # 元类 默认的元类 type
i
=
i
+
1
for
item
in
arrayList
:
self
.
listFiles
(
map
,
shareId
,
shareToken
,
item
)
self
.
listFiles
(
map
,
shareId
,
shareToken
,
item
)
def
login
(
self
):
self
.
localTime
=
int
(
time
.
time
())
url
=
'https://api.aliyundrive.com/token/refresh'
if
len
(
self
.
authorization
)
==
0
or
self
.
timeoutTick
-
self
.
localTime
<=
600
:
form
=
{
'refresh_token'
:
'4acb3ad2f2254ba1b566279f7cd98ba3
'
'refresh_token'
:
'59744816075f4729bc00cd23b98e3447
'
}
rsp
=
requests
.
post
(
url
,
json
=
form
,
headers
=
self
.
header
)
rsp
=
requests
.
post
(
url
,
json
=
form
,
headers
=
self
.
header
)
if
rsp
.
status_code
==
200
:
jo
=
json
.
loads
(
rsp
.
text
)
self
.
authorization
=
jo
[
'token_type'
]
+
' '
+
jo
[
'access_token'
]
self
.
expiresIn
=
int
(
jo
[
'expires_in'
])
self
.
timeoutTick
=
self
.
localTime
+
self
.
expiresIn
else
:
self
.
erro
=
1
# print(self.authorization)
# print(self.timeoutTick)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录