diff sat_website/media.py @ 92:7a79cb5ed43b

add subtitles in video metadata and <track /> elements
author souliane <souliane@mailoo.org>
date Tue, 16 Jun 2015 20:31:16 +0200
parents 5de2a3dd4e67
children 9ae3d9c8b28a
line wrap: on
line diff
--- a/sat_website/media.py	Tue Jun 16 17:36:08 2015 +0200
+++ b/sat_website/media.py	Tue Jun 16 20:31:16 2015 +0200
@@ -25,7 +25,21 @@
 import os.path
 
 ImageDesc = namedtuple("ImageDesc", "path description data")
-VideoDesc = namedtuple("VideoDesc", "paths description poster data")
+
+class VideoDesc(namedtuple("VideoDesc", "paths description poster data")):
+    @property
+    def subtitles(self):
+        key = _(u"subtitles")
+        if key not in self.data:
+            return {}
+        result = OrderedDict()
+        for lang in self.data[key]:
+            try:
+                result[lang] = os.path.splitext(self.paths[lang])[0] + '.vtt'
+            except IndexError:
+                # FIXME: subtitles for a lang that is not in self.paths are ignored
+                pass
+        return result
 
 screencasts = os.path.join(settings.MEDIA_EXTERNAL_URL, "screencasts") + "/"
 video = os.path.join(settings.MEDIA_EXTERNAL_URL, "video") + "/"
@@ -39,7 +53,7 @@
                            "fr": video + "libervia_adhesion_2015_fr.webm"}),
               _(u"Membership campaign for Libervia"),
               video + "posters/libervia_adhesion_2015.png",
-              {_(u"version"): "0.5", _(u"year"): "2015"}),
+              {_(u"version"): "0.5", _(u"year"): "2015", _(u"subtitles"): ["en", "fr"]}),
 
     ImageDesc("images/screenshots/0.5/overview_libervia.png", _(u"Overview"),
               {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}),