[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:
El Laggron 2020-11-30 18:10:44 +01:00 committed by GitHub
parent e2adb29cf3
commit e2a6d451c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,11 +133,17 @@ class YoutubeStream(Stream):
stream_data stream_data
and stream_data != "None" and stream_data != "None"
and stream_data.get("actualEndTime", None) is 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: if video_id not in self.livestreams:
self.livestreams.append(data["items"][0]["id"]) self.livestreams.append(data["items"][0]["id"])
else: else:
@ -169,15 +175,20 @@ class YoutubeStream(Stream):
channel_title = vid_data["snippet"]["channelTitle"] channel_title = vid_data["snippet"]["channelTitle"]
embed = discord.Embed(title=title, url=video_url) embed = discord.Embed(title=title, url=video_url)
is_schedule = False 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"]: if "actualStartTime" not in vid_data["liveStreamingDetails"]:
start_time = parse_time(vid_data["liveStreamingDetails"]["scheduledStartTime"]) start_time = parse_time(vid_data["liveStreamingDetails"]["scheduledStartTime"])
start_in = start_time.replace(tzinfo=None) - datetime.now() start_in = start_time.replace(tzinfo=None) - datetime.now()
embed.description = _("This stream will start in {time}").format( if start_in.total_seconds() > 0:
time=humanize_timedelta( embed.description = _("This stream will start in {time}").format(
timedelta=timedelta(minutes=start_in.total_seconds() // 60) time=humanize_timedelta(
) # getting rid of seconds 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 embed.timestamp = start_time
is_schedule = True is_schedule = True
else: else: