From 4ab9d497ff1afc961a7afec5a25364ba11e759b9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 2 Sep 2014 14:25:27 +0000 Subject: [PATCH] add by language srt url --- pandora/item/models.py | 7 +++++-- pandora/item/urls.py | 3 +++ pandora/item/views.py | 9 ++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 9bdb00b04..2f7ab5777 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 a89f75e3d..3851383fb 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 528f3cd00..3ce20ef54 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):