82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"intimate"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/474420502/gcurl"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func main() {
|
|
bcurl := `curl 'https://www.mirrativ.com/api/live/catalog?id=2&cursor=%s' \
|
|
-H 'authority: www.mirrativ.com' \
|
|
-H 'accept: application/json' \
|
|
-H 'x-timezone: Asia/Shanghai' \
|
|
-H 'x-csrf-token: F3Ojd6RBtApP6YAZzVn-9jWN1of159VxAqOQL1Zn' \
|
|
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36' \
|
|
-H 'content-type: application/json' \
|
|
-H 'sec-fetch-site: same-origin' \
|
|
-H 'sec-fetch-mode: cors' \
|
|
-H 'sec-fetch-dest: empty' \
|
|
-H 'referer: https://www.mirrativ.com/' \
|
|
-H 'accept-language: zh-CN,zh;q=0.9,ja;q=0.8' \
|
|
-H 'cookie: f=A2D75F0E-D218-11EA-A042-452BF6D21CE8; _ga=GA1.2.689947597.1596081392; mr_id=kxb65LddGMZf5C28jkR_tGCZD_ZFOAepD5gfXO7eNjfPMB8EKYvU1Vg_Y29V1lsa; _gid=GA1.2.2116692650.1600139685; lang=ja' \
|
|
--compressed`
|
|
|
|
curl := gcurl.Parse(bcurl)
|
|
tp := curl.CreateTemporary(nil)
|
|
cursor := tp.QueryParam(`cursor`)
|
|
cursor.StringSet("")
|
|
|
|
for {
|
|
|
|
log.Println(tp.ParsedURL.String())
|
|
resp, err := tp.Execute()
|
|
if err != nil {
|
|
log.Println(err)
|
|
time.Sleep(time.Second * 2)
|
|
continue
|
|
}
|
|
|
|
apijson := gjson.ParseBytes(resp.Content())
|
|
next := apijson.Get("next_cursor").String()
|
|
|
|
for _, liveinfo := range apijson.Get("list").Array() {
|
|
var prekey string
|
|
if liveinfo.Get("live_preview").Exists() {
|
|
prekey = "live_preview"
|
|
} else {
|
|
prekey = "live"
|
|
}
|
|
owner := liveinfo.Get(prekey + ".owner")
|
|
if guserid := owner.Get("user_id"); guserid.String() != "" {
|
|
streamer := &intimate.Streamer{}
|
|
streamer.Platform = intimate.PMirrativ
|
|
streamer.Operator = 0
|
|
streamer.UserId = &guserid.Str
|
|
streamer.UserName = &sql.NullString{String: liveinfo.Get("name").String(), Valid: true}
|
|
streamer.UpdateInterval = 60
|
|
streamer.UpdateTime = intimate.GetUpdateTimeNow()
|
|
|
|
err = intimate.TStreamer.InsertOrUpdate(
|
|
streamer,
|
|
intimate.DUpdate{Field: "update_time"},
|
|
)
|
|
if err != nil {
|
|
log.Println(err)
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
if next == "" {
|
|
time.Sleep(time.Minute * 5)
|
|
} else {
|
|
time.Sleep(time.Second * 2)
|
|
}
|
|
cursor.StringSet(next)
|
|
}
|
|
}
|