mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Streams] Handle streams with past schedules (#4631)
* Resolve bug with [p]streamalert youtube The command didn't handle channels that were not provided as IDs * Provide a different message if the scheduled date has passed * Ignore streams scheduled for more than an hour
This commit is contained in:
parent
e2adb29cf3
commit
e2a6d451c3
@ -133,11 +133,17 @@ class YoutubeStream(Stream):
|
||||
stream_data
|
||||
and stream_data != "None"
|
||||
and stream_data.get("actualEndTime", None) is None
|
||||
and (
|
||||
stream_data.get("actualStartTime", None) is not None
|
||||
or stream_data.get("scheduledStartTime", None) is not None
|
||||
)
|
||||
):
|
||||
actual_start_time = stream_data.get("actualStartTime", None)
|
||||
scheduled = stream_data.get("scheduledStartTime", None)
|
||||
if scheduled is not None and actual_start_time is None:
|
||||
scheduled = parse_time(scheduled)
|
||||
if (
|
||||
scheduled.replace(tzinfo=None) - datetime.now()
|
||||
).total_seconds() < -3600:
|
||||
continue
|
||||
elif actual_start_time is None:
|
||||
continue
|
||||
if video_id not in self.livestreams:
|
||||
self.livestreams.append(data["items"][0]["id"])
|
||||
else:
|
||||
@ -169,15 +175,20 @@ class YoutubeStream(Stream):
|
||||
channel_title = vid_data["snippet"]["channelTitle"]
|
||||
embed = discord.Embed(title=title, url=video_url)
|
||||
is_schedule = False
|
||||
if vid_data["liveStreamingDetails"]["scheduledStartTime"] is not None:
|
||||
if vid_data["liveStreamingDetails"].get("scheduledStartTime", None) is not None:
|
||||
if "actualStartTime" not in vid_data["liveStreamingDetails"]:
|
||||
start_time = parse_time(vid_data["liveStreamingDetails"]["scheduledStartTime"])
|
||||
start_in = start_time.replace(tzinfo=None) - datetime.now()
|
||||
embed.description = _("This stream will start in {time}").format(
|
||||
time=humanize_timedelta(
|
||||
timedelta=timedelta(minutes=start_in.total_seconds() // 60)
|
||||
) # getting rid of seconds
|
||||
)
|
||||
if start_in.total_seconds() > 0:
|
||||
embed.description = _("This stream will start in {time}").format(
|
||||
time=humanize_timedelta(
|
||||
timedelta=timedelta(minutes=start_in.total_seconds() // 60)
|
||||
) # getting rid of seconds
|
||||
)
|
||||
else:
|
||||
embed.description = _(
|
||||
"This stream was scheduled for {min} minutes ago"
|
||||
).format(min=round((start_in.total_seconds() * -1) // 60))
|
||||
embed.timestamp = start_time
|
||||
is_schedule = True
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user