add by language srt url
This commit is contained in:
parent
72d9dbf0f2
commit
4ab9d497ff
3 changed files with 14 additions and 5 deletions
|
@ -1559,16 +1559,19 @@ class Item(models.Model):
|
||||||
Clip.objects.filter(item=self, annotations__id=None).delete()
|
Clip.objects.filter(item=self, annotations__id=None).delete()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def srt(self, layer):
|
def srt(self, layer, language=None):
|
||||||
def format_value(value):
|
def format_value(value):
|
||||||
value = value.replace('<br/>', '<br>').replace('<br>\n', '\n').replace('<br>', '\n')
|
value = value.replace('<br/>', '<br>').replace('<br>\n', '\n').replace('<br>', '\n')
|
||||||
value = value.replace('\n\n', '<br>\n')
|
value = value.replace('\n\n', '<br>\n')
|
||||||
return value
|
return value
|
||||||
|
annotations = self.annotations.filter(layer=layer)
|
||||||
|
if language:
|
||||||
|
annotations = annotations.filter(languages__contains=language)
|
||||||
return ox.srt.encode([{
|
return ox.srt.encode([{
|
||||||
'in': a.start,
|
'in': a.start,
|
||||||
'out': a.end,
|
'out': a.end,
|
||||||
'value': format_value(a.value)
|
'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):
|
def delete_item(sender, **kwargs):
|
||||||
i = kwargs['instance']
|
i = kwargs['instance']
|
||||||
|
|
|
@ -29,6 +29,9 @@ urlpatterns = patterns("item.views",
|
||||||
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'),
|
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'),
|
||||||
(r'^(?P<id>[A-Z0-9].*)/xml$', 'item_xml'),
|
(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
|
#srt export
|
||||||
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.srt$', 'srt'),
|
(r'^(?P<id>[A-Z0-9].*)/(?P<layer>.+)\.srt$', 'srt'),
|
||||||
|
|
||||||
|
|
|
@ -956,16 +956,19 @@ def video(request, id, resolution, format, index=None, track=None):
|
||||||
response['Cache-Control'] = 'public'
|
response['Cache-Control'] = 'public'
|
||||||
return response
|
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)
|
item = get_object_or_404(models.Item, itemId=id)
|
||||||
if not item.access(request.user):
|
if not item.access(request.user):
|
||||||
response = HttpResponseForbidden()
|
response = HttpResponseForbidden()
|
||||||
else:
|
else:
|
||||||
response = HttpResponse()
|
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-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
|
||||||
response['Content-Type'] = 'text/x-srt'
|
response['Content-Type'] = 'text/x-srt'
|
||||||
response.write(item.srt(layer))
|
response.write(item.srt(layer, language))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def random_annotation(request):
|
def random_annotation(request):
|
||||||
|
|
Loading…
Reference in a new issue