From 244b7a92bde8842a51218dcdfcefd4b0ccc9be18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Wed, 9 Sep 2020 00:27:03 +0200 Subject: [PATCH] Deduplicate YouTube videos --- bot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bot.py b/bot.py index 9229074..7f4ed19 100644 --- a/bot.py +++ b/bot.py @@ -59,6 +59,7 @@ class Bot(discord.Client): re.compile(r'^(?P!)(?Preaction)\s+(?P")?(?P.+)(?(q)")$'), ) self.youtube = YouTube(yt_api_key, yt_channel_id) + self.yt_videos = [] super().__init__() async def process_event(self, service, data): @@ -140,6 +141,11 @@ class Bot(discord.Client): video = self.youtube.get_video(video_id) except YouTubeError as e: return + published = entry.get('published') + if published: + if [v for v, p in self.yt_videos if v == video_id and p == published]: + return + self.yt_videos.append((video_id, published)) channel = self.get_channel(youtube_channel_id) if channel: note = ''