/
tool.go
61 lines (49 loc) · 1.69 KB
/
tool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package spider
import (
"strings"
"github.com/A-SoulFan/asasfans-api/internal/app/asasapi/spider/video_analysis"
"github.com/A-SoulFan/asasfans-api/internal/pkg/bilibili"
)
const (
allowMinScore = 80
allowTags = "嘉然,向晚,贝拉,珈乐,乃琳,阿草,嘉心糖,嘉然今天吃什么,A-SOUL,a-soul,传说的世界,向晚大魔王,顶晚人,乃琳Queen,乃淇琳,贝拉kira,贝极星,珈乐Carol,ASOUL,asoul,GNK48,超级敏感,传说的世界,A-SOUL二创激励计划,乃贝,嘉晚饭,果丹皮,琳嘉"
)
func calculateScore(info *bilibili.VideoInfoResponse) uint64 {
score := float64(info.Stat.View)*0.25 +
float64(info.Stat.Like+info.Stat.Coin+info.Stat.Reply+info.Stat.Like)*0.4 +
float64(info.Stat.Favorite)*0.3 +
float64(info.Stat.Share)*0.6
return uint64(score)
}
// isSkip 判断是否需要跳过此条
// 防止错误的收录不属于 keyword 的内容
func isSkip(tags []string, mid string, analysis *video_analysis.Analysis) bool {
score := analysis.Calculate(video_analysis.Mid, mid)
// 黑名单用户
if score < 0 {
return true
}
for _, tag := range tags {
score += analysis.Calculate(video_analysis.Tag, tag)
}
return score <= allowMinScore
}
func tagStrToSlice(tagStr, title string) []string {
tagStr = strings.Replace(tagStr, "['", "", -1)
tagStr = strings.Replace(tagStr, "']", "", -1)
tagStr = strings.Replace(tagStr, title, "", -1)
tags := make([]string, 0, 5)
for _, tag := range strings.Split(tagStr, ",") {
if l := len(tag); l < 1 || l > 30 {
continue
}
tags = append(tags, preTag(tag))
}
return tags
}
func preTag(tag string) string {
for _, s := range []string{"[", "]", "'", "#", " "} {
tag = strings.Replace(tag, s, "", -1)
}
return tag
}