Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复BV AV转换函数,原代码非64位平台编译错误 #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yangtfu
Copy link
Collaborator

@yangtfu yangtfu commented Jan 5, 2025

更改类型为int64

@CuteReimu
Copy link
Owner

这里有几个很纠结的地方,首先我们很多接口其实没有管32位机的问题,这个要不要考虑上,而且会不会发生breaking changes?

要不改一下golangci-lint.yml试试,看看有没有其它问题?

  build:
-   runs-on: ubuntu-latest
+   runs-on: ${{ matrix.os }}
+
+   strategy:
+     matrix:
+       os: [ubuntu-latest, ubuntu-32bit]
  steps:

如果有其它问题的话,其实仅这一个改动意义不大

@CuteReimu
Copy link
Owner

CuteReimu commented Jan 6, 2025

试了一下,Github还不支持32位系统编译。这就很麻烦了,感觉misc_test.go似乎在32位机上也测试不过。

@CuteReimu
Copy link
Owner

你看,换了几种写法,也难以进行32位机的测试。有办法验证32位机是否能够跑通吗?

@yangtfu
Copy link
Collaborator Author

yangtfu commented Jan 6, 2025

对go不是很熟悉,搞了半天复现不了编译问题,是在引用本repo时发现的,用的goreleaser/goreleaser-action@v6
https://github.com/yangtfu/podsync/actions/runs/12611437596/job/35147096176

⨯ release failed after 2m49s               error=build failed: failed to build for linux_arm_6: exit status 1: # github.com/CuteReimu/bilibili/v2
../../../go/pkg/mod/github.com/!cute!reimu/bilibili/[email protected]/misc.go:73:10: maxAid (untyped int constant 22517998136852[48](https://github.com/yangtfu/podsync/actions/runs/12611437596/job/35147096176#step:6:49)) overflows int
../../../go/pkg/mod/github.com/!cute!reimu/bilibili/[email protected]/misc.go:96:16: maskCode (untyped int constant 2251799813685247) overflows int

@CuteReimu
Copy link
Owner

CuteReimu commented Jan 6, 2025

两个问题:

  1. 你这个工作流有报错: https://github.com/yangtfu/bilibili/actions/runs/12627589859/job/35182474234
  2. 这个release.yml里面也没见到有明确指定32位机,你确定这个工作流是在32位机进行的吗?

misc.go Outdated
Comment on lines 68 to 71
xorCode = 0x1552356C4CDB
maxAid int64 = 1 << 51
alphabet = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么这个 maxAid 要加 int64,上面这个 xorCode 不需要加, 0x1552356C4CDB显然至少要6个字节,也超过了32位机的int

Copy link
Owner

@CuteReimu CuteReimu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bilibili/misc_test.go

Lines 5 to 12 in 5e8ece7

func TestAvBv(t *testing.T) {
if Av2Bv(111298867365120) != "BV1L9Uoa9EUx" {
t.Fail()
}
if 111298867365120 != Bv2Av("BV1L9Uoa9EUx") {
t.Fail()
}
}

这个也得改,这传进去的这么大一个整数,在32位机也没法作为int传入。

@yangtfu yangtfu force-pushed the master branch 2 times, most recently from 618dd72 to 62dbe7b Compare January 6, 2025 08:14
@yangtfu
Copy link
Collaborator Author

yangtfu commented Jan 6, 2025

看了下gorelease文档:https://goreleaser.com/customization/builds/go/
更改了参数和返回类型为int64,看下这样是否可以?

@yangtfu yangtfu requested a review from CuteReimu January 6, 2025 08:22
@yangtfu
Copy link
Collaborator Author

yangtfu commented Jan 6, 2025

// Bv2Av 将bv号转换为av号,传入的bv号格式为"BV1xxxxxxxxx",前面的"BV"不区分大小写。
func Bv2Av(bvid string) int64 {
	if len(bvid) != 12 {
		panic("bvid 格式错误: " + bvid)
	}
	const (
		xorCode  = 0x1552356C4CDB
		maskCode = 1<<51 - 1
		alphabet = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"
	)
	var tmp = 0
	for _, e := range []int{9, 7, 5, 6, 4, 8, 3, 10, 11} {
		idx := (strings.IndexByte(alphabet, bvid[e]))
		tmp = tmp*(len(alphabet)) + idx
	}
	return int64((tmp & maskCode) ^ xorCode)
}

这里如果这样改依然会报错:

./misc.go:98:22: maskCode (untyped int constant 2251799813685247) overflows int

应该是常量声明声明时自动提升为int64

@CuteReimu
Copy link
Owner

你把函数参数给改了,不就breaking change了吗?如果非要所有函数全支持32位机,建议新增v3版本。
v2版本最初的设计就是不支持32位机,并且尽量用int,声明方便不容易出争议。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants