From d049858f44c069c9af13bce0711f880acb8b6825 Mon Sep 17 00:00:00 2001 From: poiuty Date: Tue, 24 Jan 2023 23:23:17 +0300 Subject: [PATCH] update test2 --- test2/cb.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ test2/worker.go | 18 ++++++++------- 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 test2/cb.py diff --git a/test2/cb.py b/test2/cb.py new file mode 100644 index 0000000..f16e203 --- /dev/null +++ b/test2/cb.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import cloudscraper, json, re, codecs, sys + +def lowercase_escape(s): + unicode_escape = codecs.getdecoder('unicode_escape') + return re.sub( + r'\\u[0-9a-fA-F]{4}', + lambda m: unicode_escape(m.group(0))[0], + s) + +if len(sys.argv) < 2: + print('./cb.py name'); + exit(0) + + +room = sys.argv[1] + +scraper = cloudscraper.create_scraper( + interpreter='nodejs', + captcha={ + 'provider': '2captcha', + 'api_key': '' + } +) + +# Get cookies + set agreeterms 1 +html = scraper.get("https://chaturbate.com/"+room).text +cookies = scraper.cookies.get_dict() +cookies["agreeterms"] = "1" +#print(cookies) + +# Get room_uid +result = re.search('window.initialRoomDossier = "(.*)";', html) +arr = json.loads(lowercase_escape(result.group(1))) +#print(arr["room_uid"]) + +# Send post to auth +topics = '{"RoomTipAlertTopic#RoomTipAlertTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomPurchaseTopic#RoomPurchaseTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomFanClubJoinedTopic#RoomFanClubJoinedTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomMessageTopic#RoomMessageTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"GlobalPushServiceBackendChangeTopic#GlobalPushServiceBackendChangeTopic":{},"RoomAnonPresenceTopic#RoomAnonPresenceTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"QualityUpdateTopic#QualityUpdateTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomNoticeTopic#RoomNoticeTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomEnterLeaveTopic#RoomEnterLeaveTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomPasswordProtectedTopic#RoomPasswordProtectedTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomModeratorPromotedTopic#RoomModeratorPromotedTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomModeratorRevokedTopic#RoomModeratorRevokedTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomStatusTopic#RoomStatusTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomTitleChangeTopic#RoomTitleChangeTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomSilenceTopic#RoomSilenceTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomKickTopic#RoomKickTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomUpdateTopic#RoomUpdateTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"},"RoomSettingsTopic#RoomSettingsTopic:ROOM_UID":{"broadcaster_uid":"ROOM_UID"}}'.replace("ROOM_UID", arr["room_uid"]) +data = [('topics', topics), ('csrfmiddlewaretoken', cookies["csrftoken"])] +headers = { + 'Origin': 'https://chaturbate.com', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15', + 'X-Requested-With': 'XMLHttpRequest', + 'Referrer': 'https://chaturbate.com/'+room+'/', + 'X-CSRFToken': cookies["csrftoken"], +} +auth = json.loads(scraper.post("https://chaturbate.com/push_service/auth/", headers=headers, cookies=cookies, data=data).text) +#print(auth["token_request"]) + +headers = { + 'accept': 'application/json', + 'content-type': 'application/json', + 'origin': 'https://chaturbate.com', + 'referer': 'https://chaturbate.com/', +} +keys = json.loads(scraper.post('https://realtime.pa.highwebmedia.com/keys/'+auth["token_request"]["keyName"]+'/requestToken?rnd=9705437583116864', headers=headers, cookies=cookies, json=auth["token_request"]).text) +print(json.dumps({'id': arr["room_uid"], 'auth': keys["token"]})) diff --git a/test2/worker.go b/test2/worker.go index bb9c79b..8f384c1 100644 --- a/test2/worker.go +++ b/test2/worker.go @@ -87,17 +87,19 @@ func statRoom(room, room_uid, authToken string) { timeout = time.Now().Unix() + 60*60 - tips := []struct { - Data string `json:"data"` - }{} - - if err := json.Unmarshal([]byte(m), &tips); err != nil { - fmt.Println(err.Error()) - continue - } + if input.Channel == "room:tip_alert:"+room_uid { + tips := []struct { + Data string `json:"data"` + }{} + + if err := json.Unmarshal([]byte(m), &tips); err != nil { + fmt.Println(err.Error()) + continue + } + donate := struct { Name string `json:"to_username"` From string `json:"from_username"`