Change the watching method back to using Spade

This commit is contained in:
DevilXD committed 2026-07-11 14:04:02 +02:00
1 parent f225638daa
commit 4148c71986
1 file changed
+19 -29
+19 -29
View File
@@ -44,29 +44,8 @@ class Stream:
self._stream_url: URLType | None = None self._stream_url: URLType | None = None
@cached_property @cached_property
def _spade_payload(self) -> JsonType: def _watch_payload(self) -> list[JsonType]:
payload = [ return [
{
"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 = [
{ {
"event": "minute-watched", "event": "minute-watched",
"properties": { "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( return GQLQuery(
( (
"\n mutation SendEvents($input: SendSpadeEventsInput!) " "\n mutation SendEvents($input: SendSpadeEventsInput!) "
"{\n sendSpadeEvents(input: $input) {\n statusCode\n}\n}\n" "{\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 @classmethod
@@ -491,25 +481,25 @@ class Channel:
async with self._twitch.request("HEAD", stream_chunk_url) as head_response: async with self._twitch.request("HEAD", stream_chunk_url) as head_response:
return head_response.status == 200 return head_response.status == 200
# NOTE: This is currently unused. async def send_watch(self) -> bool:
async def _send_watch_spade(self) -> bool:
if self._stream is None: if self._stream is None:
return False return False
if self._spade_url is None: if self._spade_url is None:
self._spade_url = await self.get_spade_url() self._spade_url = await self.get_spade_url()
try: try:
async with self._twitch.request( 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: ) as response:
return response.status == 204 return response.status == 204
except RequestException: except RequestException:
return False 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: if self._stream is None:
return False return False
try: 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 return watch_response["data"]["sendSpadeEvents"]["statusCode"] == 204
except RequestException: except RequestException:
return False return False