Updated Youtube video renderer to handle "loop" argument correctly
authorThierry Florac <tflorac@ulthar.net>
Wed, 22 May 2019 17:16:07 +0200
changeset 1315 ae1926a4fa70
parent 1314 f22df958696f
child 1316 2ef1161388a9
Updated Youtube video renderer to handle "loop" argument correctly
src/pyams_content/component/video/provider/zmi/__init__.py
--- a/src/pyams_content/component/video/provider/zmi/__init__.py	Wed May 22 15:15:52 2019 +0200
+++ b/src/pyams_content/component/video/provider/zmi/__init__.py	Wed May 22 17:16:07 2019 +0200
@@ -34,11 +34,20 @@
         return value or ''
 
 
+def get_playlist_id(settings):
+    """Include playlist ID if loop is required"""
+    if settings.loop:
+        return settings.video_id
+    else:
+        return None
+
+
 YOUTUBE_PARAMS = (
     ('start_at', 'start', time_to_seconds),
     ('stop_at', 'end', time_to_seconds),
     ('autoplay', 'autoplay', int),
     ('loop', 'loop', int),
+    (None, 'playlist', get_playlist_id),
     ('show_commands', 'controls', int),
     ('hide_branding', 'modestbranding', int),
     ('show_related', 'rel', int),
@@ -77,7 +86,12 @@
         settings = self.context
         params = {}
         for attr, param, handler in self.params:
-            params[param] = handler(getattr(settings, attr))
+            if attr is None:
+                result = handler(settings)
+            else:
+                result = handler(getattr(settings, attr))
+            if result is not None:
+                params[param] = result
         return urlencode(params)