matches. load subtitle annotations into database
This commit is contained in:
parent
81cc331aa9
commit
e4519b41a4
4 changed files with 32 additions and 18 deletions
|
|
@ -43,7 +43,7 @@ class File(models.Model):
|
|||
episode = models.IntegerField(default=-1)
|
||||
|
||||
size = models.BigIntegerField(default=0)
|
||||
duration = models.BigIntegerField(null=True)
|
||||
duration = models.FloatField(null=True)
|
||||
|
||||
info = fields.DictField(default={})
|
||||
|
||||
|
|
@ -143,8 +143,8 @@ class File(models.Model):
|
|||
if not self.is_audio and not self.is_video and self.name.endswith('.srt'):
|
||||
self.is_subtitle = True
|
||||
|
||||
self.part = self.get_part()
|
||||
self.type = self.get_type()
|
||||
self.part = self.get_part()
|
||||
|
||||
if self.type not in ('audio', 'video'):
|
||||
self.duration = None
|
||||
|
|
@ -166,7 +166,7 @@ class File(models.Model):
|
|||
return self.data.read()
|
||||
return None
|
||||
|
||||
def srt(self):
|
||||
def srt(self, offset=0):
|
||||
|
||||
def _detectEncoding(fp):
|
||||
bomDict={ # bytepattern : name
|
||||
|
|
@ -203,7 +203,7 @@ class File(models.Model):
|
|||
return encoding
|
||||
|
||||
def parseTime(t):
|
||||
return ox.time2ms(t.replace(',', '.')) / 1000
|
||||
return offset + ox.time2ms(t.replace(',', '.')) / 1000
|
||||
|
||||
srt = []
|
||||
|
||||
|
|
|
|||
|
|
@ -89,15 +89,3 @@ def update_files(user, volume, 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…
Add table
Add a link
Reference in a new issue