Skip to content

Commit

Permalink
v3.9.3
Browse files Browse the repository at this point in the history
取消秒传转存
优化上传
  • Loading branch information
qjfoidnh committed Aug 26, 2023
1 parent 6950b33 commit 9e9a7fe
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 192 deletions.
169 changes: 76 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
* [输出工作目录](#输出工作目录)
* [列出目录](#列出目录)
* [列出目录树形图](#列出目录树形图)
* [获取文件/目录的元信息](#获取文件目录的元信息)
* [获取文件/目录的元信息](#获取文件/目录的元信息)
* [搜索文件](#搜索文件)
* [下载文件/目录](#下载文件目录)
* [上传文件/目录](#上传文件目录)
* [下载文件/目录](#下载文件/目录)
* [上传文件/目录](#上传文件/目录)
* [获取下载直链](#获取下载直链)
* [手动秒传文件](#手动秒传文件)
* [修复文件MD5](#修复文件MD5)
* [获取本地文件的秒传信息](#获取本地文件的秒传信息)
* [导出文件/目录](#导出文件目录)
* [创建目录](#创建目录)
* [删除文件/目录](#删除文件目录)
* [拷贝文件/目录](#拷贝文件目录)
* [移动/重命名文件/目录](#移动重命名文件目录)
* [转存文件/目录](#转存文件目录)
* [分享文件/目录](#分享文件目录)
+ [设置分享文件/目录](#设置分享文件目录)
+ [列出已分享文件/目录](#列出已分享文件目录)
+ [取消分享文件/目录](#取消分享文件目录)
* [删除文件/目录](#删除文件/目录)
* [拷贝文件/目录](#拷贝文件/目录)
* [移动/重命名文件/目录](#移动/重命名文件/目录)
* [转存文件/目录](#转存文件/目录)
* [分享文件/目录](#分享文件/目录)
+ [设置分享文件/目录](#设置分享文件/目录)
+ [列出已分享文件/目录](#列出已分享文件/目录)
+ [取消分享文件/目录](#取消分享文件/目录)
* [离线下载](#离线下载)
+ [添加离线下载任务](#添加离线下载任务)
+ [精确查询离线下载任务](#精确查询离线下载任务)
Expand All @@ -62,7 +59,7 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
* [回收站](#回收站)
+ [列出回收站文件列表](#列出回收站文件列表)
+ [还原回收站文件或目录](#还原回收站文件或目录)
+ [删除回收站文件或目录/清空回收站](#删除回收站文件或目录清空回收站)
+ [删除回收站文件或目录/清空回收站](#删除回收站文件或目录/清空回收站)
* [显示和修改程序配置项](#显示和修改程序配置项)
* [测试通配符](#测试通配符)
* [工具箱](#工具箱)
Expand Down Expand Up @@ -93,13 +90,18 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co

[上传](#上传文件目录)本地文件, 支持上传大文件(>2GB), 支持多个文件或目录上传;

[转存](#转存文件目录)其他用户分享的文件, 支持公开、带密码的分享链接, 支持常见的几种秒传链接;
[转存](#转存文件目录)其他用户分享的文件, 支持带密码的分享链接;

[导出](#导出文件目录)网盘内的文件秒传链接, 可选导出BaiduPCS-Go原生格式或通用格式;
[comment]: <> ([导出]&#40;#导出文件目录&#41;网盘内的文件秒传链接, 可选导出BaiduPCS-Go原生格式或通用格式;)

[离线下载](#离线下载), 支持http/https/ftp/电驴/磁力链协议.

# 版本更新
**2023.08.26** v3.9.3
- 因官方接口从原理层面封禁秒传, 取消秒传转存功能
- 更新部分使用说明
- 建议使用文件上传功能的用户更新此版本

**2023.06.03** v3.9.2
- 修复秒传链接无法转存, 因官方接口变动秒传已不再支持短链接格式
- 修复上传文件无法使用秒传
Expand Down Expand Up @@ -269,11 +271,6 @@ cli交互模式下, 光标所在行的前缀应为 `BaiduPCS-Go >`, 如果登录

## 安装

[Homebrew](https://brew.sh/) 用户可以用下面的命令行安装应用:

```sh
brew install baidupcs-go
```

## Windows

Expand Down Expand Up @@ -321,6 +318,7 @@ BaiduPCS-Go update
### 常规登录百度帐号

支持在线验证绑定的手机号或邮箱,
注: 此方式已长期不维护, 建议使用其他登录方式
```
BaiduPCS-Go login
```
Expand Down Expand Up @@ -555,14 +553,6 @@ BaiduPCS-Go d <网盘文件或目录的路径1> <文件或目录2> <文件或目
自动跳过下载重名的文件!


#### 下载模式说明

* pcs: 通过百度网盘的 PCS API 下载(不建议使用)

* stream: 通过百度网盘的 PCS API, 以流式文件的方式下载, 效果同 pcs(不建议使用)

* locate: 默认的下载模式。从百度网盘 Android 客户端, 获取下载链接的方式来下载

#### 例子
```
# 设置保存目录, 保存到 D:\Downloads
Expand Down Expand Up @@ -631,26 +621,6 @@ BaiduPCS-Go locate <文件1> <文件2> ...
BaiduPCS-Go config set -user_agent "netdisk;2.2.51.6;netdisk;10.0.63;PC;android-android"
```

## 手动秒传文件
```
BaiduPCS-Go rapidupload -length=<文件的大小> -md5=<文件的md5值> -slicemd5=<文件前256KB切片的md5值(可选)> -crc32=<文件的crc32值(可选)> <保存的网盘路径, 需包含文件名>
BaiduPCS-Go ru -length=<文件的大小> -md5=<文件的md5值> -slicemd5=<文件前256KB切片的md5值(可选)> -crc32=<文件的crc32值(可选)> <保存的网盘路径, 需包含文件名>
```

注意: 使用此功能秒传文件, 前提是知道文件的大小, md5, 前256KB切片的 md5 (可选), crc32 (可选), 且百度网盘中存在一模一样的文件.

上传的文件将会保存到网盘的目标目录.

遇到同名文件将会自动覆盖!

可能无法秒传 20GB 以上的文件!!

#### 例子:
```
# 如果秒传成功, 则保存到网盘路径 /test
BaiduPCS-Go rapidupload -length=56276137 -md5=fbe082d80e90f90f0fb1f94adbbcfa7f -slicemd5=38c6a75b0ec4499271d4ea38a667ab61 -crc32=314332359 /test
```


## 修复文件MD5
```
Expand All @@ -677,52 +647,71 @@ BaiduPCS-Go fixmd5 <文件1> <文件2> <文件3> ...
BaiduPCS-Go fixmd5 /我的资源/1.mp4
```

## 获取本地文件的秒传信息
```
BaiduPCS-Go sumfile <本地文件的路径>
BaiduPCS-Go sf <本地文件的路径>
```
[comment]: <> (## 获取本地文件的秒传信息)

获取本地文件的大小, md5, 前256KB切片的 md5, crc32, 可用于秒传文件.
[comment]: <> (```)

#### 例子:
```
# 获取 C:\Users\Administrator\Desktop\1.mp4 的秒传信息
BaiduPCS-Go sumfile C:/Users/Administrator/Desktop/1.mp4
```
[comment]: <> (BaiduPCS-Go sumfile <本地文件的路径>)

## 导出文件/目录
```
BaiduPCS-Go export <文件/目录1> <文件/目录2> ...
BaiduPCS-Go ep <文件/目录1> <文件/目录2> ...
```
[comment]: <> (BaiduPCS-Go sf <本地文件的路径>)

导出网盘内的文件或目录, 原理为秒传文件, 此操作会生成导出文件或目录的命令.
[comment]: <> (```)

#### 注意
[comment]: <> (获取本地文件的大小, md5, 前256KB切片的 md5, crc32, 可用于秒传文件.)

**无法导出 20GB 以上的文件!!**
[comment]: <> (#### 例子:)

**无法导出文件的版本历史等数据!!**
[comment]: <> (```)

**以通用秒传格式导出会丢失文件路径信息!!**
[comment]: <> (# 获取 C:\Users\Administrator\Desktop\1.mp4 的秒传信息)

并不是所有的文件都能导出成功, 程序会列出无法导出的文件列表
[comment]: <> (BaiduPCS-Go sumfile C:/Users/Administrator/Desktop/1.mp4)

#### 例子:
```
# 导出当前工作目录:
BaiduPCS-Go export
[comment]: <> (```)

# 导出所有文件和目录, 并设置新的根目录为 /root
BaiduPCS-Go export -root=/root /
[comment]: <> (## 导出文件/目录)

# 导出 /我的资源
BaiduPCS-Go export /我的资源
[comment]: <> (```)

# 导出 /我的资源 格式为通用秒传链接格式
BaiduPCS-Go export /我的资源 --link
```
[comment]: <> (BaiduPCS-Go export <文件/目录1> <文件/目录2> ...)

[comment]: <> (BaiduPCS-Go ep <文件/目录1> <文件/目录2> ...)

[comment]: <> (```)

[comment]: <> (导出网盘内的文件或目录, 原理为秒传文件, 此操作会生成导出文件或目录的命令.)

[comment]: <> (#### 注意)

[comment]: <> (**无法导出 20GB 以上的文件!!**)

[comment]: <> (**无法导出文件的版本历史等数据!!**)

[comment]: <> (**以通用秒传格式导出会丢失文件路径信息!!**)

[comment]: <> (并不是所有的文件都能导出成功, 程序会列出无法导出的文件列表)

[comment]: <> (#### 例子:)

[comment]: <> (```)

[comment]: <> (# 导出当前工作目录:)

[comment]: <> (BaiduPCS-Go export)

[comment]: <> (# 导出所有文件和目录, 并设置新的根目录为 /root)

[comment]: <> (BaiduPCS-Go export -root=/root /)

[comment]: <> (# 导出 /我的资源)

[comment]: <> (BaiduPCS-Go export /我的资源)

[comment]: <> (# 导出 /我的资源 格式为通用秒传链接格式)

[comment]: <> (BaiduPCS-Go export /我的资源 --link)

[comment]: <> (```)

## 创建目录
```
Expand Down Expand Up @@ -798,21 +787,15 @@ BaiduPCS-Go mv /我的资源/1.mp4 /我的资源/3.mp4
```
# 转存分享链接里的文件到当前目录:
BaiduPCS-Go transfer <分享链接> <提取码>
# 转存通用秒传链接里的文件到当前目录:
BaiduPCS-Go transfer <秒传链接>
```

注意: 公开分享链接不需输入提取码, 支持多个文件/目录; 只支持包含单个文件的秒传链接.

转存文件保存到当前工作目录下, 不支持指定.
注意: 转存文件保存到当前工作目录下, 不支持指定.

#### 例子
```
# 将 https://pan.baidu.com/s/12L_ZZVNxz5f_2CccoyyVrW (提取码edv4) 转存到当前目录
BaiduPCS-Go transfer https://pan.baidu.com/s/12L_ZZVNxz5f_2CccoyyVrW edv4
# 将 E7E7B8613854379642F70230B179F37A#FA690D0AB7C8BC6A62WD1B6B3FC5248F#128859362#test.7z 转存到当前目录
BaiduPCS-Go transfer E7E7B8613854379642F70230B179F37A#FA690D0AB7C8BC6A62WD1B6B3FC5248F#128859362#test.7z
BaiduPCS-Go transfer https://pan.baidu.com/s/12L_ZZVNxz5f_2CccoyyVrW?pwd=edv4
```

## 分享文件/目录
Expand Down Expand Up @@ -998,8 +981,8 @@ BaiduPCS-Go config set -h
# 设置下载文件的储存目录
BaiduPCS-Go config set -savedir D:/Downloads
# 设置下载最大并发量为 150
BaiduPCS-Go config set -max_parallel 150
# 设置下载最大并发量为 15
BaiduPCS-Go config set -max_parallel 15
# 组合设置
BaiduPCS-Go config set -max_parallel 150 -savedir D:/Downloads
Expand Down
8 changes: 4 additions & 4 deletions baidupcs/pcserror/xpanerrorinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func (pane *XPanErrorInfo) Error() string {
func FindXPanErr(errno, returnType int) (errmsg string) {
switch errno {
case 0:
if returnType != 2 {
return "未匹配到符合文件"
if returnType == 2 {
return StrSuccess
}
return StrSuccess
return fmt.Sprintf("错误类型: %d", returnType)
default:
return "未知错误"
return fmt.Sprintf("错误类型: %d", returnType)
}
}
18 changes: 13 additions & 5 deletions baidupcs/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"unsafe"
Expand Down Expand Up @@ -317,17 +318,24 @@ func (pcs *BaiduPCS) prepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32
}

// prepareRapidUploadV2 秒传文件接口2, 不进行文件夹检查
func (pcs *BaiduPCS) prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
func (pcs *BaiduPCS) prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, dataContent, crc32 string, offset, length, totalSize, dataTime int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcsURL := pcs.generatePanURL("precreate", nil)
post := map[string]string{
"path": targetPath,
"size": strconv.FormatInt(length, 10),
"target_path": path.Dir(targetPath) + "/",
"size": strconv.FormatInt(totalSize, 10),
"data_offset": strconv.FormatInt(offset, 10),
"isdir": "0",
"local_mtime": strconv.FormatInt(dataTime, 10),
"local_ctime": strconv.FormatInt(dataTime, 10),
"rtype": "2",
"checkexist": "0",
"autoinit": "1",
"content-md5": contentMD5,
"slice-md5": sliceMD5,
"data_time": strconv.FormatInt(dataTime, 10),
"data_length": strconv.FormatInt(length, 10),
"data_content": dataContent,
"block_list": mergeStringList(contentMD5),
"mode": "1",
}
Expand All @@ -353,13 +361,13 @@ func (pcs *BaiduPCS) PrepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32
}

// PrepareRapidUploadV2 秒传文件新接口, 只返回服务器响应数据和错误信息
func (pcs *BaiduPCS) PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
func (pcs *BaiduPCS) PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5, dataContent, crc32 string, offset, length, totalSize, dataTime int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
pcs.lazyInit()
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", length)
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", totalSize)
if pcsError != nil {
return nil, pcsError
}
return pcs.prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, "", length)
return pcs.prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, dataContent, crc32, offset, length, totalSize, dataTime)
}

// PrepareLocateDownload 获取下载链接, 只返回服务器响应数据和错误信息
Expand Down
11 changes: 4 additions & 7 deletions baidupcs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,14 @@ func randomifyMD5(md5 string) string {
}

// RapidUpload 秒传文件
func (pcs *BaiduPCS) RapidUpload(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (pcsError pcserror.Error) {
func (pcs *BaiduPCS) RapidUpload(targetPath, contentMD5, sliceMD5, dataContent, crc32 string, offset, length, totalSize, dataTime int64) (pcsError pcserror.Error) {
defer func() {
if pcsError == nil {
// 更新缓存
pcs.deleteCache([]string{path.Dir(targetPath)})
}
}()
pcsError = pcs.rapidUploadV2(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), length)
if pcsError != nil {
pcsError = pcs.rapidUpload(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), "", length)
}
pcsError = pcs.rapidUploadV2(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), dataContent, crc32, offset, length, totalSize, dataTime)
return
}

Expand All @@ -132,8 +129,8 @@ func (pcs *BaiduPCS) rapidUpload(targetPath, contentMD5, sliceMD5, crc32 string,
return pcserror.DecodePanJSONError(OperationRapidUpload, dataReadCloser)
}

func (pcs *BaiduPCS) rapidUploadV2(targetPath, contentMD5, sliceMD5 string, length int64) (pcsError pcserror.Error) {
dataReadCloser, pcsError := pcs.PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5, length)
func (pcs *BaiduPCS) rapidUploadV2(targetPath, contentMD5, sliceMD5, dataContent, crc32 string, offset, length, totalSize, dataTime int64) (pcsError pcserror.Error) {
dataReadCloser, pcsError := pcs.PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5, dataContent, crc32, offset, length, totalSize, dataTime)
if pcsError != nil {
return
}
Expand Down
Loading

0 comments on commit 9e9a7fe

Please sign in to comment.