-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move ClientType
into Twitch
class as an attribute
#437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I see this can be done slightly different though, while also cleaning up the code a little.
c2af00d
to
8deb361
Compare
My Python skills are basically none, so please bear with me. 😅 In any case, let me know if it looks good now. |
Hey, no worries, you've got it right 🙂 Although I didn't really think through the logistics of the new attribute, and it would be best to avoid repacking it like that. I didn't really want to bother you with this, but to avoid repacking the object, the entire thing had to be moved from module-level to inside the class, rewriting all existing references, so I just pushed a new commit to address it. If you want to, you can incorporate it into yours, or edit the commit message, I didn't really know how to name it 😅 |
No worries, thank you for implementing it for me! However, I just tested your latest changes, and I'm getting an exception: 13:26:28: Watching: Rainbow6
13:26:28: INFO: Websocket[1] connecting...
13:26:28: INFO: Websocket[2] connecting...
13:26:28: INFO: Websocket[3] connecting...
13:26:28: INFO: Websocket[4] connecting...
13:26:28: INFO: Websocket[5] connecting...
13:26:28: INFO: Websocket[6] connecting...
13:26:28: INFO: Websocket[7] connecting...
13:26:28: ERROR: Exception in task
13:26:28: Traceback (most recent call last):
13:26:28: File "/home/gui/dev/TwitchDropsMiner/utils.py", line 139, in wrapper
13:26:28: await afunc(*args, **kwargs)
13:26:28: File "/home/gui/dev/TwitchDropsMiner/twitch.py", line 1047, in _watch_loop
13:26:28: succeeded: bool = await channel.send_watch()
13:26:28: ^^^^^^^^^^^^^^^^^^^^^^^^^^
13:26:28: File "/home/gui/dev/TwitchDropsMiner/channel.py", line 379, in send_watch
13:26:28: self._spade_url = await self.get_spade_url()
13:26:28: ^^^^^^^^^^^^^^^^^^^^^^^^^^
13:26:28: File "/home/gui/dev/TwitchDropsMiner/channel.py", line 231, in get_spade_url
13:26:28: async with self._twitch.request("GET", self.url) as response:
13:26:28: ^^^^^^^^
13:26:28: File "/home/gui/dev/TwitchDropsMiner/channel.py", line 154, in url
13:26:28: return URLType(f"{self._twitch.client_info.CLIENT_URL}/{self._login}")
13:26:28: ^^^^^^^^^^^^^^^^^^^^^^^^
13:26:28: AttributeError: 'Twitch' object has no attribute 'client_info' |
Ah, right 😓 The attribute name is |
This allows us to use the base URL as specified in ClientInfo for requests made to Twitch. Previously, we'd hardcode "www.twitch.tv" as the base URL to make channel-related requests, but because we're currently spoofing the mobile client, that would always cause a HTTP redirect to m.twitch.tv. This change avoids that HTTP redirect, and potentially saves a whopping 150 ms (or more 😱) when making channel-related requests. Co-authored-by: DevilXD <[email protected]>
m.twitch.tv
to load the channel pageClientType
into Twitch
class as an attribute
f6ceed3
to
dbf51ae
Compare
Thank you! I've squashed your commit into mine and added you as a co-author. I'm using your original commit title, and I tweaked its description. Hopefully it's good enough! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! Thank you for your contribution 😊
This allows us to use the base URL as specified in
ClientInfo
for requests made to Twitch.Previously, we'd hardcode
www.twitch.tv
as the base URL to make channel-related requests, but because we're currently spoofing the mobile client, that would always cause a HTTP redirect tom.twitch.tv
.This change avoids that HTTP redirect, and potentially saves a whopping 150 ms (or more 😱) when making channel-related requests.
Before:
After: