Skip to content

Commit

Permalink
修复BV AV转换函数,原代码非64位平台编译错误,添加gorelease action
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtfu committed Jan 6, 2025
1 parent 4c267b8 commit 618dd72
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
tags:
- '*'

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
timeout-minutes: 20

permissions:
contents: write
packages: write

steps:
- name: 📦 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: test-release

- name: Set up Go
uses: actions/setup-go@v5

- name: 🚧️ Make release
uses: goreleaser/goreleaser-action@v6
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: latest
args: release --clean
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# vendor/
dist/
20 changes: 20 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
project_name: "bilibili"

before:
hooks:
- go mod tidy

builds:
- no_main_check: true
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
- arm
- arm64
11 changes: 6 additions & 5 deletions misc.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package bilibili

import (
"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
"regexp"
"strconv"
"strings"
"time"

"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -63,14 +64,14 @@ func (c *Client) Now() (time.Time, error) {
}

// Av2Bv 将av号转换为bv号,返回格式为"BV1xxxxxxxxx"。
func Av2Bv(aid int) string {
func Av2Bv(aid int64) string {
const (
xorCode = 0x1552356C4CDB
maxAid int64 = 1 << 51
alphabet = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"
)
bvid := []byte("BV1000000000")
tmp := (maxAid | int64(aid)) ^ xorCode
tmp := (maxAid | aid) ^ xorCode
l := int64(len(alphabet))
for _, e := range []int{11, 10, 3, 8, 4, 6, 5, 7, 9} {
bvid[e] = alphabet[tmp%l]
Expand All @@ -80,7 +81,7 @@ func Av2Bv(aid int) string {
}

// Bv2Av 将bv号转换为av号,传入的bv号格式为"BV1xxxxxxxxx",前面的"BV"不区分大小写。
func Bv2Av(bvid string) int {
func Bv2Av(bvid string) int64 {
if len(bvid) != 12 {
panic("bvid 格式错误: " + bvid)
}
Expand Down

0 comments on commit 618dd72

Please sign in to comment.