diff --git a/management/commands/generate_clips.py b/management/commands/generate_clips.py index caec151..3b56c35 100644 --- a/management/commands/generate_clips.py +++ b/management/commands/generate_clips.py @@ -1,6 +1,5 @@ import json import os -import re from collections import defaultdict from django.core.management.base import BaseCommand @@ -19,9 +18,9 @@ class Command(BaseCommand): def handle(self, **options): prefix = options['prefix'] clips = [] - for i in item.models.Item.objects.filter(sort__type='original'): + for i in item.models.Item.objects.filter(data__type__contains="Original"): qs = item.models.Item.objects.filter(data__title=i.data['title']).exclude(id=i.id) - if qs.count() >= 1: + if qs.count() >= 2: clip = {} durations = [] for e in item.models.Item.objects.filter(data__title=i.data['title']): @@ -42,18 +41,6 @@ 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: @@ -64,8 +51,6 @@ 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 aa0c491..d3571e2 100644 --- a/render.py +++ b/render.py @@ -35,16 +35,6 @@ 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 @@ -90,17 +80,8 @@ 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) + clip = random_choice(seq, clips, True) if not clips: clips = [c for c in all_clips if c != clip] if not clips: @@ -109,25 +90,22 @@ 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'] + fg = clip['foreground'] + if 'foley' in clip: + foley = clip['foley'] else: - 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'] + 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'], @@ -145,31 +123,20 @@ 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'], - "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['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 + } + }) scene['back']['V2'].append({ 'duration': clip['duration'], 'src': clip['original'],