diff --git a/.github/RELEASE_TEMPLATE.md b/.github/RELEASE_TEMPLATE.md index 76930b13..3c932d2f 100644 --- a/.github/RELEASE_TEMPLATE.md +++ b/.github/RELEASE_TEMPLATE.md @@ -1,10 +1,13 @@ # 更新日志: -1. 修复 bug; -2. 支持检测更新; -3. 列目录支持排序选项; -4. 调整配置文件储存目录, 可选家目录和程序所在目录; -5. emm... +1. 修复下载无法断点续传的 bug; +2. 修复程序自动更新失败的 bug; +3. 支持分享/取消分享文件/目录; +4. 支持获取文件下载的直链; +5. 支持以分享文件的方式获取下载链接来下载,和以获取直链的方式来下载; +6. 新增 who 命令, 获取当前帐号; + +v3.5.1 的自动更新功能异常, 手动更新吧.... 个人项目bug在所难免! 欢迎提 issue 和 pull request!!. diff --git a/README.md b/README.md index 99d8af64..b7367257 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang * [检测程序更新](#检测程序更新) * [登录百度帐号](#登录百度帐号) * [列出帐号列表](#列出帐号列表) + * [获取当前帐号](#获取当前帐号) * [切换百度帐号](#切换百度帐号) * [退出百度帐号](#退出百度帐号) * [获取网盘配额](#获取网盘配额) @@ -30,6 +31,7 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang * [获取单个文件/目录的元信息](#获取单个文件目录的元信息) * [下载文件/目录](#下载文件目录) * [上传文件/目录](#上传文件目录) + * [获取下载直链](#获取下载直链) * [手动秒传文件](#手动秒传文件) * [获取本地文件的秒传信息](#获取本地文件的秒传信息) * [导出文件/目录](#导出文件目录) @@ -37,6 +39,10 @@ This project was largely inspired by [GangZhuo/BaiduPCS](https://github.com/Gang * [删除文件/目录](#删除文件目录) * [拷贝文件/目录](#拷贝文件目录) * [移动/重命名文件/目录](#移动重命名文件目录) + * [分享文件/目录](#分享文件目录) + + [设置分享文件/目录](#设置分享文件目录) + + [列出已分享文件/目录](#列出已分享文件目录) + + [取消分享文件/目录](#取消分享文件目录) * [离线下载](#离线下载) + [添加离线下载任务](#添加离线下载任务) + [精确查询离线下载任务](#精确查询离线下载任务) @@ -164,7 +170,13 @@ BaiduPCS-Go login BaiduPCS-Go loglist ``` -获取当前帐号, 和所有已登录的百度帐号 +列出所有已登录的百度帐号 + +## 获取当前帐号 + +``` +BaiduPCS-Go who +``` ## 切换百度帐号 @@ -299,12 +311,15 @@ BaiduPCS-Go d <网盘文件或目录的路径1> <文件或目录2> <文件或目 ### 可选参数 ``` --test: 测试下载, 此操作不会保存文件到本地 --status: 输出所有线程的工作状态 ---save: 将下载的文件直接保存到当前工作目录 ---saveto: 将下载的文件直接保存到指定的目录 --x: 为文件加上执行权限, (windows系统无效) --p : 指定下载的最大并发量 + --test 测试下载, 此操作不会保存文件到本地 + --ow overwrite, 覆盖已存在的文件 + --status 输出所有线程的工作状态 + --save 将下载的文件直接保存到当前工作目录 + --saveto value 将下载的文件直接保存到指定的目录 + -x 为文件加上执行权限, (windows系统无效) + --share 以分享文件的方式获取下载链接来下载 + --locate 以获取直链的方式来下载 + -p value 指定下载线程数 ``` 支持多个文件或目录的下载. @@ -355,6 +370,11 @@ BaiduPCS-Go upload C:/Users/Administrator/Desktop/1.mp4 C:/Users/Administrator/D BaiduPCS-Go upload C:/Users/Administrator/Desktop /视频 ``` +## 获取下载直链 +``` +BaiduPCS-Go locate <文件1> <文件2> ... +``` + ## 手动秒传文件 ``` BaiduPCS-Go rapidupload -length=<文件的大小> -md5=<文件的md5值> -slicemd5=<文件前256KB切片的md5值(可选)> -crc32=<文件的crc32值(可选)> <保存的网盘路径, 需包含文件名> @@ -403,10 +423,10 @@ BaiduPCS-Go ep <文件/目录1> <文件/目录2> ... # 导出当前工作目录: BaiduPCS-Go export -# 导出所有文件和目录, 并设置新的根目录为 `/root` +# 导出所有文件和目录, 并设置新的根目录为 /root BaiduPCS-Go export -root=/root / -# 导出 `/我的资源` +# 导出 /我的资源 BaiduPCS-Go export /我的资源 ``` @@ -480,6 +500,31 @@ BaiduPCS-Go mv /我的资源/1.mp4 / BaiduPCS-Go mv /我的资源/1.mp4 /我的资源/3.mp4 ``` +## 分享文件/目录 +``` +BaiduPCS-Go share +``` + +### 设置分享文件/目录 +``` +BaiduPCS-Go share set <文件/目录1> <文件/目录2> ... +BaiduPCS-Go share s <文件/目录1> <文件/目录2> ... +``` + +### 列出已分享文件/目录 +``` +BaiduPCS-Go share list +BaiduPCS-Go share l +``` + +### 取消分享文件/目录 +``` +BaiduPCS-Go share cancel ... +BaiduPCS-Go share c ... +``` + +目前只支持通过分享id (shareid) 来取消分享. + ## 离线下载 ``` BaiduPCS-Go offlinedl @@ -695,4 +740,4 @@ QQ群: 178324706 |支付宝| |:-----:| -|![alipay](./assets/donate/alipay.jpg)| +|![alipay](https://github.com/iikira/BaiduPCS-Go/raw/master/assets/donate/alipay.jpg)| diff --git a/baidupcs/share.go b/baidupcs/share.go index 63262a35..946537ca 100644 --- a/baidupcs/share.go +++ b/baidupcs/share.go @@ -5,7 +5,6 @@ import ( "github.com/iikira/baidu-tools/pan" "github.com/json-iterator/go" "net/url" - "path" "strconv" "strings" ) @@ -48,26 +47,13 @@ type ShareRecordInfoList []*ShareRecordInfo // Clean 清理 func (sril *ShareRecordInfoList) Clean() { - newSril := make(ShareRecordInfoList, 0, len(*sril)) - for _, sri := range *sril { if sri == nil { continue } - if !path.IsAbs(sri.TypicalPath) { - continue - } - - if len(sri.FsIds) == 0 { - continue - } - sri.Clean() - newSril = append(newSril, sri) } - - *sril = newSril } // ShareSet 分享文件 diff --git a/build.sh b/build.sh index 112c7f0a..5d734a4f 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ name="BaiduPCS-Go" version=$1 if [ "$1" = "" ];then - version=v3.5.1 + version=v3.5.2 fi output="out/" @@ -19,10 +19,10 @@ Build() { export GOOS=$2 GOARCH=$3 GO386=sse2 CGO_ENABLED=0 GOARM=$4 if [ $2 = "windows" ];then goversioninfo -icon=assets/$name.ico -manifest="$name".exe.manifest -product-name="$name" -file-version="$version" -product-version="$version" -company=iikira -copyright="© 2016-2018 iikira." -o=resource_windows.syso - go build -ldflags "-s -w" -o "$output/$1/$name.exe" + go build -ldflags "-X main.Version=$version -s -w" -o "$output/$1/$name.exe" RicePack $1 $name.exe else - go build -ldflags "-s -w" -o "$output/$1/$name" + go build -ldflags "-X main.Version=$version -s -w" -o "$output/$1/$name" RicePack $1 $name fi @@ -32,7 +32,7 @@ Build() { ArmBuild() { echo "Building $1..." export GOOS=$2 GOARCH=$3 GOARM=$4 CGO_ENABLED=1 - go build -ldflags '-s -w -linkmode=external -extldflags=-pie' -o "$output/$1/$name" + go build -ldflags "-X main.Version=$version -s -w -linkmode=external -extldflags=-pie" -o "$output/$1/$name" if [ $2 = "darwin" ] && [ $3 = "arm" -o $3 = "arm64" ];then # cp Info.plist "$output/$1" ldid -S "$output/$1/$name" diff --git a/debian/iphoneos-arm/control b/debian/iphoneos-arm/control index bb82bc9d..58d382d5 100644 --- a/debian/iphoneos-arm/control +++ b/debian/iphoneos-arm/control @@ -1,5 +1,5 @@ Package: BaiduPCS-Go -Version: 3.5.1 +Version: 3.5.2 Homepage: https://github.com/iikira/BaiduPCS-Go Section: 实用工具 Priority: optional diff --git a/internal/pcscommand/share.go b/internal/pcscommand/share.go index 4172b66e..0be8b0a9 100644 --- a/internal/pcscommand/share.go +++ b/internal/pcscommand/share.go @@ -7,6 +7,7 @@ import ( "github.com/iikira/BaiduPCS-Go/pcstable" "github.com/iikira/BaiduPCS-Go/requester" "github.com/iikira/baidu-tools/pan" + "net/url" "os" "path" "strconv" @@ -55,13 +56,13 @@ func RunShareList() { } tb := pcstable.NewTable(os.Stdout) - tb.SetHeader([]string{"#", "ShareID", "分享链接", "提取密码", "根目录"}) + tb.SetHeader([]string{"#", "ShareID", "分享链接", "提取密码", "根目录", "路径"}) for k, record := range records { if record == nil { continue } - tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(record.ShareID, 10), record.Shortlink, record.Passwd, path.Dir(record.TypicalPath)}) + tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(record.ShareID, 10), record.Shortlink, record.Passwd, record.TypicalPath[:strings.LastIndex(record.TypicalPath, "/")+1], record.TypicalPath}) } tb.Render() } @@ -155,5 +156,17 @@ func getLink(shareID int64, shareLink, passwd, rootSharePath, filePath string) ( return "" } - return fd.Dlink + u, err := url.Parse(fd.Dlink) + if err != nil { + pcsCommandVerbose.Warn(err.Error()) + return "" + } + + if pcsconfig.Config.EnableHTTPS() { + u.Scheme = "https" + } else { + u.Scheme = "http" + } + + return u.String() } diff --git a/internal/pcsupdate/pcsupdate.go b/internal/pcsupdate/pcsupdate.go index 6e8b3709..eeb1e3e5 100644 --- a/internal/pcsupdate/pcsupdate.go +++ b/internal/pcsupdate/pcsupdate.go @@ -64,8 +64,8 @@ func CheckUpdate(version string, yes bool) { continue } - // 忽略 Beta 版本 - if strings.Contains(versionInfo.Filename, "Beta") { + // 忽略 Beta 版本, 和版本前缀不符的 + if strings.Contains(versionInfo.Filename, "Beta") || !strings.HasPrefix(versionInfo.Filename, "v") { continue } @@ -139,7 +139,7 @@ func CheckUpdate(version string, yes bool) { continue } - if fileInfo.Isdir == 1 || !strings.HasPrefix(fileInfo.Filename, "v") { + if fileInfo.Isdir == 1 { continue } diff --git a/main.go b/main.go index 6e2aa9c7..5f0b8c2b 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ import ( var ( // Version 版本号 - Version = "v3.5.1" + Version = "v3.5.2-devel" historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt") reloadFn = func(c *cli.Context) error { @@ -125,7 +125,7 @@ func main() { fmt.Printf("未找到命令: %s\n运行命令 %s help 获取帮助\n", c.Args().Get(0), app.Name) return } - cli.ShowAppHelp(c) + pcsverbose.Verbosef("VERBOSE: 这是一条调试信息\n\n") var ( @@ -271,6 +271,8 @@ func main() { return }) + fmt.Printf("提示: 输入 help 获取帮助.\n") + for { var ( prompt string @@ -580,18 +582,27 @@ func main() { { Name: "loglist", Usage: "列出帐号列表", - Description: "获取当前帐号, 和所有已登录的百度帐号", + Description: "列出所有已登录的百度帐号", Category: "百度帐号", Before: reloadFn, Action: func(c *cli.Context) error { - activeUser := pcsconfig.Config.ActiveUser() - fmt.Printf("\n当前帐号 uid: %d, 用户名: %s\n\n", activeUser.UID, activeUser.Name) - list := pcsconfig.Config.BaiduUserList() fmt.Println(list.String()) return nil }, }, + { + Name: "who", + Usage: "获取当前帐号", + Description: "获取当前帐号的信息", + Category: "百度帐号", + Before: reloadFn, + Action: func(c *cli.Context) error { + activeUser := pcsconfig.Config.ActiveUser() + fmt.Printf("当前帐号 uid: %d, 用户名: %s, 性别: %s, 年龄: %.1f\n", activeUser.UID, activeUser.Name, activeUser.Sex, activeUser.Age) + return nil + }, + }, { Name: "quota", Usage: "获取网盘配额", @@ -1004,7 +1015,7 @@ func main() { Name: "locate", Aliases: []string{"lt"}, Usage: "获取下载直链", - UsageText: fmt.Sprintf("%s locate <文件>", app.Name), + UsageText: fmt.Sprintf("%s locate <文件1> <文件2> ...", app.Name), Category: "百度网盘", Before: reloadFn, Action: func(c *cli.Context) error { @@ -1154,7 +1165,7 @@ func main() { }, { Name: "share", - Usage: "分享文件", + Usage: "分享文件/目录", UsageText: app.Name + " share", Category: "百度网盘", Before: reloadFn, @@ -1167,10 +1178,11 @@ func main() { }, Subcommands: []cli.Command{ { - Name: "set", - Aliases: []string{"s"}, - Usage: "设置分享文件", - UsageText: app.Name + " share set <文件/目录1> <文件/目录2> ...", + Name: "set", + Aliases: []string{"s"}, + Usage: "设置分享文件/目录", + UsageText: app.Name + " share set <文件/目录1> <文件/目录2> ...", + Description: `目前只支持创建私密链接.`, Action: func(c *cli.Context) error { if c.NArg() < 1 { cli.ShowCommandHelp(c, c.Command.Name) @@ -1183,7 +1195,7 @@ func main() { { Name: "list", Aliases: []string{"l"}, - Usage: "列出已分享文件", + Usage: "列出已分享文件/目录", UsageText: app.Name + " share list", Action: func(c *cli.Context) error { pcscommand.RunShareList() @@ -1191,10 +1203,11 @@ func main() { }, }, { - Name: "cancel", - Aliases: []string{"c"}, - Usage: "取消分享文件", - UsageText: app.Name + " share cancel ...", + Name: "cancel", + Aliases: []string{"c"}, + Usage: "取消分享文件/目录", + UsageText: app.Name + " share cancel ...", + Description: `目前只支持通过分享id (shareid) 来取消分享.`, Action: func(c *cli.Context) error { if c.NArg() < 1 { cli.ShowCommandHelp(c, c.Command.Name) diff --git a/resource_windows.syso b/resource_windows.syso index 681e4300..210c92da 100644 Binary files a/resource_windows.syso and b/resource_windows.syso differ diff --git a/versioninfo.json b/versioninfo.json index 8693e924..c9247195 100644 --- a/versioninfo.json +++ b/versioninfo.json @@ -3,13 +3,13 @@ "FileVersion": { "Major": 3, "Minor": 5, - "Patch": 1, + "Patch": 2, "Build": 0 }, "ProductVersion": { "Major": 3, "Minor": 5, - "Patch": 1, + "Patch": 2, "Build": 0 }, "FileFlagsMask": "3f", @@ -22,14 +22,14 @@ "Comments": "", "CompanyName": "iikira", "FileDescription": "百度网盘客户端", - "FileVersion": "v3.5.1", + "FileVersion": "v3.5.2", "InternalName": "", "LegalCopyright": "© 2016-2018 iikira.", "LegalTrademarks": "", "OriginalFilename": "", "PrivateBuild": "", "ProductName": "BaiduPCS-Go", - "ProductVersion": "v3.5.1", + "ProductVersion": "v3.5.2", "SpecialBuild": "" }, "VarFileInfo": {