only add/remove empty clips as needed

This commit is contained in:
j 2014-03-16 13:52:56 +00:00
parent 6de05d4c9d
commit 220e091460

View file

@ -1417,15 +1417,27 @@ class Item(models.Model):
duration = sum([s.duration for s in self.streams()]) duration = sum([s.duration for s in self.streams()])
start = 0 start = 0
layer = subtitles['id'] layer = subtitles['id']
Annotation.objects.filter(layer=layer, item=self, value='').delete()
#FIXME: allow annotations from no user instead? #FIXME: allow annotations from no user instead?
user = User.objects.all().order_by('id')[0] user = User.objects.all().order_by('id')[0]
for i in range(0, int(duration) - 5, 60):
clips = [(i, i+5) for i in range(0, int(duration) - 5, 60)]
exist = []
delete = []
for a in Annotation.objects.filter(layer=layer, item=self, value=''):
clip = (a.start, a.end)
if clip not in clips:
delete.append(a.id)
else:
exist.append(clip)
if delete:
Annotation.objects.filter(layer=layer, item=self, value='', id__in=delete).delete()
clips = list(set(clips) - set(exist))
for clip in clips:
annotation = Annotation( annotation = Annotation(
item=self, item=self,
layer=layer, layer=layer,
start=i, start=clip[0],
end=i + 5, end=clip[1],
value='', value='',
user=user user=user
) )