forked from 0x2620/pandora
subtitles should annotations part 1
This commit is contained in:
parent
645310907f
commit
b32ac91211
3 changed files with 19 additions and 3 deletions
|
@ -101,8 +101,8 @@ class Annotation(models.Model):
|
|||
def get_id(self):
|
||||
return ox.to32(self.id)
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
def json(self, layer=False):
|
||||
j = {
|
||||
'id': self.get_id(),
|
||||
'user': self.user.username,
|
||||
'in': self.start,
|
||||
|
@ -111,6 +111,9 @@ class Annotation(models.Model):
|
|||
'created': self.created,
|
||||
'modified': self.modified
|
||||
}
|
||||
if layer:
|
||||
j['layer'] = self.layer.name
|
||||
return j
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s/%s-%s" %(self.item, self.start, self.end)
|
||||
|
|
|
@ -19,7 +19,7 @@ import chardet
|
|||
from item import utils
|
||||
from item.models import Item
|
||||
from person.models import get_name_sort
|
||||
|
||||
from annotation.models import Annotation, Layer
|
||||
|
||||
class File(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -88,3 +88,16 @@ def update_files(user, volume, files):
|
|||
#remove deleted files
|
||||
#FIXME: can this have any bad consequences? i.e. on the selction of used item files.
|
||||
models.Instance.objects.filter(volume=volume).exclude(file__oshash__in=all_files).delete()
|
||||
|
||||
def import_subtitles(id):
|
||||
f = models.File.objects.get(pk=id)
|
||||
layer = models.Layer.objects.get(name='subtitles')
|
||||
for data in f.srt():
|
||||
annotation = models.Annotation(
|
||||
item=f.item,
|
||||
layer=layer,
|
||||
start=data['in'],
|
||||
end=data['out'],
|
||||
value=data['value']
|
||||
)
|
||||
annotation.save()
|
||||
|
|
Loading…
Reference in a new issue