Mercurial > sat_legacy_website
comparison sat_website/media.py @ 93:9ae3d9c8b28a
actually display the subtitles (with Firefox it is used only when it's the first <track /> of the list, and when the "default" option is present)
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 16 Jun 2015 21:26:58 +0200 |
parents | 7a79cb5ed43b |
children | 14080acdf896 |
comparison
equal
deleted
inserted
replaced
92:7a79cb5ed43b | 93:9ae3d9c8b28a |
---|---|
17 GNU Affero General Public License for more details. | 17 GNU Affero General Public License for more details. |
18 | 18 |
19 You should have received a copy of the GNU Affero General Public License | 19 You should have received a copy of the GNU Affero General Public License |
20 along with Foobar. If not, see <http://www.gnu.org/licenses/>. | 20 along with Foobar. If not, see <http://www.gnu.org/licenses/>. |
21 """ | 21 """ |
22 from django.utils.translation import ugettext_lazy as _ | 22 from django.utils.translation import get_language, ugettext_lazy as _ |
23 from django.conf import settings | 23 from django.conf import settings |
24 from collections import namedtuple, OrderedDict | 24 from collections import namedtuple, OrderedDict |
25 import os.path | 25 import os.path |
26 | 26 |
27 ImageDesc = namedtuple("ImageDesc", "path description data") | 27 ImageDesc = namedtuple("ImageDesc", "path description data") |
28 | 28 |
29 class VideoDesc(namedtuple("VideoDesc", "paths description poster data")): | 29 class VideoDesc(namedtuple("VideoDesc", "paths description poster data")): |
30 @property | 30 @property |
31 def subtitles(self): | 31 def subtitles(self): |
32 key = _(u"subtitles") | 32 key = "subtitles" |
33 if key not in self.data: | 33 if key not in self.data: |
34 return {} | 34 return {} |
35 result = OrderedDict() | 35 result = OrderedDict() |
36 for lang in self.data[key]: | 36 |
37 # put the current lang first | |
38 current_lang = get_language() | |
39 langs = [current_lang] if current_lang in self.data[key] else [] | |
40 langs.extend([lang for lang in self.data[key] if lang != current_lang]) | |
41 | |
42 for lang in langs: | |
37 try: | 43 try: |
38 result[lang] = os.path.splitext(self.paths[lang])[0] + '.vtt' | 44 result[lang] = os.path.splitext(self.paths[lang])[0] + '.vtt' |
39 except IndexError: | 45 except IndexError: |
40 # FIXME: subtitles for a lang that is not in self.paths are ignored | 46 # FIXME: subtitles for a lang that is not in self.paths are ignored |
41 pass | 47 pass |
51 # use OrderedDict when more than one language, the first item is the default one | 57 # use OrderedDict when more than one language, the first item is the default one |
52 VideoDesc(OrderedDict({"en": video + "libervia_adhesion_2015_en.webm", | 58 VideoDesc(OrderedDict({"en": video + "libervia_adhesion_2015_en.webm", |
53 "fr": video + "libervia_adhesion_2015_fr.webm"}), | 59 "fr": video + "libervia_adhesion_2015_fr.webm"}), |
54 _(u"Membership campaign for Libervia"), | 60 _(u"Membership campaign for Libervia"), |
55 video + "posters/libervia_adhesion_2015.png", | 61 video + "posters/libervia_adhesion_2015.png", |
56 {_(u"version"): "0.5", _(u"year"): "2015", _(u"subtitles"): ["en", "fr"]}), | 62 {_(u"version"): "0.5", _(u"year"): "2015", "subtitles": ["en", "fr"]}), |
57 | 63 |
58 ImageDesc("images/screenshots/0.5/overview_libervia.png", _(u"Overview"), | 64 ImageDesc("images/screenshots/0.5/overview_libervia.png", _(u"Overview"), |
59 {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}), | 65 {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}), |
60 ImageDesc("images/screenshots/0.5/http_unsecure_warning.png", _(u"Optional security check"), | 66 ImageDesc("images/screenshots/0.5/http_unsecure_warning.png", _(u"Optional security check"), |
61 {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}), | 67 {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}), |