From 1d2698872138e6dfb4f4625e678ba6db136917d9 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Thu, 19 Oct 2023 22:09:29 +0200 Subject: [PATCH] Fix slug generation method --- twitch.py | 10 ++++++---- utils.py | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/twitch.py b/twitch.py index 2f71e57..aea0e20 100644 --- a/twitch.py +++ b/twitch.py @@ -1698,10 +1698,12 @@ class Twitch: }, }) ) - return [ - Channel.from_directory(self, stream_channel_data["node"], drops_enabled=True) - for stream_channel_data in response["data"]["game"]["streams"]["edges"] - ] + if "game" in response["data"]: + return [ + Channel.from_directory(self, stream_channel_data["node"], drops_enabled=True) + for stream_channel_data in response["data"]["game"]["streams"]["edges"] + ] + return [] async def claim_points(self, channel_id: str | int, claim_id: str) -> None: await self.gql_request( diff --git a/utils.py b/utils.py index 86adbed..e86b7d5 100644 --- a/utils.py +++ b/utils.py @@ -409,4 +409,10 @@ class Game: """ Converts the game name into a slug, useable for the GQL API. """ - return re.sub(r'(?![- ])\W', '', self.name.lower().replace(' ', '-')) + # remove specific characters + slug_text = re.sub(r'\'', '', self.name.lower()) + # remove non alpha-numeric characters + slug_text = re.sub(r'\W+', '-', slug_text) + # strip and collapse dashes + slug_text = re.sub(r'-{2,}', '-', slug_text.strip('-')) + return slug_text