From c44e624f534aa26ac5cbb759c5c11d2726542828 Mon Sep 17 00:00:00 2001 From: Mow910 Date: Mon, 9 Mar 2026 20:20:28 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20la=20gestion=20de=20l'?= =?UTF-8?q?historique=20des=20vid=C3=A9os=20YouTube.=20Ajout=20de=20l'enre?= =?UTF-8?q?gistrement=20de=20toutes=20les=20vid=C3=A9os=20d=C3=A9tect?= =?UTF-8?q?=C3=A9es=20dans=20l'historique,=20tout=20en=20simplifiant=20la?= =?UTF-8?q?=20logique=20de=20notification=20pour=20=C3=A9viter=20les=20dou?= =?UTF-8?q?blons.=20Mise=20=C3=A0=20jour=20des=20conditions=20de=20notific?= =?UTF-8?q?ation=20pour=20garantir=20que=20les=20vid=C3=A9os=20sont=20corr?= =?UTF-8?q?ectement=20enregistr=C3=A9es=20et=20notifi=C3=A9es.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- discordbot/youtube.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/discordbot/youtube.py b/discordbot/youtube.py index dd161fb..e2da013 100644 --- a/discordbot/youtube.py +++ b/discordbot/youtube.py @@ -121,19 +121,21 @@ async def _checkChannelVideos(notification: YouTubeNotification, is_first_check: videos.sort(key=lambda x: x[1]['published'], reverse=True) + # Enregistrer toutes les vidéos du flux dans l'historique (les doublons sont ignorés) + for vid, vdata in videos: + _save_video_history(notification.id, vid, vdata, notified=False) + if videos: latest_video_id, latest_video = videos[0] if is_first_check: if not notification.last_video_id or notification.last_video_id != latest_video_id: logger.info(f"YouTube: synchronisation initiale pour {channel_id}, dernière vidéo: {latest_video_id}") - _save_video_history(notification.id, latest_video_id, latest_video, notified=False) notification.last_video_id = latest_video_id db.session.commit() return if not notification.last_video_id: - _save_video_history(notification.id, latest_video_id, latest_video, notified=False) notification.last_video_id = latest_video_id db.session.commit() return @@ -144,13 +146,10 @@ async def _checkChannelVideos(notification: YouTubeNotification, is_first_check: success = await _notifyVideo(embed_config, latest_video, latest_video_id) if success: _save_video_history(notification.id, latest_video_id, latest_video, notified=True) - notification.last_video_id = latest_video_id - db.session.commit() else: - _save_video_history(notification.id, latest_video_id, latest_video, notified=False) - notification.last_video_id = latest_video_id - db.session.commit() logger.warning(f"Notification échouée pour {latest_video_id}, vidéo enregistrée comme non notifiée") + notification.last_video_id = latest_video_id + db.session.commit() except Exception as e: logger.error(f"Erreur lors de la vérification des vidéos: {e}")