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
This commit is contained in:
jack1142 2021-03-29 14:05:42 +02:00 committed by GitHub
parent b71d278ae5
commit f30772a7bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -724,6 +724,7 @@ class Streams(commands.Cog):
stream._messages_cache.append(m) stream._messages_cache.append(m)
async def check_streams(self): async def check_streams(self):
to_remove = []
for stream in self.streams: for stream in self.streams:
try: try:
try: try:
@ -738,6 +739,10 @@ class Streams(commands.Cog):
else: else:
embed = await stream.is_online() 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: except OfflineStream:
if not stream._messages_cache: if not stream._messages_cache:
continue continue
@ -818,6 +823,11 @@ class Streams(commands.Cog):
except Exception as e: except Exception as e:
log.error("An error has occured with Streams. Please report it.", exc_info=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( async def _get_mention_str(
self, guild: discord.Guild, channel: discord.TextChannel self, guild: discord.Guild, channel: discord.TextChannel
) -> Tuple[str, List[discord.Role]]: ) -> Tuple[str, List[discord.Role]]:

View File

@ -106,6 +106,8 @@ class YoutubeStream(Stream):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(YOUTUBE_CHANNEL_RSS.format(channel_id=self.id)) as r: async with session.get(YOUTUBE_CHANNEL_RSS.format(channel_id=self.id)) as r:
if r.status == 404:
raise StreamNotFound()
rssdata = await r.text() rssdata = await r.text()
if self.not_livestreams: if self.not_livestreams: