From bc1985c1460511a1400a58647ca3d9ff7afdf800 Mon Sep 17 00:00:00 2001 From: qydysky Date: Fri, 21 May 2021 17:04:17 +0800 Subject: [PATCH] =?utf8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=90=9C=E7=B4=A2?= =?utf8?q?=E4=B8=BB=E6=92=AD=E7=9B=B4=E6=92=AD=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-- F/cmd.go | 22 +++++++++++++++++++ Json/search.go | 48 ++++++++++++++++++++++++++++++++++++++++ README.md | 14 ++++++++---- 4 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 Json/search.go diff --git a/F/api.go b/F/api.go index 47121b8..2dfecdf 100644 --- a/F/api.go +++ b/F/api.go @@ -4,7 +4,7 @@ import ( "time" "os" "strconv" - // "strings" + "strings" "context" "encoding/json" "net/http" @@ -30,7 +30,7 @@ var apilog = c.Log.Base(`api`) var api_limit = limit.New(1,2000,30000)//频率限制1次/2s,最大等待时间30s func Get(key string) { - apilog := apilog.Base_add(`Get`).L(`T: `,key) + apilog := apilog.Base_add(`Get`) if api_limit.TO() {return}//超额请求阻塞,超时将取消 @@ -195,6 +195,7 @@ func Get(key string) { if fList,ok := api_can_get[key];ok{ for _,fItem := range fList{ + apilog.L(`T: `, `Get`, key) missKey := fItem() if len(missKey) > 0 { apilog.L(`T: `,`missKey when get`,key,missKey) @@ -2417,6 +2418,60 @@ func GetHistory(Roomid_int int) (j J.GetHistory) { return } +type searchresult struct{ + Roomid int + Uname string + Is_live bool +} + +func SearchUP(s string) (list []searchresult) { + apilog := apilog.Base_add(`搜索主播`) + if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消 + + {//使用其他api + req := reqf.New() + if err := req.Reqf(reqf.Rval{ + Url:"https://api.bilibili.com/x/web-interface/search/type?context=&search_type=live_user&cover_type=user_cover&page=1&order=&category_id=&__refresh__=true&_extra=&highlight=1&single_column=0&keyword=" + url.PathEscape(s), + Proxy:c.Proxy, + Timeout:10*1000, + Retry:2, + });err != nil { + apilog.L(`E: `,err) + return + } + + var j J.Search + + //Search + { + if e := json.Unmarshal(req.Respon,&j);e != nil{ + apilog.L(`E: `, e) + return + } else if j.Code != 0 { + apilog.L(`E: `, j.Message) + return + } + } + + if j.Data.Numresults == 0 { + apilog.L(`I: `,`没有匹配`);return + } + + for i:=0;i`,``) + uname = strings.ReplaceAll(uname, ``,``) + list = append(list, searchresult{ + Roomid: j.Data.Result[i].Roomid, + Uname: uname, + Is_live: j.Data.Result[i].IsLive, + }) + } + + } + + return +} + func KeepConnect() (o bool) { for !IsConnected() { o = true diff --git a/F/cmd.go b/F/cmd.go index e9c65a8..0ec2416 100644 --- a/F/cmd.go +++ b/F/cmd.go @@ -31,6 +31,7 @@ func Cmd() { } else { fmt.Println("登陆->输入' login'回车") } + fmt.Println("搜索主播->输入' search关键词'回车") fmt.Println("房间信息->输入' room'回车") fmt.Println("开始结束录制->输入' rec'回车") fmt.Println("其他输出隔断不影响") @@ -93,6 +94,27 @@ func Cmd() { continue } + //搜索主播 + if strings.Contains(inputs, ` search`) { + if len(inputs) == 7 { + cmdlog.L(`W: `, "未输入搜索内容") + continue + } + + fmt.Print("\n") + for k,v := range SearchUP(inputs[7:]) { + liveList[` live`+strconv.Itoa(k)] = v.Roomid + if v.Is_live { + fmt.Println(k, `✔`, v.Uname, `(直播中)`) + } else { + fmt.Println(k, `✘`, v.Uname, `(未直播)`) + } + } + fmt.Println("回复' live(序号)'进入直播间") + fmt.Print("\n") + + continue + } //当前直播间信息 if strings.Contains(inputs, ` room`) { fmt.Print("\n") diff --git a/Json/search.go b/Json/search.go new file mode 100644 index 0000000..132890e --- /dev/null +++ b/Json/search.go @@ -0,0 +1,48 @@ +package part + +type Search struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data struct { + Seid string `json:"seid"` + Page int `json:"page"` + Pagesize int `json:"pagesize"` + Numresults int `json:"numResults"` + Numpages int `json:"numPages"` + SuggestKeyword string `json:"suggest_keyword"` + RqtType string `json:"rqt_type"` + CostTime struct { + ParamsCheck string `json:"params_check"` + IllegalHandler string `json:"illegal_handler"` + DeserializeResponse string `json:"deserialize_response"` + AsResponseFormat string `json:"as_response_format"` + AsRequest string `json:"as_request"` + SaveCache string `json:"save_cache"` + AsDocRequest string `json:"as_doc_request"` + AsRequestFormat string `json:"as_request_format"` + Total string `json:"total"` + MainHandler string `json:"main_handler"` + } `json:"cost_time"` + ExpList interface{} `json:"exp_list"` + EggHit int `json:"egg_hit"` + Result []struct { + RankOffset int `json:"rank_offset"` + UID int `json:"uid"` + Tags string `json:"tags"` + Type string `json:"type"` + LiveTime string `json:"live_time"` + HitColumns []string `json:"hit_columns"` + LiveStatus int `json:"live_status"` + Area int `json:"area"` + IsLive bool `json:"is_live"` + Uname string `json:"uname"` + Uface string `json:"uface"` + RankIndex int `json:"rank_index"` + RankScore int `json:"rank_score"` + Roomid int `json:"roomid"` + Attentions int `json:"attentions"` + } `json:"result"` + ShowColumn int `json:"show_column"` + } `json:"data"` +} \ No newline at end of file diff --git a/README.md b/README.md index 2520c99..3c35b42 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ I: 2021/04/13 20:04:56 命令行操作 [分区排行: 50+ 人气: 41802746] I: 2021/04/13 20:04:56 命令行操作 [直播Web服务: http://192.168.31.245:38259] ``` -还支持登录、唤起获取小心心等功能 +还支持登录、唤起获取小心心、搜索主播直播间等功能 #### cookie加密 保护cookie.txt @@ -255,9 +255,15 @@ release默认编译tts ``` {D}:为tts内容 key为demo/face下的文件名 -{ - "0multi": "观众:{D}", - "29183321":"{D}" +"onoff":{ + "help":"空字符串将不触发,{D}会被替换", + "0buyguide": "感谢{D}" +} + +有些无法被tts引擎阅读的符号可以在此项中替换 +"replace":{ + "?":"问号", + "?":"问号" } ``` #### 弹幕窗 -- 2.39.2