From 9cc90ec2455ed44a19b776132e0e10c4e5499bc4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 2 Jan 2012 22:38:19 +0530 Subject: [PATCH] export layers as srt --- pandora/annotation/views.py | 1 + pandora/item/models.py | 7 +++++++ pandora/item/urls.py | 3 +++ pandora/item/views.py | 13 +++++++++++++ 4 files changed, 24 insertions(+) diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index 512c4acd5..3865ce1a5 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -203,3 +203,4 @@ def editAnnotation(request): response = json_response(status=403, text='permission denied') return render_to_json_response(response) actions.register(editAnnotation, cache=False) + diff --git a/pandora/item/models.py b/pandora/item/models.py index 536426630..5eed3d78c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1166,6 +1166,13 @@ class Item(models.Model): Clip.objects.filter(item=self, annotations__id=None).delete() self.update_find() + def srt(self, layer): + return ox.srt.encode([{ + 'in': a.start, + 'out': a.end, + 'value': a.value + } for a in self.annotations.filter(layer=layer).order_by('start')]) + def delete_item(sender, **kwargs): i = kwargs['instance'] i.delete_files() diff --git a/pandora/item/urls.py b/pandora/item/urls.py index f94216939..e5ac889ec 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -18,6 +18,9 @@ urlpatterns = patterns("item.views", #torrent (r'^(?P[A-Z0-9].*)/torrent/(?P.*?)$', 'torrent'), + #srt export + (r'^(?P[A-Z0-9].*)/(?P.+)\.srt$', 'srt'), + #icon (r'^(?P[A-Z0-9].*)/icon(?P\d*)\.jpg$', 'icon'), diff --git a/pandora/item/views.py b/pandora/item/views.py index 3455b9af1..5098a3562 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -784,6 +784,18 @@ def video(request, id, resolution, format, index=None): response['Cache-Control'] = 'public' return response +def srt(request, id, layer, index=None): + item = get_object_or_404(models.Item, itemId=id) + if not item.access(request.user): + response = HttpResponseForbidden() + else: + response = HttpResponse() + filename = "%s.srt" % item.get('title') + response['Content-Disposition'] = 'attachment; filename="%s"' % filename + response['Content-Type'] = 'text/x-srt' + response.write(item.srt(layer)) + return response + def random_annotation(request): n = models.Item.objects.all().count() pos = random.randint(0, n) @@ -792,3 +804,4 @@ def random_annotation(request): pos = random.randint(0, n) clip = item.annotations.all()[pos] return redirect('/%s'% clip.public_id) +