39
39
searchDynamicRe = regexp .MustCompile (searchDynamic )
40
40
searchArticleRe = regexp .MustCompile (searchArticle )
41
41
searchLiveRoomRe = regexp .MustCompile (searchLiveRoom )
42
+ cachePath string
42
43
)
43
44
44
45
// 插件主体
@@ -48,14 +49,13 @@ func init() {
48
49
Brief : "b站链接解析" ,
49
50
Help : "例:- t.bilibili.com/642277677329285174\n - bilibili.com/read/cv17134450\n - bilibili.com/video/BV13B4y1x7pS\n - live.bilibili.com/22603245 " ,
50
51
})
51
- cachePath : = en .DataFolder () + "cache/"
52
+ cachePath = en .DataFolder () + "cache/"
52
53
_ = os .RemoveAll (cachePath )
53
54
_ = os .MkdirAll (cachePath , 0755 )
54
55
en .OnRegex (`((b23|acg).tv|bili2233.cn)\\?/[0-9a-zA-Z]+` ).SetBlock (true ).Limit (limit .LimitByGroup ).
55
56
Handle (func (ctx * zero.Ctx ) {
56
57
u := ctx .State ["regex_matched" ].([]string )[0 ]
57
58
u = strings .ReplaceAll (u , "\\ " , "" )
58
- ctx .State ["cache_path" ] = cachePath
59
59
realurl , err := bz .GetRealURL ("https://" + u )
60
60
if err != nil {
61
61
ctx .SendChain (message .Text ("ERROR: " , err ))
@@ -105,22 +105,10 @@ func init() {
105
105
}
106
106
ctx .SendChain (message .Text ("已" , option , "视频总结" ))
107
107
})
108
- en .OnRegex (searchVideo , func (ctx * zero.Ctx ) bool {
109
- ctx .State ["cache_path" ] = cachePath
110
- return true
111
- }).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleVideo )
112
- en .OnRegex (searchDynamic , func (ctx * zero.Ctx ) bool {
113
- ctx .State ["cache_path" ] = cachePath
114
- return true
115
- }).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleDynamic )
116
- en .OnRegex (searchArticle , func (ctx * zero.Ctx ) bool {
117
- ctx .State ["cache_path" ] = cachePath
118
- return true
119
- }).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleArticle )
120
- en .OnRegex (searchLiveRoom , func (ctx * zero.Ctx ) bool {
121
- ctx .State ["cache_path" ] = cachePath
122
- return true
123
- }).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleLive )
108
+ en .OnRegex (searchVideo ).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleVideo )
109
+ en .OnRegex (searchDynamic ).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleDynamic )
110
+ en .OnRegex (searchArticle ).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleArticle )
111
+ en .OnRegex (searchLiveRoom ).SetBlock (true ).Limit (limit .LimitByGroup ).Handle (handleLive )
124
112
}
125
113
126
114
func handleVideo (ctx * zero.Ctx ) {
@@ -148,7 +136,6 @@ func handleVideo(ctx *zero.Ctx) {
148
136
}
149
137
}
150
138
ctx .SendChain (msg ... )
151
- cachePath := ctx .State ["cache_path" ].(string )
152
139
downLoadMsg , err := getVideoDownload (cfg , card , cachePath )
153
140
if err != nil {
154
141
ctx .SendChain (message .Text ("ERROR: " , err ))
@@ -256,7 +243,7 @@ func getVideoDownload(cookiecfg *bz.CookieConfig, card bz.Card, cachePath string
256
243
cmd .Stderr = & stderr
257
244
err = cmd .Run ()
258
245
if err != nil {
259
- err = errors .Errorf ("未配置ffmpeg,%s " , stderr . String () )
246
+ err = errors .Errorf ("未配置ffmpeg,%v " , stderr )
260
247
return
261
248
}
262
249
msg = append (msg , message .Video ("file:///" + file .BOTPATH + "/" + videoFile ))
0 commit comments