Skip to content

Commit

Permalink
支持2gb以上的文件上传了
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Jul 20, 2018
1 parent 33e7312 commit 2ba6ac7
Show file tree
Hide file tree
Showing 33 changed files with 1,456 additions and 426 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/GangZhuo/BaiduPCS)

## 注意

此文档只针对于最新的commit, 可能不适用于已发布的最新版本.

<!-- toc -->
## 目录

- [特色](#特色)
- [编译/交叉编译 说明](#编译交叉编译-说明)
Expand Down Expand Up @@ -74,9 +79,9 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang

通配符匹配网盘路径和 Tab 自动补齐命令和路径, [通配符_百度百科](https://baike.baidu.com/item/通配符);

[下载](#下载文件或目录)网盘内文件, 支持多个文件或目录下载, 支持断点续传和单文件并行下载;
[下载](#下载文件目录)网盘内文件, 支持多个文件或目录下载, 支持断点续传和单文件并行下载;

[上传](#上传文件或目录)2GB以内的文件, 支持多个文件或目录上传;
[上传](#上传文件目录)2GB以内的文件, 支持多个文件或目录上传;

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

Expand Down Expand Up @@ -375,6 +380,13 @@ BaiduPCS-Go upload C:/Users/Administrator/Desktop /视频
BaiduPCS-Go locate <文件1> <文件2> ...
```

#### 注意

若该功能无法正常使用, 提示`user is not authorized, hitcode:101`, 尝试更换 User-Agent 为 `netdisk`:
```
BaiduPCS-Go config set -user_agent "netdisk"
```

## 手动秒传文件
```
BaiduPCS-Go rapidupload -length=<文件的大小> -md5=<文件的md5值> -slicemd5=<文件前256KB切片的md5值(可选)> -crc32=<文件的crc32值(可选)> <保存的网盘路径, 需包含文件名>
Expand Down Expand Up @@ -717,6 +729,10 @@ cli交互模式下, 运行命令 `config set -max_parallel 250` 将下载最大

运行命令 `quit``exit` 或 组合键 `Ctrl+C` 或 组合键 `Ctrl+D`

# 已知问题

* 分片上传文件时, 当文件分片数大于1, 网盘端最终计算所得的md5值和本地的不一致, 这可能是百度网盘的bug, 测试把上传的文件下载到本地后,对比md5值是匹配的. 可通过秒传的原理来修复md5值.

# 常见问题

参见 [常见问题](https://github.com/iikira/BaiduPCS-Go/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
Expand Down
2 changes: 2 additions & 0 deletions baidupcs/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func findErr(errCode int, errMsg string) (int, string) {
return errCode, ""
case 31045: // user not exists
return errCode, "操作失败, 可能百度帐号登录状态过期, 请尝试重新登录, 消息: " + errMsg
case 31066: // file does not exist
return errCode, "文件或目录不存在"
}
return errCode, errMsg
}
6 changes: 5 additions & 1 deletion baidupcs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import (
const (
// MaxUploadBlockSize 最大上传的文件分片大小
MaxUploadBlockSize = 2 * converter.GB
// MinUploadBlockSize 推荐的上传的文件分片大小
MinUploadBlockSize = 128 * converter.MB
// RecommendUploadBlockSize 推荐的上传的文件分片大小
RecommendUploadBlockSize = 1792 * converter.KB
RecommendUploadBlockSize = 1 * converter.GB
// DefaultSliceMD5 默认的长度为32的slicemd5
DefaultSliceMD5 = "ec87a838931d4d5d2e94a04644788a55"
)

// UploadFunc 上传文件处理函数
Expand Down
8 changes: 8 additions & 0 deletions baidupcs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func GetHTTPScheme(https bool) (scheme string) {
return "http"
}

// FixSliceMD5 修复slicemd5为合法的md5
func FixSliceMD5(slicemd5 string) string {
if len(slicemd5) != 32 {
return DefaultSliceMD5
}
return slicemd5
}

// decodeJSONError 解析json中的远端服务器返回的错误
func decodeJSONError(op string, data io.Reader) Error {
errInfo := NewErrorInfo(op)
Expand Down
10 changes: 2 additions & 8 deletions internal/pcscommand/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,6 @@ func RunDownload(paths []string, options *DownloadOptions) {
}

task := e.(*dtask)
if task == nil {
continue
}

wg.AddDelta()
go func() {
defer wg.Done()
Expand Down Expand Up @@ -385,7 +381,7 @@ func RunDownload(paths []string, options *DownloadOptions) {

if dlink != "" {
pcsCommandVerbose.Infof("[%d] 获取到下载链接: %s\n", task.ID, dlink)
client := requester.NewHTTPClient()
client := pcsconfig.Config.HTTPClient()
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
// 去掉 Referer
if !pcsconfig.Config.EnableHTTPS() {
Expand All @@ -398,15 +394,13 @@ func RunDownload(paths []string, options *DownloadOptions) {
}
client.SetTimeout(20 * time.Minute)
client.SetKeepAlive(true)
setupHTTPClient(client)
err = download(task.ID, dlink, task.savePath, dlinks, client, *cfg, options)
} else {
dfunc := func(downloadURL string, jar *cookiejar.Jar) error {
h := requester.NewHTTPClient()
h := pcsconfig.Config.HTTPClient()
h.SetCookiejar(jar)
h.SetKeepAlive(true)
h.SetTimeout(10 * time.Minute)
setupHTTPClient(h)

err := download(task.ID, downloadURL, task.savePath, dlinks, h, *cfg, options)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions internal/pcscommand/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"bytes"
"fmt"
"github.com/iikira/Baidu-Login"
"github.com/iikira/BaiduPCS-Go/internal/pcsconfig"
"github.com/iikira/BaiduPCS-Go/internal/pcsfunctions/pcscaptcha"
"github.com/iikira/BaiduPCS-Go/pcsliner"
"github.com/iikira/BaiduPCS-Go/requester"
"image/png"
"io/ioutil"
"path/filepath"
)

// handleVerifyImg 处理验证码, 下载到本地
Expand All @@ -24,7 +23,7 @@ func handleVerifyImg(imgURL string) (savePath string, err error) {
return "", fmt.Errorf("验证码解析错误: %s", err)
}

savePath = filepath.Join(pcsconfig.GetConfigDir(), "captcha.png")
savePath = pcscaptcha.CaptchaPath()

return savePath, ioutil.WriteFile(savePath, imgContents, 0777)
}
Expand Down Expand Up @@ -53,6 +52,11 @@ func RunLogin(username, password string) (bduss, ptoken, stoken string, err erro
}

var vcode, vcodestr string
// 移除验证码文件
defer func() {
pcscaptcha.RemoveCaptchaPath()
pcscaptcha.RemoveOldCaptchaPath()
}()

for_1:
for i := 0; i < 10; i++ {
Expand Down
Loading

0 comments on commit 2ba6ac7

Please sign in to comment.