2020-07-08 07:02:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-07-20 10:13:54 +00:00
|
|
|
"encoding/json"
|
2020-07-08 07:02:55 +00:00
|
|
|
"intimate"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2020-08-13 11:11:53 +00:00
|
|
|
"github.com/474420502/gcurl"
|
2020-07-09 09:09:46 +00:00
|
|
|
"github.com/tidwall/gjson"
|
2020-07-08 07:02:55 +00:00
|
|
|
)
|
|
|
|
|
2020-09-08 10:24:51 +00:00
|
|
|
// // sstore 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql
|
|
|
|
// var sstore *intimate.StoreSource = intimate.NewStoreSource(string(intimate.STOpenrec))
|
2020-07-20 10:13:54 +00:00
|
|
|
|
2020-09-08 10:24:51 +00:00
|
|
|
// // estore 解析存储连接实例
|
|
|
|
// var estore *intimate.StoreExtractor = intimate.NewStoreExtractor()
|
2020-07-08 07:02:55 +00:00
|
|
|
|
2020-08-13 11:11:53 +00:00
|
|
|
// Execute 执行方法
|
|
|
|
func Execute() {
|
2020-07-08 07:02:55 +00:00
|
|
|
|
2020-08-13 11:11:53 +00:00
|
|
|
ps := intimate.NewPerfectShutdown()
|
|
|
|
turl := `curl 'https://public.openrec.tv/external/api/v5/channel-ranks?period=monthly&date=&tag=&page=1' \
|
2020-07-08 07:02:55 +00:00
|
|
|
-H 'authority: public.openrec.tv' \
|
|
|
|
-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 'origin: https://www.openrec.tv' \
|
|
|
|
-H 'sec-fetch-site: same-site' \
|
|
|
|
-H 'sec-fetch-mode: cors' \
|
|
|
|
-H 'sec-fetch-dest: empty' \
|
|
|
|
-H 'referer: https://www.openrec.tv/ranking' \
|
|
|
|
-H 'accept-language: zh-CN,zh;q=0.9' \
|
|
|
|
-H 'if-none-match: W/"25edb-aUYBdmLqZcr6DW4ZWKX9r2aqolg"' \
|
|
|
|
--compressed`
|
|
|
|
|
2020-08-28 11:07:12 +00:00
|
|
|
g := gcurl.Parse(turl)
|
2020-08-13 11:11:53 +00:00
|
|
|
tp := g.Temporary()
|
2020-07-16 10:31:13 +00:00
|
|
|
|
2020-08-13 11:11:53 +00:00
|
|
|
for !ps.IsClose() {
|
2020-07-08 07:02:55 +00:00
|
|
|
|
2020-08-13 11:11:53 +00:00
|
|
|
resp, err := tp.Execute()
|
2020-07-08 07:02:55 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2020-07-17 11:20:08 +00:00
|
|
|
time.Sleep(time.Second * 2)
|
|
|
|
continue
|
2020-07-08 07:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
content := resp.Content()
|
2020-07-27 11:30:54 +00:00
|
|
|
if len(content) <= 200 { //末页时没有内容返回, 末页退出
|
2020-07-17 10:21:38 +00:00
|
|
|
finishpoint := time.Now()
|
2020-07-23 10:29:56 +00:00
|
|
|
log.Println("任务Ranking UserId结束休眠, 下次启动时间:", finishpoint.Add(time.Minute*120))
|
|
|
|
for time.Now().Sub(finishpoint) < time.Minute*120 {
|
2020-07-17 10:21:38 +00:00
|
|
|
time.Sleep(time.Second)
|
2020-08-13 11:11:53 +00:00
|
|
|
if ps.IsClose() {
|
2020-07-17 10:21:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-07-20 10:13:54 +00:00
|
|
|
|
2020-07-21 07:05:56 +00:00
|
|
|
log.Println("获取Ranking UserId启动:", time.Now())
|
2020-07-20 10:13:54 +00:00
|
|
|
querys := tp.GetQuery()
|
|
|
|
querys.Set("page", strconv.Itoa(1))
|
|
|
|
tp.SetQuery(querys)
|
|
|
|
|
2020-07-17 10:21:38 +00:00
|
|
|
continue
|
2020-07-08 07:02:55 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 09:09:46 +00:00
|
|
|
result := gjson.ParseBytes(content)
|
|
|
|
if result.IsArray() {
|
|
|
|
for _, User := range result.Array() {
|
2020-07-20 10:13:54 +00:00
|
|
|
|
2020-07-09 09:09:46 +00:00
|
|
|
userid := User.Get("channel.id").String()
|
2020-07-20 10:13:54 +00:00
|
|
|
streamer := &intimate.Streamer{}
|
2020-09-08 10:24:51 +00:00
|
|
|
streamer.UserId = &userid
|
2020-07-23 10:29:56 +00:00
|
|
|
streamer.Platform = intimate.Popenrec
|
2020-07-20 10:13:54 +00:00
|
|
|
|
|
|
|
updateUrl := make(map[string]interface{})
|
|
|
|
|
2020-07-21 07:05:56 +00:00
|
|
|
supportersUrl := "curl '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"
|
2020-07-20 10:13:54 +00:00
|
|
|
updateUrl["supporters"] = supportersUrl
|
|
|
|
updateUrl["user"] = "https://www.openrec.tv/user/" + userid
|
|
|
|
updateUrl["live"] = "https://www.openrec.tv/live/" + userid
|
|
|
|
|
|
|
|
updateUrlBytes, err := json.Marshal(updateUrl)
|
|
|
|
if err != nil {
|
2020-09-08 10:24:51 +00:00
|
|
|
intimate.TStreamer.UpdateError(streamer, err)
|
2020-07-20 10:13:54 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
streamer.UpdateUrl = updateUrlBytes
|
2020-09-08 10:24:51 +00:00
|
|
|
intimate.TStreamer.Insert(streamer)
|
2020-07-09 09:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 07:02:55 +00:00
|
|
|
|
2020-09-08 10:24:51 +00:00
|
|
|
log.Println("streamer count:", len(result.Array()), tp.ParsedURL.String())
|
2020-07-27 11:30:54 +00:00
|
|
|
// 修改url query 参数的page递增. 遍历所有页面
|
2020-08-13 11:11:53 +00:00
|
|
|
tp.QueryParam("page").IntAdd(1)
|
2020-07-20 10:13:54 +00:00
|
|
|
time.Sleep(time.Second * 1)
|
2020-07-08 07:02:55 +00:00
|
|
|
}
|
|
|
|
}
|