add stripchat

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Vasiliy Tolstov 2022-08-11 15:12:43 +03:00
parent 53e34904b0
commit 2eaee311f2
2 changed files with 70 additions and 113 deletions

View file

@ -1,9 +1,14 @@
package main package main
import ( import (
"os" "bytes"
"context"
"fmt" "fmt"
"io/ioutil"
"net/http"
"net/url" "net/url"
"os"
"regexp"
) )
func main() { func main() {
@ -16,7 +21,44 @@ func main() {
server := os.Args[2] server := os.Args[2]
proxy := os.Args[3] proxy := os.Args[3]
u := url.URL{Scheme: "wss", Host: server + ".bcccdn.com", Path: "/websocket"} u := getToken(room)
startRoom(room, server, proxy, u) startRoom(room, server, proxy, u)
} }
func getToken(room string) *url.URL {
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "https://ru.stripchat.com/"+room, nil)
if err != nil {
panic(err)
}
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-Language", "en-US,en;q=0.5")
req.Header.Add("Connection", "keep-alive")
req.Header.Add("Referer", "https://ru.stripchat.com")
rsp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
} else if rsp.StatusCode != http.StatusOK {
panic("failed to get rsp")
}
defer rsp.Body.Close()
buf, err := ioutil.ReadAll(rsp.Body)
if err != nil {
panic(err)
}
re := regexp.MustCompile(`"websocketUrl":"*(.*?)\s*"`)
m := re.FindSubmatch(buf)
if len(m) != 2 {
panic("not match")
}
r := bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`))
u, err := url.Parse(string(r))
if err != nil {
panic(err)
}
return u
}

View file

@ -1,85 +1,42 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
type AuthResponse struct {
Status string `json:"status"`
LocalData struct {
DataKey string `json:"dataKey"`
} `json:"localData"`
UserData struct {
Username string `json:"username"`
DisplayName string `json:"displayName"`
Location string `json:"location"`
Chathost string `json:"chathost"`
IsRu bool `json:"isRu"`
} `json:"userData"`
}
type ServerResponse struct { type ServerResponse struct {
TS int64 `json:"ts"` // {"id":"1660218639317-sub-viewServerChanged:hls-07","status":200,"body":""}
Type string `json:"type"` // {"subscriptionKey":"global","params":{"subscriptionKey":"clearChatMessages","params":{"senderIds":[80825678]}}}
Body json.RawMessage `json:"body"` // {"id":"1660218639317-sub-viewServerChanged:hls-07","method":"PUT","url":"/front/clients/9gd4q9r0/subscriptions/viewServerChanged:hls-07"}
// {"subscriptionKey":"global","params":{"subscriptionKey":"clearChatMessages","params":{"senderIds":[80825678]}}}
// {"subscriptionKey":"newChatMessage:36500801","params":{"message":{"cacheId":"62f4ed9872be2","modelId":36500801,"senderId":36500801,"type":"lovense","details":{"lovenseDetails":{"type":"tip","status":"","text":"","detail":{"name":"land-marks","amount":15,"time":5,"power":"medium"}},"fanClubTier":null,"fanClubNumberMonthsOfSubscribed":0},"userData":{"id":36500801,"username":"DoviaClaire","gender":"female","hasAdminBadge":false,"isAdmin":false,"isSupport":false,"isModel":true,"isStudio":false,"isGold":false,"isUltimate":false,"isGreen":false,"isRegular":false,"isExGreen":false,"hasVrDevice":false,"userRanking":null,"isKing":false,"isKnight":false,"isStudioModerator":false,"isStudioAdmin":false},"createdAt":"2022-08-11T11:52:56Z","additionalData":[],"id":1740865563732962}}}
SubscriptionKey string `json:"subscriptionKey,omitempty"`
Params struct {
Message struct {
Details struct {
LovenseDetails struct {
Type string `json:"type,omitempty"`
Detail struct {
Name string `json:"name,omitempty"`
Amount float64 `json:"amount,omitepty"`
} `json:"detail,omitempty"`
} `json:"lovenseDetails"`
} `json:"details,omitempty"`
} `json:"message,omitempty`
} `json:"params,omitempty`
} }
type DonateResponse struct { func startRoom(room, server, proxy string, u *url.URL) {
F struct {
Username string `json:"username"`
} `json:"f"`
A int `json:"a"`
}
func getAMF(room string) (bool, *AuthResponse) {
v := &AuthResponse{}
req, err := http.NewRequest(http.MethodPost, "https://rt.bongocams.com/tools/amf.php?res=771840&t=1654437233142", strings.NewReader(`method=getRoomData&args[]=`+room))
if err != nil {
fmt.Println(err.Error())
return false, v
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Header.Add("X-Requested-With", "XMLHttpRequest")
req.Header.Add("Accept", "application/json")
req.Header.Add("Referrer", "https://bongacams.com")
req.Header.Add("User-agent", "curl/7.79.1")
rsp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err.Error())
return false, v
}
defer rsp.Body.Close()
if err = json.NewDecoder(rsp.Body).Decode(v); err != nil {
fmt.Println(err.Error())
return false, v
}
return true, v
}
func startRoom(room, server, proxy string, u url.URL) {
// curl -vvv -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "X-Requested-With: XMLHttpRequest" -d "method=getRoomData" -d "args[]=Icehotangel" "https://rt.bongocams.com/tools/amf.php?res=771840&t=1654437233142" // curl -vvv -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "X-Requested-With: XMLHttpRequest" -d "method=getRoomData" -d "args[]=Icehotangel" "https://rt.bongocams.com/tools/amf.php?res=771840&t=1654437233142"
fmt.Println("Start", room, "server", server, "proxy", proxy) fmt.Println("Start", room, "server", server, "proxy", proxy)
ok, v := getAMF(room)
if !ok {
fmt.Println("exit: no amf parms")
return
}
Dialer := *websocket.DefaultDialer Dialer := *websocket.DefaultDialer
proxyMap := make(map[string]string) proxyMap := make(map[string]string)
@ -103,16 +60,6 @@ func startRoom(room, server, proxy string, u url.URL) {
return return
} }
pid := 1
now := time.Now().Unix()
ping := now+30
if err = c.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{"id":%d,"name":"joinRoom","args":["%s",{"username":"%s","displayName":"%s","location":"%s","chathost":"%s","isRu":%t,"isPerformer":false,"hasStream":false,"isLogged":false,"isPayable":false,"showType":"public"},"%s"]}`, pid, v.UserData.Chathost, v.UserData.Username, v.UserData.DisplayName, v.UserData.Location, v.UserData.Chathost, v.UserData.IsRu, v.LocalData.DataKey))); err != nil {
fmt.Println(err.Error())
return
}
defer c.Close() defer c.Close()
for { for {
_, message, err := c.ReadMessage() _, message, err := c.ReadMessage()
@ -121,27 +68,6 @@ func startRoom(room, server, proxy string, u url.URL) {
return return
} }
if pid == 1 {
pid++
fmt.Println("send ChatModule.connect")
if err = c.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{"id":%d,"name":"ChatModule.connect","args":["public-chat"]}`, pid))); err != nil {
fmt.Println(err.Error())
return
}
continue
}
now = time.Now().Unix()
if(now > ping){
pid++
fmt.Println("send ping", pid)
if err = c.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{"id":%d,"name":"ping"}`, pid))); err != nil {
return
}
ping = now+30
}
// fmt.Println(string(message))d // fmt.Println(string(message))d
m := &ServerResponse{} m := &ServerResponse{}
@ -151,19 +77,8 @@ func startRoom(room, server, proxy string, u url.URL) {
continue continue
} }
if m.Type == "ServerMessageEvent:PERFORMER_STATUS_CHANGE" && bytes.Contains(m.Body, []byte(`offile`)) { if m.Params.Message.Details.LovenseDetails.Type == "tip" {
return fmt.Println(m.Params.Message.Details.LovenseDetails.Detail.Name, " send ", m.Params.Message.Details.LovenseDetails.Detail.Amount, "tokens")
}
if m.Type == "ServerMessageEvent:ROOM_CLOSE" {
return
}
if m.Type == "ServerMessageEvent:INCOMING_TIP" {
d := &DonateResponse{}
if err = json.Unmarshal(m.Body, d); err == nil {
fmt.Println(d.F.Username, " send ", d.A, "tokens")
}
} }
} }
} }