mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
b71d278ae5
commit
f30772a7bd
@ -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]]:
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user