Skip to content

Commit

Permalink
v3.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Jan 31, 2021
1 parent e6735e1 commit 8320df5
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 14 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co

# 版本更新

**2021.1.31** v3.7.4:

- fix 下载目录会丢失目录结构
- fix 分享列表状态信息显示错误
- 支持自定义文件上传服务器

**2021.1.22** v3.7.3:

- 分享支持自定义分享码和有效天数
Expand Down Expand Up @@ -860,6 +866,18 @@ Windows: `%APPDATA%\BaiduPCS-Go`

谨慎修改 `appid`, `user_agent`, `pcs_ua`, `pan_ua` 的值, 否则访问网盘服务器时, 可能会出现错误.

上传速度慢的海外用户可尝试修改 `pcs_addr` 值, 选择速度较快的服务器, 目前已知的地址有:

```
pcs.baidu.com
c.pcs.baidu.com
c2.pcs.baidu.com
c3.pcs.baidu.com
c4.pcs.baidu.com
c5.pcs.baidu.com
d.pcs.baidu.com
```

`cache_size` 的值支持可选设置单位了, 单位不区分大小写, `b``B` 均表示字节的意思, 如 `64KB`, `1MB`, `32kb`, `65536b`, `65536`.

`max_download_rate`, `max_upload_rate` 的值支持可选设置单位了, 单位为每秒的传输速率, 后缀`/s` 可省略, 如 `2MB/s`, `2MB`, `2m`, `2mb` 均为一个意思.
Expand Down
8 changes: 7 additions & 1 deletion baidupcs/baidupcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type (
uid uint64 // 百度uid
client *requester.HTTPClient // http 客户端
pcsUA string
pcsAddr string
panUA string
isSetPanUA bool
ph *panhome.PanHome
Expand Down Expand Up @@ -319,6 +320,11 @@ func (pcs *BaiduPCS) SetPCSUserAgent(ua string) {
pcs.pcsUA = ua
}

// SetPCSAddr 设置 PCS 服务器地址
func (pcs *BaiduPCS) SetPCSAddr(addr string) {
pcs.pcsAddr = addr
}

// SetPanUserAgent 设置 Pan User-Agent
func (pcs *BaiduPCS) SetPanUserAgent(ua string) {
pcs.panUA = ua
Expand All @@ -334,7 +340,7 @@ func (pcs *BaiduPCS) SetHTTPS(https bool) {
func (pcs *BaiduPCS) URL() *url.URL {
return &url.URL{
Scheme: GetHTTPScheme(pcs.isHTTPS),
Host: PCSBaiduCom,
Host: pcs.pcsAddr,
}
}

Expand Down
2 changes: 1 addition & 1 deletion baidupcs/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (pcs *BaiduPCS) PrepareLocateDownload(pcspath string) (dataReadCloser io.Re
ns := netdisksign.NewLocateDownloadSign(pcs.uid, bduss)
pcsURL := &url.URL{
Scheme: GetHTTPScheme(pcs.isHTTPS),
Host: PCSBaiduCom,
Host: pcs.pcsAddr,
Path: "/rest/2.0/pcs/file",
RawQuery: (url.Values{
"check_blue": []string{"1"},
Expand Down
4 changes: 3 additions & 1 deletion baidupcs/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type (
Status int `json:"status"` // 状态
Public int `json:"public"` // 是否为公开分享
TypicalCategory int `json:"typicalCategory"` // 文件类型
TypicalPath string `json:"typicalPath"`
TypicalPath string `json:"typicalPath"` // 路径
ExpireType int `json:"expiredType"` // 过期类型
ExpireTime int64 `json:"expiredTime"` // 过期时间
Valid string // 是否过期
}

Expand Down
19 changes: 14 additions & 5 deletions internal/pcscommand/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path"
"strconv"
"strings"
"time"
)

// RunShareSet 执行分享
Expand Down Expand Up @@ -56,22 +58,29 @@ func RunShareList(page int) {
}

tb := pcstable.NewTable(os.Stdout)
tb.SetHeader([]string{"#", "ShareID", "分享链接", "提取密码", "特征目录", "特征路径", "分享状态"})
tb.SetHeader([]string{"#", "ShareID", "分享链接", "提取密码", "特征目录", "特征路径", "过期时间"})
for k, record := range records {
if record.TypicalCategory == -1 {
if record.ExpireType == -1 {
record.Valid = "已过期" // 已失效分享
} else {
record.Valid = "有效"
if record.ExpireTime == 0 {
record.Valid = "永久"
} else {
tm := time.Unix(time.Now().Unix() + record.ExpireTime, 0)
record.Valid = tm.Format("2006/01/02 15:04:05")

}

}
// 获取Passwd
if record.Public == 0 && record.TypicalCategory != -1 {
if record.Public == 0 && record.ExpireType != -1 {
// 私密分享
info, pcsError := pcs.ShareSURLInfo(record.ShareID)
if pcsError != nil {
// 获取错误
fmt.Printf("[%d] 获取分享密码错误: %s\n", k, pcsError)
} else {
record.Passwd = info.Pwd
record.Passwd = strings.TrimSpace(info.Pwd)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pcsconfig/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (baidu *Baidu) BaiduPCS() *baidupcs.BaiduPCS {
if strings.Contains(baidu.COOKIES, "STOKEN=") && baidu.STOKEN == "" {
// 未显式指定stoken则从cookies中读取
pcs = baidupcs.NewPCSWithCookieStr(Config.AppID, baidu.COOKIES)
} else if(!strings.Contains(baidu.COOKIES, "STOKEN=") && baidu.STOKEN == "") {
} else if(!strings.Contains(strings.ToLower(baidu.COOKIES), "stoken=") && baidu.STOKEN == "") {
fmt.Println("缺少stoken,将无法使用转存功能")
}
pcs.SetHTTPS(Config.EnableHTTPS)
Expand Down
1 change: 1 addition & 0 deletions internal/pcsconfig/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (c *PCSConfig) PrintTable() {
[]string{"no_check", fmt.Sprint(c.NoCheck), "true", "关闭下载文件md5校验"},
[]string{"user_agent", c.UserAgent, requester.DefaultUserAgent, "浏览器标识"},
[]string{"pcs_ua", c.PCSUA, "", "PCS 浏览器标识"},
[]string{"pcs_addr", c.PCSAddr, "pcs.baidu.com", "PCS 服务器地址"},
[]string{"pan_ua", c.PanUA, baidupcs.NetdiskUA, "Pan 浏览器标识"},
[]string{"proxy", c.Proxy, "", "设置代理, 支持 http/socks5 代理"},
[]string{"local_addrs", c.LocalAddrs, "", "设置本地网卡地址, 多个地址用逗号隔开"},
Expand Down
12 changes: 12 additions & 0 deletions internal/pcsconfig/maniper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ func (c *PCSConfig) SetPanUA(panUA string) {
}
}

// SetPCSAddr 设置 PCS 服务器地址
func (c *PCSConfig) SETPCSAddr(pcsaddr string) bool {
match, _ := regexp.MatchString("^([cd]\\d?\\.)?pcs\\.baidu\\.com", pcsaddr)
if match {
c.PCSAddr = pcsaddr
if c.pcs != nil {
c.pcs.SetPCSAddr(pcsaddr)
}
}
return match
}

// SetEnableHTTPS 设置是否启用https
func (c *PCSConfig) SetEnableHTTPS(https bool) {
c.EnableHTTPS = https
Expand Down
3 changes: 3 additions & 0 deletions internal/pcsconfig/pcsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type PCSConfig struct {

UserAgent string `json:"user_agent"` // 浏览器标识
PCSUA string `json:"pcs_ua"` // PCS浏览器标识
PCSAddr string `json:"pcs_addr"` // PCS服务器域名
PanUA string `json:"pan_ua"` // PAN浏览器标识
SaveDir string `json:"savedir"` // 下载储存路径
EnableHTTPS bool `json:"enable_https"` // 启用https
Expand Down Expand Up @@ -152,6 +153,7 @@ func (c *PCSConfig) init() error {
return err
}
c.pcs = c.activeUser.BaiduPCS()
c.pcs.SetPCSAddr(c.PCSAddr)

// 设置全局User-Agent
requester.UserAgent = c.UserAgent
Expand Down Expand Up @@ -228,6 +230,7 @@ func (c *PCSConfig) InitDefaultConfig() {
c.MaxDownloadLoad = 1
c.UserAgent = requester.UserAgent
c.PCSUA = ""
c.PCSAddr = "pcs.baidu.com"
c.PanUA = baidupcs.NetdiskUA
c.EnableHTTPS = true
c.NoCheck = true
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

var (
// Version 版本号
Version = "v3.7.3-devel"
Version = "v3.7.4-devel"

historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt")
reloadFn = func(c *cli.Context) error {
Expand Down Expand Up @@ -1854,6 +1854,13 @@ func main() {
if c.IsSet("pcs_ua") {
pcsconfig.Config.SetPCSUA(c.String("pcs_ua"))
}
if c.IsSet("pcs_addr") {
match := pcsconfig.Config.SETPCSAddr(c.String("pcs_addr"))
if !match {
fmt.Println("设置 pcs_addr 错误: pcs服务器地址不合法")
return nil
}
}
if c.IsSet("pan_ua") {
pcsconfig.Config.SetPanUA(c.String("pan_ua"))
}
Expand Down Expand Up @@ -1964,6 +1971,10 @@ func main() {
Name: "pcs_ua",
Usage: "PCS 浏览器标识",
},
cli.StringFlag{
Name: "pcs_addr",
Usage: "PCS 服务器地址",
},
cli.StringFlag{
Name: "pan_ua",
Usage: "Pan 浏览器标识",
Expand Down
8 changes: 4 additions & 4 deletions versioninfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"FileVersion": {
"Major": 3,
"Minor": 7,
"Patch": 3,
"Patch": 4,
"Build": 0
},
"ProductVersion": {
"Major": 3,
"Minor": 7,
"Patch": 3,
"Patch": 4,
"Build": 0
},
"FileFlagsMask": "3f",
Expand All @@ -22,14 +22,14 @@
"Comments": "",
"CompanyName": "qjfoidnh",
"FileDescription": "百度网盘客户端(加强版)",
"FileVersion": "v3.7.3",
"FileVersion": "v3.7.4",
"InternalName": "",
"LegalCopyright": "© 2016-2020 iikira.",
"LegalTrademarks": "",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "BaiduPCS-Go",
"ProductVersion": "v3.7.3",
"ProductVersion": "v3.7.4",
"SpecialBuild": ""
},
"VarFileInfo": {
Expand Down

0 comments on commit 8320df5

Please sign in to comment.