This commit is contained in:
poiuty 2022-08-15 12:27:38 +03:00
parent dad37ec59b
commit 30e7296135
3 changed files with 29 additions and 34 deletions

View file

@ -14,6 +14,7 @@ var memInfo runtime.MemStats
type Info struct { type Info struct {
ch chan struct{} ch chan struct{}
room string room string
Id string `json:"id"`
Server string `json:"server"` Server string `json:"server"`
Proxy string `json:"proxy"` Proxy string `json:"proxy"`
Online string `json:"online"` Online string `json:"online"`
@ -74,11 +75,12 @@ func cmdHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
params := r.URL.Query() params := r.URL.Query()
if len(params["room"]) > 0 && len(params["server"]) > 0 && len(params["proxy"]) > 0 { if len(params["room"]) > 0 && len(params["id"]) > 0 && len(params["proxy"]) > 0 {
now := time.Now().Unix() now := time.Now().Unix()
workerData := Info{ workerData := Info{
room: params["room"][0], room: params["room"][0],
Server: params["server"][0], Id: params["id"][0],
Server: "",
Proxy: params["proxy"][0], Proxy: params["proxy"][0],
Online: "0", Online: "0",
Start: now, Start: now,

View file

@ -113,9 +113,10 @@ func fastStart() {
if now > v.Last+60*20 { if now > v.Last+60*20 {
continue continue
} }
fmt.Println("fastStart:", k, v.Server, v.Proxy) fmt.Println("fastStart:", k, v.Id, v.Proxy)
workerData := Info{ workerData := Info{
room: k, room: k,
Id: v.Id,
Server: v.Server, Server: v.Server,
Proxy: v.Proxy, Proxy: v.Proxy,
Online: v.Online, Online: v.Online,

View file

@ -74,7 +74,7 @@ func mapRooms() {
for { for {
select { select {
case m := <-rooms.Add: case m := <-rooms.Add:
data[m.room] = &Info{Server: m.Server, Proxy: m.Proxy, Start: m.Start, Last: m.Last, Online: m.Online, Income: m.Income, Dons: m.Dons, Tips: m.Tips, ch: m.ch} data[m.room] = &Info{Id: m.Id, Server: m.Server, Proxy: m.Proxy, Start: m.Start, Last: m.Last, Online: m.Online, Income: m.Income, Dons: m.Dons, Tips: m.Tips, ch: m.ch}
case s := <-rooms.Json: case s := <-rooms.Json:
j, err := json.Marshal(data) j, err := json.Marshal(data)
@ -117,51 +117,35 @@ func announceCount() {
} }
} }
func getToken(room string) (*url.URL, string) { func getToken(room string) string {
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "https://ru.stripchat.com/"+room, nil) req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "https://stripchat.com/"+room, nil)
if err != nil { if err != nil {
return &url.URL{}, "cantGetToken" return "cant get req"
} }
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0") req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0")
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
req.Header.Add("Accept-Language", "en-US,en;q=0.5") req.Header.Add("Accept-Language", "en-US,en;q=0.5")
req.Header.Add("Connection", "keep-alive") req.Header.Add("Connection", "keep-alive")
req.Header.Add("Referer", "https://ru.stripchat.com") req.Header.Add("Referer", "https://stripchat.com")
rsp, err := http.DefaultClient.Do(req) rsp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil || rsp.StatusCode != http.StatusOK {
return &url.URL{}, "cantGetToken" return "cant get page"
} else if rsp.StatusCode != http.StatusOK {
return &url.URL{}, "cantGetToken"
} }
defer rsp.Body.Close() defer rsp.Body.Close()
buf, err := ioutil.ReadAll(rsp.Body) buf, err := ioutil.ReadAll(rsp.Body)
if err != nil { if err != nil {
return &url.URL{}, "cantGetToken" return "cant read page"
} }
re := regexp.MustCompile(`"websocketUrl":"*(.*?)\s*"`) re := regexp.MustCompile(`"websocketUrl":"*(.*?)\s*"`)
m := re.FindSubmatch(buf) m := re.FindSubmatch(buf)
if len(m) != 2 { if len(m) != 2 {
return &url.URL{}, "cantGetToken" return "cant get ws"
} }
r := bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`)) return string(bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`)))
u, err := url.Parse(string(r))
if err != nil {
return &url.URL{}, "cantGetToken"
}
re = regexp.MustCompile(`img.strpst.com/thumbs/*(.*?)\s*"`)
id := re.FindSubmatch(buf)
if len(id) != 2 {
return &url.URL{}, "cantGetToken"
}
xid := string(id[1])
return u, xid[strings.Index(xid, "/")+1:]
} }
func xWorker(workerData Info) { func xWorker(workerData Info) {
fmt.Println("Start", workerData.room, "server", workerData.Server, "proxy", workerData.Proxy) fmt.Println("Start", workerData.room, "id", workerData.Id, "proxy", workerData.Proxy)
rooms.Add <- workerData rooms.Add <- workerData
@ -169,9 +153,16 @@ func xWorker(workerData Info) {
rooms.Del <- workerData.room rooms.Del <- workerData.room
}() }()
u, id := getToken(workerData.room) xurl := workerData.Server
if id == "cantGetToken" {
fmt.Println("cantGetToken", workerData.room) if xurl == "" {
xurl = getToken(workerData.room)
workerData.Server = xurl
}
u, err := url.Parse(xurl)
if err != nil {
fmt.Println(xurl, err, workerData.room)
return return
} }
@ -194,7 +185,7 @@ func xWorker(workerData Info) {
c, _, err := Dialer.Dial(u.String(), nil) c, _, err := Dialer.Dial(u.String(), nil)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error(), u.String(), workerData.room)
return return
} }
@ -225,6 +216,7 @@ func xWorker(workerData Info) {
rooms.Add <- workerData rooms.Add <- workerData
if m.SubscriptionKey == "connected" { if m.SubscriptionKey == "connected" {
id := workerData.Id
messages := [][]byte{} messages := [][]byte{}
messages = append(messages, []byte(`{"id":"1660248194970-sub-lotteryChanged","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/lotteryChanged"}`)) messages = append(messages, []byte(`{"id":"1660248194970-sub-lotteryChanged","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/lotteryChanged"}`))
messages = append(messages, []byte(`{"id":"1660248194970-sub-userBanned:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/userBanned:`+id+`"}`)) messages = append(messages, []byte(`{"id":"1660248194970-sub-userBanned:`+id+`","method":"PUT","url":"/front/clients/`+m.Params.ClientId+`/subscriptions/userBanned:`+id+`"}`))