Skip to content

Commit

Permalink
🚧 目前用此工具投稿的工具无法过审,原因未知,待修复
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMiku01 committed Oct 1, 2022
1 parent ba8d1dc commit 284a132
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*.exe
.idea
biliup-go

dist/
91 changes: 91 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# biliup-go

**测试中,目前上传的视频过不了审,原因未知待解决**

B 站命令行投稿工具 Golang 实现,支持 **扫码登录**, 并将登录后返回的 cookie 和 token 保存在 `cookie.json` 中,可用于其他项目。

[biliup-rs](https://github.com/ForgQi/biliup-rs) 的 Golang 实现。

## 登录

```bash
biliup-go login
./biliup-go login
```

## 上传视频
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
)
44 changes: 32 additions & 12 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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++
}
Expand All @@ -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
}

0 comments on commit 284a132

Please sign in to comment.