cookieLock sync.RWMutex
)
-func CookieGet() []byte {
+func CookieGet(path string) []byte {
clog := clog.Base_add(`获取`)
cookieLock.RLock()
pri = d
}
} else {
- if d, e := FileLoad(`cookie.txt`); e != nil {
+ if d, e := FileLoad(path); e != nil {
clog.L(`E: `, e, `cookie保存格式`)
return []byte{}
} else if string(d[:6]) == `t=nol;` {
}
}
}
- if d, e := FileLoad(`cookie.txt`); e != nil {
+ if d, e := FileLoad(path); e != nil {
clog.L(`E: `, e, `cookie保存格式`)
return []byte{}
} else if string(d[:6]) == `t=pem;` {
}
}
-func CookieSet(source []byte) {
+func CookieSet(path string, source []byte) {
clog := clog.Base_add(`设置`)
cookieLock.Lock()
pub = d
}
} else {
- f := file.New(`cookie.txt`, 0, true)
+ f := file.New(path, 0, true)
_ = f.Delete()
_, _ = f.Write(append([]byte("t=nol;"), source...), true)
return
clog.L(`E: `, e)
return
} else {
- f := file.New(`cookie.txt`, 0, true)
+ f := file.New(path, 0, true)
_ = f.Delete()
_, _ = f.Write(append([]byte("t=pem;"), source...), true)
}
}
}()
- if file.New("cookie.txt", 0, true).IsExist() { //读取cookie文件
- if cookieString := string(CookieGet()); cookieString != `` {
+ savepath := "./cookie.txt"
+ if tmp, ok := t.K_v.LoadV("cookie路径").(string); ok && tmp != "" {
+ savepath = tmp
+ }
+
+ if file.New(savepath, 0, true).IsExist() { //读取cookie文件
+ if cookieString := string(CookieGet(savepath)); cookieString != `` {
for k, v := range reqf.Cookies_String_2_Map(cookieString) { //cookie存入全局变量syncmap
t.Cookie.Store(k, v)
}
var ErrNoCookiesSave = errors.New("ErrNoCookiesSave")
-func save_cookie(Cookies []*http.Cookie, cs ...*c.Common) error {
+func save_cookie(Cookies []*http.Cookie, cs *c.Common) error {
if len(Cookies) == 0 {
return ErrNoCookiesSave
}
for k, v := range reqf.Cookies_List_2_Map(Cookies) {
c.C.Cookie.Store(k, v)
- for i := 0; i < len(cs); i++ {
- cs[i].Cookie.Store(k, v)
- }
}
Cookie := make(map[string]string)
Cookie[k.(string)] = v.(string)
return true
})
- CookieSet([]byte(reqf.Map_2_Cookies_String(Cookie)))
+
+ savepath := "./cookie.txt"
+ if tmp, ok := cs.K_v.LoadV("cookie路径").(string); ok && tmp != "" {
+ savepath = tmp
+ }
+ CookieSet(savepath, []byte(reqf.Map_2_Cookies_String(Cookie)))
biliApi.SetCookies(Cookies)
return nil
}
### 说明
本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml)
+#### cookie自定义位置
+配置文件添加配置项`cookie路径`(>v0.14.26),默认为`./cookie.txt`
+
#### 获取视频切片
当请求`http://{Web服务地址}{直播Web服务路径}stream?ref={录播文件夹名}&st={起始时间}&dur={片段时长}`时,将返回从录播文件的切片视频(>v0.14.21)
""
],
"自动弹幕机_发送间隔s": 30,
+ "cookie路径-help": "为空时,为程序所在目录./cookie.txt",
+ "cookie路径": "./cookie.txt",
"cookie保护": "下填路径",
"cookie加密公钥": "public.pem",
"cookie解密私钥": "private.pem",