package main import ( "database/sql" "encoding/json" "intimate" "log" "os" "os/signal" "strconv" "sync/atomic" "syscall" "time" "github.com/474420502/gcurl" "github.com/tidwall/gjson" "github.com/474420502/hunter" ) var oer *OpenrecExtratorRanking // store 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql var store *intimate.SourceStore = intimate.NewSourceStore(string(intimate.STOpenrec)) func init() { oer = &OpenrecExtratorRanking{} } // OpenrecExtratorRanking 获取用户信息 type OpenrecExtratorRanking struct { // Store *intimate.Store } // Execute 执行方法 func (oer *OpenrecExtratorRanking) Execute(cxt *hunter.TaskContext) { var loop int32 = 1 go func() { signalchan := make(chan os.Signal) signal.Notify(signalchan, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP) log.Println("accept stop command:", <-signalchan) atomic.StoreInt32(&loop, 0) }() for atomic.LoadInt32(&loop) > 0 { source, err := store.Pop(string(intimate.TTOpenrecUser)) if source == nil || err != nil { log.Println(err) time.Sleep(time.Second * 2) continue } userSource := &intimate.Source{} userid := source.GetSource().String userUrl := "https://www.openrec.tv/user/" + userid userSource.SetUrl(userUrl) wf := cxt.Session().Get(userUrl) resp, err := wf.Execute() source.SetUpdateTime(sql.NullTime{Time: time.Now(), Valid: true}) if err != nil { log.Println(err) store.UpdateError(source, err) continue } cookies := cxt.Session().GetCookies(wf.GetParsedURL()) scurl := "https://www.openrec.tv/viewapp/api/v6/supporters?identify_id=sumomo_xqx&month=&Uuid=B96EE988-E3A2-4A44-A543-611A8B4BC683&Token=46598c320408bd69ae3c63298f6f4a3a97354175&Random=AZVXNAAXQVMOSVWNDPIQ&page_number=1 -H 'accept: application/json, text/javascript, */*; q=0.01' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' -H 'cookie: uuid=B96EE988-E3A2-4A44-A543-611A8B4BC683;' --compressed" curl := gcurl.ParseRawCURL(scurl) supportersSession := curl.CreateSession() temporary := curl.CreateTemporary(supportersSession) supportersSession.SetCookies(temporary.GetParsedURL(), cookies) var supporters []string for { supportersQuery := temporary.GetQuery() for _, cookie := range cookies { if cookie.Name == "uuid" { supportersQuery.Set("Uuid", cookie.Value) continue } if cookie.Name == "token" { supportersQuery.Set("Token", cookie.Value) continue } if cookie.Name == "random" { supportersQuery.Set("Random", cookie.Value) continue } } supportersQuery.Set("identify_id", source.GetSource().String) temporary.SetQuery(supportersQuery) resp, err := temporary.Execute() if err != nil { log.Println(err) } supporterjson := gjson.ParseBytes(resp.Content()) supporterdata := supporterjson.Get("data") if supporterdata.Type == gjson.Null { break } supporters = append(supporters, string(resp.Content())) page := supportersQuery.Get("page_number") pageint, err := strconv.Atoi(page) if err != nil { log.Println(err) break } pageint++ page = strconv.Itoa(pageint) supportersQuery.Set("page_number", page) temporary.SetQuery(supportersQuery) } // cookies := cxt.Session().GetCookies(wf.GetParsedURL()) ext := make(map[string]interface{}) ext["supporters"] = supporters ext["user"] = string(resp.Content()) wf = cxt.Session().Get("https://www.openrec.tv/live/" + userid) resp, err = wf.Execute() if err != nil { log.Println(err) store.UpdateError(source, err) continue } ext["user_live"] = string(resp.Content()) extJsonBytes, err := json.Marshal(ext) if err != nil { log.Println(err) store.UpdateError(source, err) continue } source.SetOperator(int32(intimate.OperatorOK)) source.SetExt(string(extJsonBytes)) store.Update(source) } }