add by language srt url

This commit is contained in:
j 2014-09-02 14:25:27 +00:00
parent 72d9dbf0f2
commit 4ab9d497ff
3 changed files with 14 additions and 5 deletions

View file

@ -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('<br/>', '<br>').replace('<br>\n', '\n').replace('<br>', '\n')
value = value.replace('\n\n', '<br>\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']

View file

@ -29,6 +29,9 @@ urlpatterns = patterns("item.views",
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'),
(r'^(?P<id>[A-Z0-9].*)/xml$', 'item_xml'),
#srt export
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.(?P<language>.{2})\.srt$', 'srt'),
#srt export
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.srt$', 'srt'),

View file

@ -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()
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):