Skip to content

Commit

Permalink
v3.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Feb 8, 2021
1 parent 8320df5 commit 0b819d2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 20 deletions.
6 changes: 5 additions & 1 deletion baidupcs/baidupcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,13 @@ func (pcs *BaiduPCS) SetHTTPS(https bool) {

// URL 返回 url
func (pcs *BaiduPCS) URL() *url.URL {
host := pcs.pcsAddr
if host == "" {
host = PCSBaiduCom
}
return &url.URL{
Scheme: GetHTTPScheme(pcs.isHTTPS),
Host: pcs.pcsAddr,
Host: host,
}
}

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: pcs.pcsAddr,
Host: pcs.URL().Host,
Path: "/rest/2.0/pcs/file",
RawQuery: (url.Values{
"check_blue": []string{"1"},
Expand Down
16 changes: 8 additions & 8 deletions baidupcs/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/tidwall/gjson"
Expand All @@ -17,6 +18,7 @@ type (
// ShareOption 分享可选项
TransferOption struct {
Download bool // 是否直接开始下载
Collect bool // 多文件整合
}
)

Expand Down Expand Up @@ -52,10 +54,8 @@ func (pcs *BaiduPCS) ExtractShareInfo(metajsonstr string) (res map[string]string
}
res["filename"] = gjson.Get(metajsonstr, `file_list.list.0.server_filename`).String()
fsid_list := gjson.Get(metajsonstr, `file_list.list.#.fs_id`).Array()
res["item_num"] = strconv.Itoa(len(fsid_list))
var fids_str string = "["
if len(fsid_list) > 1 {
res["filename"] += " 等多个文件"
}
for _, sid := range fsid_list {
fids_str += sid.String() + ","
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (pcs *BaiduPCS) AccessSharePage(featurestr string, first bool) (tokens map[
re, _ := regexp.Compile(`yunData\.setData\((\{"loginstate.+?\})\);`)
sub := re.FindSubmatch(body)
if len(sub) < 2 {
tokens["ErrMsg"] = "分享页面解析失败"
tokens["ErrMsg"] = "请确认登录参数中已经包含了网盘STOKEN"
return
}
tokens["metajson"] = string(sub[1])
Expand Down Expand Up @@ -183,7 +183,7 @@ func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string)
res["ErrMsg"] = "获取分享项元数据错误"
if mode == "POST" && errno == 12 {
path := gjson.Get(string(body), `info.0.path`).String()
_, file := filepath.Split(path)
_, file := filepath.Split(path) // Should be path.Split here, but never mind~
_errno := gjson.Get(string(body), `info.0.errno`).Int()
target_file_nums := gjson.Get(string(body), `target_file_nums`).Int()
target_file_nums_limit := gjson.Get(string(body), `target_file_nums_limit`).Int()
Expand All @@ -206,11 +206,11 @@ func (pcs *BaiduPCS) GenerateRequestQuery(mode string, params map[string]string)
filenames := gjson.Get(string(body), `info.#.path`).Array()
filenames_str := ""
for _, _path := range filenames {
filenames_str += path.Base(_path.String())+","
filenames_str += "," + path.Base(_path.String())
}
res["filenames"] = filenames_str
res["filenames"] = filenames_str[1:]
if len(gjson.Get(string(body), `info.#.fsid`).Array()) > 1 {
res["filename"] += "等多个文件"
res["filename"] += "等多个文件/文件夹"
}
return
}
Expand Down
14 changes: 11 additions & 3 deletions internal/pcscommand/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pcscommand
import (
"encoding/base64"
"fmt"
"path/filepath"
"path"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -77,6 +77,11 @@ func RunShareTransfer(params []string, opt *baidupcs.TransferOption) {
return
}
trans_metas["path"] = GetActiveUser().Workdir
if trans_metas["item_num"] != "1" && opt.Collect {
trans_metas["filename"] += "等文件"
trans_metas["path"] = path.Join(GetActiveUser().Workdir, trans_metas["filename"])
pcs.Mkdir(trans_metas["path"])
}
trans_metas["referer"] = "https://pan.baidu.com/s/" + featurestr
pcs.UpdatePCSCookies(true)
resp := pcs.GenerateRequestQuery("POST", trans_metas)
Expand All @@ -88,6 +93,9 @@ func RunShareTransfer(params []string, opt *baidupcs.TransferOption) {
}
return
}
if opt.Collect {
resp["filename"] = trans_metas["filename"]
}
fmt.Printf("%s成功, 保存了%s到当前目录\n", baidupcs.OperationShareFileSavetoLocal, resp["filename"])
if opt.Download {
fmt.Println("即将开始下载")
Expand Down Expand Up @@ -115,7 +123,7 @@ func RunRapidTransfer(link string) {
md5 := strings.ToLower(substrs[0])
slicemd5 := strings.ToLower(substrs[1])
length, _ := strconv.ParseInt(substrs[2], 10, 64)
filename := filepath.Join(GetActiveUser().Workdir, substrs[3])
filename := path.Join(GetActiveUser().Workdir, substrs[3])
RunRapidUpload(filename, md5, slicemd5, "", length)
return
}
Expand All @@ -124,7 +132,7 @@ func RunRapidTransfer(link string) {
md5 := strings.ToLower(substrs[2])
slicemd5 := strings.ToLower(substrs[3])
length, _ := strconv.ParseInt(substrs[1], 10, 64)
filename := filepath.Join(GetActiveUser().Workdir, substrs[0])
filename := path.Join(GetActiveUser().Workdir, substrs[0])
RunRapidUpload(filename, md5, slicemd5, "", length)
return
}
Expand Down
2 changes: 0 additions & 2 deletions internal/pcsconfig/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ 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(strings.ToLower(baidu.COOKIES), "stoken=") && baidu.STOKEN == "") {
fmt.Println("缺少stoken,将无法使用转存功能")
}
pcs.SetHTTPS(Config.EnableHTTPS)
pcs.SetPCSUserAgent(Config.PCSUA)
Expand Down
8 changes: 8 additions & 0 deletions internal/pcsfunctions/pcsdownload/download_task_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ func (dtu *DownloadTaskUnit) Run() (result *taskframework.TaskUnitRunResult) {
result.Succeed = true // 执行成功
return
}

if dtu.FileInfo.Size == 0 {
if !dtu.Cfg.IsTest {
os.Create(dtu.SavePath)
}
result.Succeed = true // 执行成功
return
}

fmt.Printf("[%s] 准备下载: %s\n", dtu.taskInfo.Id(), dtu.PcsPath)

Expand Down
7 changes: 6 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.4-devel"
Version = "v3.7.5-devel"

historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt")
reloadFn = func(c *cli.Context) error {
Expand Down Expand Up @@ -1418,6 +1418,7 @@ func main() {
}
opt := &baidupcs.TransferOption{
Download: c.Bool("download"),
Collect: c.Bool("collect"),
}
pcscommand.RunShareTransfer(c.Args(), opt)
return nil
Expand All @@ -1427,6 +1428,10 @@ func main() {
Name: "download",
Usage: "转存后直接下载到本地默认目录",
},
cli.BoolFlag{
Name: "collect",
Usage: "多文件整合到一个文件夹中",
},
},
},
{
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": 4,
"Patch": 5,
"Build": 0
},
"ProductVersion": {
"Major": 3,
"Minor": 7,
"Patch": 4,
"Patch": 5,
"Build": 0
},
"FileFlagsMask": "3f",
Expand All @@ -22,14 +22,14 @@
"Comments": "",
"CompanyName": "qjfoidnh",
"FileDescription": "百度网盘客户端(加强版)",
"FileVersion": "v3.7.4",
"FileVersion": "v3.7.5",
"InternalName": "",
"LegalCopyright": "© 2016-2020 iikira.",
"LegalTrademarks": "",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "BaiduPCS-Go",
"ProductVersion": "v3.7.4",
"ProductVersion": "v3.7.5",
"SpecialBuild": ""
},
"VarFileInfo": {
Expand Down

0 comments on commit 0b819d2

Please sign in to comment.