include outer cuts (before, after)

This commit is contained in:
j 2021-08-06 12:02:27 +02:00
parent b1834520bd
commit 0a7b6c0452
3 changed files with 26 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import ox
from archive import extract from archive import extract
from . import managers from . import managers
from .utils import add_cuts
def get_layers(item, interval=None, user=None): def get_layers(item, interval=None, user=None):
@ -155,7 +156,7 @@ class MetaClip(object):
if value: if value:
data[key] = value data[key] = value
data['duration'] = data['out'] - data['in'] data['duration'] = data['out'] - data['in']
data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end]) add_cuts(data, self.item, self.start, self.end)
data['layers'] = self.get_layers(user) data['layers'] = self.get_layers(user)
data['streams'] = [s.file.oshash for s in self.item.streams()] data['streams'] = [s.file.oshash for s in self.item.streams()]
return data return data

22
pandora/clip/utils.py Normal file
View file

@ -0,0 +1,22 @@
def add_cuts(data, item, start, end):
cuts = []
last = False
outer = []
first = 0
for cut in item.get('cuts', []):
if cut > start and cut < end:
if not cuts:
outer.append(first)
cuts.append(cut)
last = True
elif cut <= start:
first = cut
elif cut >= end:
if not len(outer):
outer.append(first)
if len(outer) == 1:
outer.append(cut)
data['cuts'] = tuple(cuts)
data['outerCuts'] = tuple(outer)

View file

@ -24,6 +24,7 @@ import clip.models
from archive import extract from archive import extract
from user.utils import update_groups from user.utils import update_groups
from user.models import Group from user.models import Group
from clip.utils import add_cuts
from . import managers from . import managers
@ -507,7 +508,7 @@ class Clip(models.Model):
if value: if value:
data[key] = value data[key] = value
data['duration'] = data['out'] - data['in'] data['duration'] = data['out'] - data['in']
data['cuts'] = tuple([c for c in self.item.get('cuts', []) if c > self.start and c < self.end]) add_cuts(data, self.item, self.start, self.end)
data['layers'] = self.get_layers(user) data['layers'] = self.get_layers(user)
data['streams'] = [s.file.oshash for s in self.item.streams()] data['streams'] = [s.file.oshash for s in self.item.streams()]
return data return data