Skip to content

Commit

Permalink
新增弹幕midhash转用户uid
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengfei00 committed Jun 20, 2020
1 parent 33b7959 commit b58735d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# bilibili工具箱

##不断更新ing...


## 弹幕获取
```go
import "github/wnstar/bili-utils/api/dm"
Expand All @@ -14,3 +17,9 @@ import "github/wnstar/bili-utils/common"
fmt.Println(common.Bv2av("BV1XC4y1h78J"))
fmt.Println(common.Av2bv("795898202"))
```

## 弹幕midHash转用户uid
```go
import "github/wnstar/bili-utils/common"
fmt.Println(common.DmMidHash2Uid("a9ce8ef5"))
```
5 changes: 5 additions & 0 deletions api/dm/seg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/wnstar/gorequests"
"github/wnstar/bili-utils/common"
)

//go:generate protoc --go_out=./ bilibili.proto

func (d DanmakuElem) Uid() int64 {
return common.DmMidHash2Uid(d.MidHash)
}

func GetDm(cid string) []*DanmakuElem {
result := make([]*DanmakuElem, 0)
i := 0
Expand Down
12 changes: 12 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package common
import (
"fmt"
"github/wnstar/bili-utils/api/webInterface"
"hash/crc32"
"strconv"
)

func Bv2av(bv string) string {
Expand All @@ -28,3 +30,13 @@ func Av2bv(av string) string {
return ""
}
}

func DmMidHash2Uid(midHash string) int64 {
hashid := ""
i := int64(0)
for ; hashid != midHash; i++ {
s := crc32.ChecksumIEEE([]byte(strconv.FormatInt(i, 10)))
hashid = strconv.FormatInt(int64(s), 16)
}
return i
}
3 changes: 2 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package example
package main

import (
"fmt"
Expand All @@ -11,4 +11,5 @@ func main() {
fmt.Println(elements)
fmt.Println(common.Bv2av("BV1XC4y1h78J"))
fmt.Println(common.Av2bv("795898202"))
fmt.Println(common.DmMidHash2Uid("a9ce8ef5"))
}

0 comments on commit b58735d

Please sign in to comment.