mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Streams] Check non-existent streams more than once (#5223)
* [Streams] Check non-existent streams more than once - For YouTube streams, it seems like the RSS feed may sometimes return an HTTP 404 for a channel, even though the channel exists. - If this happens more than a few times, then we should declare the stream as non-existent, and purge it from the list of streams we check. * [Streams] Move retry_count reset for YouTubeStream - Reset after the RSS check, since that is the only place where we raise StreamNotFound in that function. * [Streams] Increase retry to 20 * [Streams] Reduce retry count to 10
This commit is contained in:
parent
cad7f400f9
commit
36ea867dcf
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user