youtube_parser: fix regex

master
dece 3 years ago
parent 93d59ff30b
commit 7ca8fa2ce4

@ -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<code1>[^&\s]+)"
r"|youtu\.be/(?P<code2>[^&\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

Loading…
Cancel
Save