Fix Spade URL extraction

This commit is contained in:
DevilXD committed 2023-08-15 22:20:23 +02:00
1 parent ed253a4b1e
commit 29fa220238
1 file changed
+18 -14
+18 -14
View File
@@ -219,24 +219,28 @@ class Channel:
""" """
To get this monstrous thing, you have to walk a chain of requests. To get this monstrous thing, you have to walk a chain of requests.
Streamer page (HTML) --parse-> Streamer Settings (JavaScript) --parse-> Spade URL Streamer page (HTML) --parse-> Streamer Settings (JavaScript) --parse-> Spade URL
For mobile view, spade_url is available immediately from the page, skipping step #2.
""" """
SETTINGS_PATTERN: str = (
r'src="(https://static\.twitchcdn\.net/config/settings\.[0-9a-f]{32}\.js)"'
)
SPADE_PATTERN: str = (
r'"spade_?url": ?"(https://video-edge-[.\w\-/]+\.ts(?:\?allow_stream=true)?)"'
)
async with self._twitch.request("GET", self.url) as response: async with self._twitch.request("GET", self.url) as response:
streamer_html: str = await response.text(encoding="utf8") streamer_html: str = await response.text(encoding="utf8")
match = re.search( match = re.search(SPADE_PATTERN, streamer_html, re.I)
r'src="(https://static\.twitchcdn\.net/config/settings\.[0-9a-f]{32}\.js)"',
streamer_html,
re.I,
)
if not match: if not match:
raise MinerException("Error while spade_url extraction: step #1") match = re.search(SETTINGS_PATTERN, streamer_html, re.I)
streamer_settings = match.group(1) if not match:
async with self._twitch.request("GET", streamer_settings) as response: raise MinerException("Error while spade_url extraction: step #1")
settings_js: str = await response.text(encoding="utf8") streamer_settings = match.group(1)
match = re.search( async with self._twitch.request("GET", streamer_settings) as response:
r'"spade_url": ?"(https://video-edge-[.\w\-/]+\.ts)"', settings_js, re.I settings_js: str = await response.text(encoding="utf8")
) match = re.search(SPADE_PATTERN, settings_js, re.I)
if not match: if not match:
raise MinerException("Error while spade_url extraction: step #2") raise MinerException("Error while spade_url extraction: step #2")
return URLType(match.group(1)) return URLType(match.group(1))
async def get_stream(self) -> Stream | None: async def get_stream(self) -> Stream | None: