Compare commits

...

3 commits

2 changed files with 80 additions and 32 deletions

View file

@ -1,5 +1,6 @@
import json
import os
import re
from collections import defaultdict
from django.core.management.base import BaseCommand
@ -18,9 +19,9 @@ class Command(BaseCommand):
def handle(self, **options):
prefix = options['prefix']
clips = []
for i in item.models.Item.objects.filter(data__type__contains="Original"):
for i in item.models.Item.objects.filter(sort__type='original'):
qs = item.models.Item.objects.filter(data__title=i.data['title']).exclude(id=i.id)
if qs.count() >= 2:
if qs.count() >= 1:
clip = {}
durations = []
for e in item.models.Item.objects.filter(data__title=i.data['title']):
@ -41,6 +42,18 @@ class Command(BaseCommand):
clip["duration"] = min(durations)
clip['tags'] = i.data.get('tags', [])
clip['editingtags'] = i.data.get('editingtags', [])
name = os.path.basename(clip['original'])
seqid = re.sub("Hotel Aporia_(\d+)", "S\\1_", name).split('_')[:2]
seqid = [b[1:] if b[0] in ('B', 'S') else '0' for b in seqid]
seqid[1] = ''.join([b for b in seqid[1] if b.isdigit()])
if not seqid[1]:
seqid[1] = '0'
try:
clip['seqid'] = int(''.join(['%06d' % int(b) for b in seqid]))
except:
print(name, seqid, 'failed')
raise
if "original" in clip and "foreground" in clip and "background" in clip:
clips.append(clip)
elif "original" in clip and "animation" in clip:
@ -51,6 +64,8 @@ class Command(BaseCommand):
with open(os.path.join(prefix, 'clips.json'), 'w') as fd:
json.dump(clips, fd, indent=2, ensure_ascii=False)
print("using", len(clips), "clips")
voice_over = defaultdict(dict)
for vo in item.models.Item.objects.filter(
data__type__contains="Voice Over",

View file

@ -35,6 +35,16 @@ def random_choice(seq, items, pop=False):
def chance(seq, chance):
return (seq() / 10) >= chance
def get_clip_by_seqid(clips, seqid):
selected = None
for i, clip in enumerate(clips):
if clip['seqid'] == seqid:
selected = i
break
if selected is not None:
return clips.pop(i)
return None
def compose(clips, target=150, base=1024, voice_over=None):
length = 0
@ -80,7 +90,16 @@ def compose(clips, target=150, base=1024, voice_over=None):
for vo in voice_overs:
scene['audio']['A3'].append(vo)
clip = None
while target - length > 0 and clips:
# coin flip which site is visible (50% chance)
if clip:
if chance(seq, 0.5):
next_seqid = clip['seqid'] + 1
clip = get_clip_by_seqid(clips, next_seqid)
else:
clip = None
if not clip:
clip = random_choice(seq, clips, True)
if not clips:
clips = [c for c in all_clips if c != clip]
@ -90,6 +109,9 @@ def compose(clips, target=150, base=1024, voice_over=None):
break
length += clip['duration']
if "foreground" not in clip and "animation" in clip:
fg = clip['animation']
else:
fg = clip['foreground']
if 'foley' in clip:
foley = clip['foley']
@ -123,6 +145,7 @@ def compose(clips, target=150, base=1024, voice_over=None):
else:
transparency_back = transparency
transparency_front = 0
if "background" in clip:
scene['front']['V2'].append({
'duration': clip['duration'],
'src': clip['background'],
@ -137,6 +160,16 @@ def compose(clips, target=150, base=1024, voice_over=None):
'transparency': transparency_back
}
})
else:
scene['front']['V2'].append({
'blank': True,
'duration': clip['duration'],
})
scene['back']['V1'].append({
'blank': True,
'duration': clip['duration'],
})
scene['back']['V2'].append({
'duration': clip['duration'],
'src': clip['original'],