From 7ca8fa2ce4140ffefb17a51a509233243fc4665b Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 7 Jun 2021 10:45:54 +0200 Subject: [PATCH] youtube_parser: fix regex --- edmond/plugins/youtube_parser.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/edmond/plugins/youtube_parser.py b/edmond/plugins/youtube_parser.py index e949dbb..fd31f33 100644 --- a/edmond/plugins/youtube_parser.py +++ b/edmond/plugins/youtube_parser.py @@ -12,7 +12,8 @@ from edmond.plugin import Plugin class YoutubeParserPlugin(Plugin): VIDEO_URL_RE = re.compile( - r"https:\/\/www\.youtube\.com\/watch\?(?:.*&)?v=([^&]+)" + r"https?:\/\/(?:www\.youtube\.com\/watch\?(?:.*&)?v=(?P[^&\s]+)" + r"|youtu\.be/(?P[^&\s]+))" ) def __init__(self, bot): @@ -34,7 +35,11 @@ class YoutubeParserPlugin(Plugin): def on_pubmsg(self, event): match = self.VIDEO_URL_RE.match(event.arguments[0]) if match: - self.tell_video_title(match.group(1), event.target) + groupdict = match.groupdict() + code = groupdict.get("code1") or groupdict.get("code2") + if not code: + return False + self.tell_video_title(code, event.target) return True return False