diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index 197eeca69..139c4380b 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -31,6 +31,8 @@ from datetime import datetime from collections import defaultdict from typing import Optional, List, Tuple, Union, Dict +MAX_RETRY_COUNT = 10 + _ = Translator("Streams", __file__) log = logging.getLogger("red.core.cogs.Streams") @@ -747,8 +749,14 @@ 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) + if stream.retry_count > MAX_RETRY_COUNT: + log.info("Stream with name %s no longer exists. Removing...", stream.name) + to_remove.append(stream) + else: + log.info( + "Stream with name %s seems to not exist, will retry later", stream.name + ) + stream.retry_count += 1 continue except OfflineStream: if not stream.messages: diff --git a/redbot/cogs/streams/streamtypes.py b/redbot/cogs/streams/streamtypes.py index 294f2c7d9..a70cdd64e 100644 --- a/redbot/cogs/streams/streamtypes.py +++ b/redbot/cogs/streams/streamtypes.py @@ -64,6 +64,9 @@ class Stream: # self.already_online = kwargs.pop("already_online", False) self.messages = kwargs.pop("messages", []) self.type = self.__class__.__name__ + # Keep track of how many failed consecutive attempts we had at checking + # if the stream's channel actually exists. + self.retry_count = 0 @property def display_name(self) -> Optional[str]: @@ -129,6 +132,10 @@ class YoutubeStream(Stream): raise StreamNotFound() rssdata = await r.text() + # Reset the retry count since we successfully got information about this + # channel's streams + self.retry_count = 0 + if self.not_livestreams: self.not_livestreams = list(dict.fromkeys(self.not_livestreams)) @@ -401,6 +408,10 @@ class TwitchStream(Stream): if follows_data: final_data["followers"] = follows_data["total"] + # Reset the retry count since we successfully got information about this + # channel's streams + self.retry_count = 0 + return self.make_embed(final_data), final_data["type"] == "rerun" elif stream_code == 400: raise InvalidTwitchCredentials() @@ -462,6 +473,9 @@ class PicartoStream(Stream): data = await r.text(encoding="utf-8") if r.status == 200: data = json.loads(data) + # Reset the retry count since we successfully got information about this + # channel's streams + self.retry_count = 0 if data["online"] is True: # self.already_online = True return self.make_embed(data)