Change the watching method back to using Spade
This commit is contained in:
1 parent
f225638daa
commit
4148c71986
1 file changed
+19
-29
+19
-29
@@ -44,29 +44,8 @@ class Stream:
|
||||
self._stream_url: URLType | None = None
|
||||
|
||||
@cached_property
|
||||
def _spade_payload(self) -> JsonType:
|
||||
payload = [
|
||||
{
|
||||
"event": "minute-watched",
|
||||
"properties": {
|
||||
"broadcast_id": str(self.broadcast_id),
|
||||
"channel_id": str(self.channel.id),
|
||||
"channel": self.channel._login,
|
||||
"hidden": False,
|
||||
"live": True,
|
||||
"location": "channel",
|
||||
"logged_in": True,
|
||||
"muted": False,
|
||||
"player": "site",
|
||||
"user_id": self.channel._twitch._auth_state.user_id,
|
||||
}
|
||||
}
|
||||
]
|
||||
return {"data": (b64encode(json_minify(payload).encode("utf8"))).decode("utf8")}
|
||||
|
||||
@cached_property
|
||||
def _gql_payload(self) -> GQLQuery:
|
||||
payload = [
|
||||
def _watch_payload(self) -> list[JsonType]:
|
||||
return [
|
||||
{
|
||||
"event": "minute-watched",
|
||||
"properties": {
|
||||
@@ -86,12 +65,23 @@ class Stream:
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@cached_property
|
||||
def spade_payload(self) -> JsonType:
|
||||
return {
|
||||
"data": (b64encode(json_minify(self._watch_payload).encode("utf8"))).decode("utf8")
|
||||
}
|
||||
|
||||
@cached_property
|
||||
def gql_payload(self) -> GQLQuery:
|
||||
return GQLQuery(
|
||||
(
|
||||
"\n mutation SendEvents($input: SendSpadeEventsInput!) "
|
||||
"{\n sendSpadeEvents(input: $input) {\n statusCode\n}\n}\n"
|
||||
),
|
||||
b64encode(gzip.compress(json_minify(payload).encode("utf8"))).decode("utf8")
|
||||
b64encode(
|
||||
gzip.compress(json_minify(self._watch_payload).encode("utf8"))
|
||||
).decode("utf8")
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -491,25 +481,25 @@ class Channel:
|
||||
async with self._twitch.request("HEAD", stream_chunk_url) as head_response:
|
||||
return head_response.status == 200
|
||||
|
||||
# NOTE: This is currently unused.
|
||||
async def _send_watch_spade(self) -> bool:
|
||||
async def send_watch(self) -> bool:
|
||||
if self._stream is None:
|
||||
return False
|
||||
if self._spade_url is None:
|
||||
self._spade_url = await self.get_spade_url()
|
||||
try:
|
||||
async with self._twitch.request(
|
||||
"POST", self._spade_url, data=self._stream._spade_payload
|
||||
"POST", self._spade_url, data=self._stream.spade_payload
|
||||
) as response:
|
||||
return response.status == 204
|
||||
except RequestException:
|
||||
return False
|
||||
|
||||
async def send_watch(self) -> bool: # send_watch_gql
|
||||
# NOTE: This is currently unused.
|
||||
async def _send_watch_gql(self) -> bool:
|
||||
if self._stream is None:
|
||||
return False
|
||||
try:
|
||||
watch_response = await self._twitch.gql_request(self._stream._gql_payload)
|
||||
watch_response = await self._twitch.gql_request(self._stream.gql_payload)
|
||||
return watch_response["data"]["sendSpadeEvents"]["statusCode"] == 204
|
||||
except RequestException:
|
||||
return False
|
||||
Reference in new issue
Block a user