Added Youtube "extended" URL into Youtube video provider
authorThierry Florac <tflorac@ulthar.net>
Fri, 08 Feb 2019 14:09:59 +0100
changeset 1274 a3ea045fdd06
parent 1273 e03e6f60a7e4
child 1275 32da1f79fb76
Added Youtube "extended" URL into Youtube video provider
src/pyams_content/component/video/provider/youtube.py
--- a/src/pyams_content/component/video/provider/youtube.py	Fri Feb 08 14:06:37 2019 +0100
+++ b/src/pyams_content/component/video/provider/youtube.py	Fri Feb 08 14:09:59 2019 +0100
@@ -12,29 +12,24 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 import re
 
 from persistent import Persistent
-
-# import interfaces
-from pyams_content.component.video.interfaces import IExternalVideo, IExternalVideoProvider, IExternalVideoSettings
-from pyams_content.component.video.provider.interfaces import IYoutubeVideoSettings
-from pyams_content.features.checker.interfaces import IContentChecker
-
-# import packages
-from pyams_content.component.video import external_video_settings_factory
-from pyams_content.features.checker import BaseContentChecker
-from pyams_utils.adapter import adapter_config
-from pyams_utils.registry import utility_config
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content import _
+from pyams_content.component.video import external_video_settings_factory
+from pyams_content.component.video.interfaces import IExternalVideo, IExternalVideoProvider, IExternalVideoSettings
+from pyams_content.component.video.provider.interfaces import IYoutubeVideoSettings
+from pyams_content.features.checker import BaseContentChecker
+from pyams_content.features.checker.interfaces import IContentChecker
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config
 
 
-YOUTUBE_BASE_URL = re.compile('https://youtu.be/(.*)')
+YOUTUBE_BASE_URL = re.compile(r'https://youtu.be/(.*)')
+YOUTUBE_EXTENDED_URL = re.compile(r'https://(?:www\.)?youtube.com/watch\?v=(.*)')
 
 
 @implementer(IYoutubeVideoSettings)
@@ -62,7 +57,7 @@
     @video_id.setter
     def video_id(self, value):
         if value:
-            match = YOUTUBE_BASE_URL.match(value)
+            match = YOUTUBE_BASE_URL.match(value) or YOUTUBE_EXTENDED_URL.match(value)
             if match:
                 value = match.groups()[0]
         self._video_id = value