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