From f30772a7bdf53d38f6add64da3eb205083d26754 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:05:42 +0200 Subject: [PATCH] Raise `StreamNotFound` for 404 errors in YouTube RSS feed (#4746) * Raise `StreamNotFound` for 404 errors in YouTube RSS feed * Catch `StreamNotFound` exception in bg task and remove such streams --- redbot/cogs/streams/streams.py | 10 ++++++++++ redbot/cogs/streams/streamtypes.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index f490bc5ce..33d63a486 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -724,6 +724,7 @@ class Streams(commands.Cog): stream._messages_cache.append(m) async def check_streams(self): + to_remove = [] for stream in self.streams: try: try: @@ -738,6 +739,10 @@ class Streams(commands.Cog): else: embed = await stream.is_online() + except StreamNotFound: + log.info("Stream with name %s no longer exists. Removing...", stream.name) + to_remove.append(stream) + continue except OfflineStream: if not stream._messages_cache: continue @@ -818,6 +823,11 @@ class Streams(commands.Cog): except Exception as e: log.error("An error has occured with Streams. Please report it.", exc_info=e) + if to_remove: + for stream in to_remove: + self.streams.remove(stream) + await self.save_streams() + async def _get_mention_str( self, guild: discord.Guild, channel: discord.TextChannel ) -> Tuple[str, List[discord.Role]]: diff --git a/redbot/cogs/streams/streamtypes.py b/redbot/cogs/streams/streamtypes.py index cab177cd6..0847b00ba 100644 --- a/redbot/cogs/streams/streamtypes.py +++ b/redbot/cogs/streams/streamtypes.py @@ -106,6 +106,8 @@ class YoutubeStream(Stream): async with aiohttp.ClientSession() as session: async with session.get(YOUTUBE_CHANNEL_RSS.format(channel_id=self.id)) as r: + if r.status == 404: + raise StreamNotFound() rssdata = await r.text() if self.not_livestreams: