more advanced fragment parsing
This commit is contained in:
parent
3252392eb5
commit
841a654254
1 changed files with 28 additions and 5 deletions
33
render.py
33
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
|
||||
|
|
Loading…
Reference in a new issue