diff --git a/management/commands/generate_clips.py b/management/commands/generate_clips.py index 3b56c35..caec151 100644 --- a/management/commands/generate_clips.py +++ b/management/commands/generate_clips.py @@ -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", diff --git a/render.py b/render.py index d3571e2..aa0c491 100644 --- a/render.py +++ b/render.py @@ -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,8 +90,17 @@ 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: - clip = random_choice(seq, clips, True) + # 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] if not clips: @@ -90,22 +109,25 @@ def compose(clips, target=150, base=1024, voice_over=None): break length += clip['duration'] - fg = clip['foreground'] - if 'foley' in clip: - foley = clip['foley'] + if "foreground" not in clip and "animation" in clip: + fg = clip['animation'] else: - foley = fg - if 'foreground2' in clip: - if 'foreground3' in clip: - n = seq() - if n <= 3: # 0,1,2,3 - clip['foreground'] - elif n <= 6: # 4,5,6 - clip['foreground2'] - else: # 7,8,9 - clip['foreground3'] - elif chance(seq, 0.5): - fg = clip['foreground2'] + fg = clip['foreground'] + if 'foley' in clip: + foley = clip['foley'] + else: + foley = fg + if 'foreground2' in clip: + if 'foreground3' in clip: + n = seq() + if n <= 3: # 0,1,2,3 + clip['foreground'] + elif n <= 6: # 4,5,6 + clip['foreground2'] + else: # 7,8,9 + clip['foreground3'] + elif chance(seq, 0.5): + fg = clip['foreground2'] scene['front']['V1'].append({ 'duration': clip['duration'], @@ -123,20 +145,31 @@ def compose(clips, target=150, base=1024, voice_over=None): else: transparency_back = transparency transparency_front = 0 - scene['front']['V2'].append({ - 'duration': clip['duration'], - 'src': clip['background'], - "filter": { - 'transparency': transparency_front - } - }) - scene['back']['V1'].append({ - 'duration': clip['duration'], - 'src': clip['background'], - "filter": { - 'transparency': transparency_back - } - }) + if "background" in clip: + scene['front']['V2'].append({ + 'duration': clip['duration'], + 'src': clip['background'], + "filter": { + 'transparency': transparency_front + } + }) + scene['back']['V1'].append({ + 'duration': clip['duration'], + 'src': clip['background'], + "filter": { + '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'],