diff --git a/.gitignore b/.gitignore index 53b5d7b..c56f672 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ *.exe .idea biliup-go + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a1940ea --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,91 @@ +env: + - GO111MODULE=on +before: + hooks: + - go mod tidy +release: + draft: true + discussion_category_name: General +builds: + - id: nowin + env: + - CGO_ENABLED=0 + - GO111MODULE=on + goos: + - linux + - darwin + goarch: + - "386" + - amd64 + - arm + - arm64 + goarm: + - "7" + ignore: + - goos: darwin + goarch: arm + - goos: darwin + goarch: "386" + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - -s -w + - id: win + env: + - CGO_ENABLED=0 + - GO111MODULE=on + goos: + - windows + goarch: + - "386" + - amd64 + - arm + - arm64 + goarm: + - "7" + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - -s -w + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + - fix typo + - Merge pull request + - Merge branch + - Merge remote-tracking + - go mod tidy + +archives: + - id: binary + builds: + - win + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + format_overrides: + - goos: windows + format: binary + - id: nowin + builds: + - nowin + - win + name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + format_overrides: + - goos: windows + format: zip + +nfpms: + - license: AGPL 3.0 + homepage: https://github.com/XiaoMiku01/biliup-go + file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + formats: + - deb + - rpm + maintainer: XiaoMiku01 diff --git a/README.md b/README.md index 87c97f8..11033ae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # biliup-go +**测试中,目前上传的视频过不了审,原因未知待解决** + B 站命令行投稿工具 Golang 实现,支持 **扫码登录**, 并将登录后返回的 cookie 和 token 保存在 `cookie.json` 中,可用于其他项目。 对 [biliup-rs](https://github.com/ForgQi/biliup-rs) 的 Golang 实现。 @@ -7,7 +9,7 @@ B 站命令行投稿工具 Golang 实现,支持 **扫码登录**, 并将登录 ## 登录 ```bash -biliup-go login +./biliup-go login ``` ## 上传视频 diff --git a/go.mod b/go.mod index 02213fd..ed6bc9d 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/imroc/req/v3 v3.24.0 github.com/schollz/progressbar/v3 v3.11.0 github.com/tidwall/gjson v1.14.3 + gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) require ( @@ -40,6 +41,5 @@ require ( golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.12 // indirect - gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect ) diff --git a/upload/upload.go b/upload/upload.go index 3131464..d79829c 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -199,14 +199,16 @@ func (u *Up) Up() { func (u *Up) upload() { var upinfo UpInfo u.client.SetCommonHeader( - "X-Upos-Auth", u.upVideo.auth).R().SetQueryParams(map[string]string{ - "uploads": "", - "output": "json", - "profile": "ugcfx/bup", - "filesize": strconv.FormatInt(u.upVideo.videoSize, 10), - "partsize": strconv.FormatInt(u.upVideo.chunkSize, 10), - "biz_id": strconv.FormatInt(u.upVideo.bizId, 10), - }).SetResult(&upinfo).Post(u.upVideo.uploadBaseUrl) + "X-Upos-Auth", u.upVideo.auth).R(). + SetQueryParams(map[string]string{ + "uploads": "", + "output": "json", + "profile": "ugcfx/bup", + "filesize": strconv.FormatInt(u.upVideo.videoSize, 10), + "partsize": strconv.FormatInt(u.upVideo.chunkSize, 10), + "biz_id": strconv.FormatInt(u.upVideo.bizId, 10), + "meta_upos_uri": u.getMetaUposUri(), + }).SetResult(&upinfo).Post(u.upVideo.uploadBaseUrl) u.upVideo.uploadId = upinfo.UploadId chunks := int64(math.Ceil(float64(u.upVideo.videoSize) / float64(u.upVideo.chunkSize))) var reqjson = new(ReqJson) @@ -234,9 +236,12 @@ func (u *Up) upload() { if size > 0 { wg.Add(1) end += size - go func(chunk int, start, end int, buf []byte) { + go func(chunk int, start, end, size int, buf []byte) { defer wg.Done() - u.client.R().SetQueryParams(map[string]string{ + u.client.R().SetHeaders(map[string]string{ + "Content-Type": "application/octet-stream", + "Content-Length": strconv.Itoa(size), + }).SetQueryParams(map[string]string{ "partNumber": strconv.Itoa(chunk + 1), "uploadId": u.upVideo.uploadId, "chunk": strconv.Itoa(chunk), @@ -245,13 +250,13 @@ func (u *Up) upload() { "start": strconv.Itoa(start), "end": strconv.Itoa(end), "total": strconv.FormatInt(u.upVideo.videoSize, 10), - }).SetBody(buf).Put(u.upVideo.uploadBaseUrl) + }).SetBodyBytes(buf).Put(u.upVideo.uploadBaseUrl) bar.Add(len(buf) / 1024 / 1024) partchan <- Part{ PartNumber: int64(chunk + 1), ETag: "etag", } - }(chunk, start, end, buf) + }(chunk, start, end, size, buf) start += size chunk++ } @@ -269,3 +274,18 @@ func (u *Up) upload() { "biz_id": strconv.FormatInt(u.upVideo.bizId, 10), }).SetBodyJsonMarshal(reqjson).SetResult(&upinfo).Post(u.upVideo.uploadBaseUrl) } + +func (u *Up) getMetaUposUri() string { + var metaUposUri PreUpInfo + u.client.R().SetQueryParams(map[string]string{ + "name": "file_meta.txt", + "size": "2000", + "r": "upos", + "profile": "fxmeta/bup", + "ssl": "0", + "version": "2.10.4", + "build": "2100400", + "webVersion": "2.0.0", + }).SetResult(&metaUposUri).Get("https://member.bilibili.com/preupload") + return metaUposUri.UposUri +}