From 4148c71986c150be2b03299402519774bce3a60a Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sat, 11 Jul 2026 14:04:02 +0200 Subject: [PATCH] Change the watching method back to using Spade --- channel.py | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/channel.py b/channel.py index 65df658..36d17d3 100644 --- a/channel.py +++ b/channel.py @@ -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