Repository: Cog-Creators/Red-DiscordBot

Issue:
[Streams] Error checking stream feeds since latest update
# Other bugs

<!-- 
Did you find a bug with something other than a command? Fill out the following:
-->

#### What were you trying to do?

<!-- Replace this line with a description of what you were trying to do -->
Running my bot with the streams cog loaded with a handful of followed accounts.

#### What were you expecting to happen?

<!-- Replace this line with a description of what you were expecting to happen -->
Bot update and cog update work just fine with no errors.

#### What actually happened?

<!-- Replace this line with a description of what actually happened. Include any error messages -->
Checked my logs after a few days and noticed pages and pages of logs filled with the following error.
```
Jan 15 23:25:32 TrustyBot redbot[939]: [2021-01-15 23:25:32] [ERROR] red.core.cogs.Streams: An error has occured with Streams. Please report it.
Jan 15 23:25:32 TrustyBot redbot[939]: Traceback (most recent call last):
Jan 15 23:25:32 TrustyBot redbot[939]:   File "/home/trusty/red/lib/python3.8/site-packages/redbot/cogs/streams/streams.py", line 737, in check_streams
Jan 15 23:25:32 TrustyBot redbot[939]:     embed, is_schedule = await stream.is_online()
Jan 15 23:25:32 TrustyBot redbot[939]:   File "/home/trusty/red/lib/python3.8/site-packages/redbot/cogs/streams/streamtypes.py", line 117, in is_online
Jan 15 23:25:32 TrustyBot redbot[939]:     for video_id in get_video_ids_from_feed(rssdata):
Jan 15 23:25:32 TrustyBot redbot[939]:   File "/home/trusty/red/lib/python3.8/site-packages/redbot/cogs/streams/streamtypes.py", line 47, in get_video_ids_from_feed
Jan 15 23:25:32 TrustyBot redbot[939]:     root = ET.fromstring(feed)
Jan 15 23:25:32 TrustyBot redbot[939]:   File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1320, in XML
Jan 15 23:25:32 TrustyBot redbot[939]:     parser.feed(text)
Jan 15 23:25:32 TrustyBot redbot[939]:   File "<string>", line None
Jan 15 23:25:32 TrustyBot redbot[939]: xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 2, column 11
```

#### How can we reproduce this issue?

<!-- Replace with numbered steps to reproduce the issue -->
I am not quite sure but I can help diagnose exactly what's causing it.



Discussion:
Turns out there was a youtube stream setup at some point that was causing this error.


Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -724,6 +724,7 @@ async def _send_stream_alert(
         stream._messages_cache.append(m)
 
     async def check_streams(self):
+        to_remove = []
         for stream in self.streams:
             try:
                 try:
@@ -738,6 +739,10 @@ async def check_streams(self):
 
                     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 @@ async def check_streams(self):
             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
--- a/redbot/cogs/streams/streamtypes.py
+++ b/redbot/cogs/streams/streamtypes.py
@@ -106,6 +106,8 @@ async def is_online(self):
 
         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:


Test patch: