diff --git a/pandora/item/models.py b/pandora/item/models.py index 9bdb00b0..2f7ab577 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1559,16 +1559,19 @@ class Item(models.Model): Clip.objects.filter(item=self, annotations__id=None).delete() return True - def srt(self, layer): + def srt(self, layer, language=None): def format_value(value): value = value.replace('
', '
').replace('
\n', '\n').replace('
', '\n') value = value.replace('\n\n', '
\n') return value + annotations = self.annotations.filter(layer=layer) + if language: + annotations = annotations.filter(languages__contains=language) return ox.srt.encode([{ 'in': a.start, 'out': a.end, 'value': format_value(a.value) - } for a in self.annotations.filter(layer=layer).order_by('start', 'end', 'sortvalue')]) + } for a in annotations.order_by('start', 'end', 'sortvalue')]) def delete_item(sender, **kwargs): i = kwargs['instance'] diff --git a/pandora/item/urls.py b/pandora/item/urls.py index a89f75e3..3851383f 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -29,6 +29,9 @@ urlpatterns = patterns("item.views", (r'^(?P[A-Z0-9].*)/json$', 'item_json'), (r'^(?P[A-Z0-9].*)/xml$', 'item_xml'), + #srt export + (r'^(?P[A-Z0-9].*)/(?P.+)\.(?P.{2})\.srt$', 'srt'), + #srt export (r'^(?P[A-Z0-9].*)/(?P.+)\.srt$', 'srt'), diff --git a/pandora/item/views.py b/pandora/item/views.py index 528f3cd0..3ce20ef5 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -956,16 +956,19 @@ def video(request, id, resolution, format, index=None, track=None): response['Cache-Control'] = 'public' return response -def srt(request, id, layer, index=None): +def srt(request, id, layer, language=None, index=None): item = get_object_or_404(models.Item, itemId=id) if not item.access(request.user): response = HttpResponseForbidden() else: response = HttpResponse() - filename = u"%s.srt" % item.get('title') + if language: + filename = u"%s.%s.srt" % (item.get('title'), language) + else: + filename = u"%s.srt" % item.get('title') response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8')) response['Content-Type'] = 'text/x-srt' - response.write(item.srt(layer)) + response.write(item.srt(layer, language)) return response def random_annotation(request):