From 841a654254372f755c5bbae8d70847a116e09b8e Mon Sep 17 00:00:00 2001 From: j Date: Wed, 8 Nov 2023 11:01:20 +0100 Subject: [PATCH] more advanced fragment parsing --- render.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/render.py b/render.py index 47c491e..1f88a6c 100644 --- a/render.py +++ b/render.py @@ -282,7 +282,7 @@ def render(root, scene, prefix=''): files.append(path) return files -def get_fragments(clips, voice_over): +def get_fragments(clips, voice_over, prefix): import itemlist.models import item.models from collections import defaultdict @@ -293,14 +293,37 @@ def get_fragments(clips, voice_over): if l.name.split(' ')[0].isdigit(): fragment = { 'name': l.name, - 'tags': [t['value'] for t in l.query['conditions'][1]['conditions'] if t['operator'] == '=='], - 'anti-tags': [t['value'] for t in l.query['conditions'][1]['conditions'] if t['operator'] == '!='], + 'tags': [], + 'anti-tags': [], 'description': l.description } + for con in l.query['conditions']: + if "conditions" in con: + for sub in con["conditions"]: + if sub['key'] == "tags" and sub['operator'] == '==': + fragment['tags'].append(sub['value']) + elif sub['key'] == "tags" and sub['operator'] == '!=': + fragment['tags'].append(sub['value']) + else: + print('unknown sub condition', sub) + elif con.get('key') == "tags" and con['operator'] == '==': + fragment['tags'].append(con['value']) + elif con.get('key') == "tags" and con['operator'] == '!=': + fragment['anti-tags'].append(con['value']) + fragment["id"] = int(fragment['name'].split(' ')[0]) + originals = [] + for i in l.get_items(l.user): + orig = i.files.filter(selected=True).first() + if orig: + ext = os.path.splitext(orig.data.path)[1] + type_ = i.data['type'][0].lower() + target = os.path.join(prefix, type_, i.data['title'] + ext) + originals.append(target) fragment['clips'] = [] for clip in clips: - if set(clip['tags']) & set(fragment['tags']) and not set(clip['tags']) & set(fragment['anti-tags']): + #if set(clip['tags']) & set(fragment['tags']) and not set(clip['tags']) & set(fragment['anti-tags']): + if clip['original'] in originals: fragment['clips'].append(clip) fragment["voice_over"] = voice_over.get(str(fragment["id"]), {}) fragments.append(fragment) @@ -322,7 +345,7 @@ def render_all(options): clips = json.load(fd) with open(os.path.join(prefix, "voice_over.json")) as fd: voice_over = json.load(fd) - fragments = get_fragments(clips, voice_over) + fragments = get_fragments(clips, voice_over, prefix) with open(os.path.join(prefix, "fragments.json"), "w") as fd: json.dump(fragments, fd, indent=2, ensure_ascii=False) position = target_position = 0