Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
CDNDrive
提交
7932d536
C
CDNDrive
项目概览
OpenDocCN
/
CDNDrive
通知
12
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
CDNDrive
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7932d536
编写于
3月 21, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改历史机制
上级
8a83946f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
31 addition
and
19 deletion
+31
-19
CDNDrive/__main__.py
CDNDrive/__main__.py
+12
-8
CDNDrive/drivers/CsdnApi.py
CDNDrive/drivers/CsdnApi.py
+1
-1
CDNDrive/drivers/__init__.py
CDNDrive/drivers/__init__.py
+3
-0
CDNDrive/encoders/__init__.py
CDNDrive/encoders/__init__.py
+1
-0
CDNDrive/util.py
CDNDrive/util.py
+14
-10
未找到文件。
CDNDrive/__main__.py
浏览文件 @
7932d536
...
...
@@ -117,7 +117,7 @@ def upload_handle(args):
return
log
(
f
"上传:
{
path
.
basename
(
file_name
)
}
(
{
size_string
(
path
.
getsize
(
file_name
))
}
)"
)
first_4mb_sha1
=
calc_sha1
(
read_in_chunk
(
file_name
,
size
=
4
*
1024
*
1024
,
cnt
=
1
))
history
=
read_history
()
history
=
read_history
(
args
.
site
)
if
first_4mb_sha1
in
history
:
url
=
history
[
first_4mb_sha1
][
'url'
]
log
(
f
"文件已于
{
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
history
[
first_4mb_sha1
][
'time'
]))
}
上传, 共有
{
len
(
history
[
first_4mb_sha1
][
'block'
])
}
个分块"
)
...
...
@@ -158,7 +158,7 @@ def upload_handle(args):
log
(
"元数据上传完毕"
)
log
(
f
"
{
meta_dict
[
'filename'
]
}
(
{
size_string
(
meta_dict
[
'size'
])
}
) 上传完毕, 用时
{
time
.
time
()
-
start_time
:.
1
f
}
秒, 平均速度
{
size_string
(
meta_dict
[
'size'
]
/
(
time
.
time
()
-
start_time
))
}
/s"
)
log
(
f
"META URL ->
{
api
.
real2meta
(
url
)
}
"
)
write_history
(
first_4mb_sha1
,
meta_dict
,
url
)
write_history
(
first_4mb_sha1
,
meta_dict
,
args
.
site
,
url
)
return
url
else
:
log
(
f
"元数据上传失败:
{
r
.
get
(
'message'
)
}
"
)
...
...
@@ -247,14 +247,18 @@ def info_handle(args):
log
(
"元数据解析失败"
)
def
history_handle
(
args
):
history
=
read_history
()
if
history
:
for
index
,
meta_dict
in
enumerate
(
history
.
values
()):
prefix
=
f
"[
{
index
+
1
}
]"
all_history
=
read_history
()
if
len
(
all_history
)
==
0
:
print
(
f
"暂无历史记录"
)
return
idx
=
0
for
site
,
history
in
all_history
.
items
():
for
meta_dict
in
history
.
values
():
prefix
=
f
"[
{
idx
+
1
}
]"
idx
+=
1
print
(
f
"
{
prefix
}
{
meta_dict
[
'filename'
]
}
(
{
size_string
(
meta_dict
[
'size'
])
}
), 共有
{
len
(
meta_dict
[
'block'
])
}
个分块, 上传于
{
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
meta_dict
[
'time'
]))
}
"
)
print
(
f
"
{
' '
*
len
(
prefix
)
}
META URL ->
{
api
.
real2meta
(
meta_dict
[
'url'
])
}
"
)
else
:
print
(
f
"暂无历史记录"
)
def
interact_mode
(
parser
,
subparsers
):
subparsers
.
add_parser
(
"help"
,
help
=
"show this help message"
).
set_defaults
(
func
=
lambda
_
:
parser
.
parse_args
([
"--help"
]).
func
())
...
...
CDNDrive/drivers/CsdnApi.py
浏览文件 @
7932d536
...
...
@@ -24,7 +24,7 @@ class CsdnApi:
self
.
cookies
=
load_cookies
(
'csdn'
)
def
meta2real
(
self
,
url
):
if
re
.
match
(
r
"^csdrive://
[
\d{17}$"
,
url
):
if
re
.
match
(
r
"^csdrive://\d{17}$"
,
url
):
return
self
.
default_url
(
self
.
extract_hash
(
url
))
else
:
return
None
...
...
CDNDrive/drivers/__init__.py
浏览文件 @
7932d536
from
.BiliApi
import
BiliApi
from
.BaijiaApi
import
BaijiaApi
from
.CsdnApi
import
CsdnApi
drivers
=
{
'bili'
:
BiliApi
(),
'baijia'
:
BaijiaApi
(),
'csdn'
:
CsdnApi
(),
}
prefixes
=
{
'bdrive'
:
'bili'
,
'bdex'
:
'bili'
,
'bjdrive'
:
'baijia'
,
'csdrive'
:
'csdn'
,
}
\ No newline at end of file
CDNDrive/encoders/__init__.py
浏览文件 @
7932d536
...
...
@@ -3,4 +3,5 @@ from .PngEncoder import PngEncoder
encoders
=
{
'bili'
:
PngEncoder
(),
'baijia'
:
PngEncoder
(),
'csdn'
:
PngEncoder
(),
}
\ No newline at end of file
CDNDrive/util.py
浏览文件 @
7932d536
...
...
@@ -46,18 +46,22 @@ def image_download(url):
return
b
""
.
join
(
content
)
def
read_history
():
try
:
with
open
(
path
.
join
(
bundle_dir
,
"history.json"
),
"r"
,
encoding
=
"utf-8"
)
as
f
:
history
=
json
.
loads
(
f
.
read
())
except
:
history
=
{}
return
history
def
read_history
(
site
=
None
):
fname
=
path
.
join
(
bundle_dir
,
"history.json"
)
if
not
path
.
exists
(
fname
):
return
{}
with
open
(
fname
,
encoding
=
"utf-8"
)
as
f
:
history
=
json
.
loads
(
f
.
read
())
if
not
site
:
return
history
else
:
return
history
.
get
(
site
,
{})
def
write_history
(
first_4mb_sha1
,
meta_dict
,
url
):
def
write_history
(
first_4mb_sha1
,
meta_dict
,
site
,
url
):
history
=
read_history
()
history
[
first_4mb_sha1
]
=
meta_dict
history
[
first_4mb_sha1
][
'url'
]
=
url
history
.
setdefault
(
site
,
{})
history
[
site
][
first_4mb_sha1
]
=
meta_dict
history
[
site
][
first_4mb_sha1
][
'url'
]
=
url
with
open
(
os
.
path
.
join
(
bundle_dir
,
"history.json"
),
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
json
.
dumps
(
history
,
ensure_ascii
=
False
,
indent
=
2
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录