#!/usr/bin/env python3 """Rebuild the single-filter native FCP wrapper from versioned native samples. The helper exports this product's actual DYDescriptors and Foundation archives; it never loads or launches the vendor application. No GUI actions are performed. """ from pathlib import Path import argparse,base64,copy,hashlib,json,plistlib,subprocess,tempfile,xml.etree.ElementTree as E ROOT=Path(__file__).resolve().parent.parent TEMPLATE=ROOT/'template' SOURCES=TEMPLATE/'sources' PROJECT_UUID='7d468273c013498e9806a0d7bc32fddf' PLUGIN_UUID='1C17B73B-F229-4C09-A434-EAF6DFF5F22A' OUTPUT_VERSION='5.11' OUTPUT_DISPLAY_VERSION='5.4.5' NATIVE_ALPHABET='*-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' STANDARD_ALPHABET='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' CONTENT_TAGS={'scenenode','layer','group','filter','behavior','mask'} def sha(data):return hashlib.sha256(data).hexdigest() def model_identity(): files=['大鱼调色/Plugin/DYModel.h','大鱼调色/Plugin/DYManagedColor.h','大鱼调色/Plugin/DYManagedColor.mm','大鱼调色/Plugin/DYModel.mm','大鱼调色/Plugin/DYUniforms.h','大鱼调色/Plugin/DYColorManagement.h','大鱼调色/Plugin/DYCSTTypes.h','大鱼调色/Plugin/DYSpiderState.h','大鱼调色/Plugin/SpiderCore/DYColorMath.h','大鱼调色/Plugin/SpiderCore/DYSpiderMesh.hpp','template/tools/dump_model.mm','大鱼调色/Plugin/DYFilmTypes.h','大鱼调色/Plugin/DYFilmMath.h','大鱼调色/Plugin/DYToolState.h','大鱼调色/Plugin/DYToolState.mm','大鱼调色/Plugin/MaskCore/DYMaskOperator.h','大鱼调色/Plugin/MaskCore/DYMask.h'] return {name:sha((ROOT/name).read_bytes()) for name in files} def refresh_metadata(): cache=Path('/Users/mac/Library/Caches/CodexBuilds/com.dayu.color/template-model') cache.mkdir(parents=True,exist_ok=True) executable=cache/'dump_model' subprocess.run(['/usr/bin/python3',str(ROOT/'ColorManagement/build_runtime.py')],check=True) command=['xcrun','clang++','-std=c++20','-fno-objc-arc','-fblocks','-F','/Library/Developer/SDKs/FxPlug.sdk/Library/Frameworks','-F','/Library/Developer/Frameworks','-framework','Foundation','-framework','AppKit','-framework','FxPlug','-framework','CoreMedia','-Wl,-rpath,/Library/Developer/Frameworks','-I',str(ROOT/'大鱼调色/Plugin'),str(TEMPLATE/'tools/dump_model.mm'),str(ROOT/'大鱼调色/Plugin/DYModel.mm'),str(ROOT/'大鱼调色/Plugin/DYManagedColor.mm'),str(ROOT/'大鱼调色/Plugin/DYToolState.mm'),'@/Users/mac/Library/Caches/CodexBuilds/com.dayu.color/cms-runtime/bridge-link.rsp','-o',str(executable)] subprocess.run(command,check=True) result=json.loads(subprocess.check_output([str(executable)],text=True)) result['sourceSHA256']=model_identity() (SOURCES/'RegisteredParameters.json').write_text(json.dumps(result,ensure_ascii=False,indent=2,sort_keys=True)+'\n') executable.unlink() return result def metadata(): result=json.loads((SOURCES/'RegisteredParameters.json').read_text()) if result['sourceSHA256']!=model_identity():raise ValueError('DYModel changed. Review it, then regenerate metadata with --refresh-model.') pids=[str(p['pid']) for p in result['parameters']] if len(pids)!=len(set(pids)):raise ValueError('Duplicate native parameter ID') return result def custom_archive(encoded): # Motion custom data carrier = big-endian length, '*', NSKeyedArchive, zero. data=base64.b64decode(encoded) count=int.from_bytes(data[:8],'big') if data[8]!=42 or data[9+count:]!=b'\0':raise ValueError('Unexpected native custom data carrier') outer=plistlib.loads(data[9:9+count]);inner=plistlib.loads(outer['$objects'][1]) obj=inner['$objects'][1];name=inner['$objects'][obj['$class'].data]['$classname'] text=encoded.rstrip('=').translate(str.maketrans(STANDARD_ALPHABET,NATIVE_ALPHABET)) return text,name def build(model): root=E.parse(SOURCES/'NativeEffectSource.moef').getroot() scene=root.find('scene');project=scene.find('scenenode[@factoryID="4"]') source=scene.find('.//scenenode[@name="效果源"]') if source is None or root.get('version')!='5.13' or root.findtext('displayversion')!='5.6.7':raise ValueError('Unexpected native EffectSource source') # Same EffectSource/FxPlug/custom-archive shape exists in the identity- # recorded native 5.11 / Motion 5.4.5 reference. Drop only later optional # 3D/HDR editor hints; keep factory/node versions and color settings intact. root.set('version',OUTPUT_VERSION);root.find('displayversion').text=OUTPUT_DISPLAY_VERSION for parent in root.iter(): for child in list(parent): if child.tag in {'Object3DEnvironments','DRTSupport','onHDRDisplay','missingDynamicRangeType'}:parent.remove(child) if source.find('parameter[@id="2"]/parameter[@id="321"]').get('value')!='3':raise ValueError('Expected native EffectSource type 3') native_factories=E.parse(SOURCES/'NativeFactories.xml').getroot() lookup={f.get('uuid'):f for f in native_factories} factory_ids={'deca4859b16011d7a12d0003936f6f92':'5'} insert_at=list(root).index(root.findall('factory')[-1])+1 for uuid,fid in factory_ids.items(): factory=copy.deepcopy(lookup[uuid]);factory.set('id',fid);root.insert(insert_at,factory);insert_at+=1 filt=E.parse(SOURCES/'NativeFxPlugShell.xml').getroot();filt.set('pluginVersion','0') # Keep the original native host mix/flip/input-point/OSC parameters, replace # the product's entire registered parameter set and custom archives. host=list(filt.findall('parameter')) for node in host:filt.remove(node) for pid,name in [('9000','大鱼调色'),('9001','LUT 文件'),('9002','工具与蒙版')]: text,class_name=custom_archive(model['archivesBase64'][pid]) expected={'9000':'DYInspectorToken','9001':'DYAssetState','9002':'DYToolDocument'}[pid] if class_name!=expected:raise ValueError('Wrong custom parameter class') flags='12884901888' if pid=='9000' else '12889161776' param=E.SubElement(filt,'parameter',name=name,id=pid,flags=flags) E.SubElement(param,'numberOfKeypoints').text='0' E.SubElement(param,'defaultVal').text=text;E.SubElement(param,'dataValue').text=text for row in model['parameters']: value=format(float(row['default']),'.17g') host_default=format(float(row.get('hostDefault',row['default'])),'.17g') E.SubElement(filt,'parameter',name=row['title'],id=str(row['pid']),flags='12889161776' if row.get('notAnimatable') else '12889161760',default=host_default,value=value) for node in host: if node.get("id")=="10005":node.set("value","1");node.set("default","0");node.set("flags","8589934592") filt.append(node) source.append(filt) # User requested removal of the author's two display-only Rig widgets. # Do not regenerate their nodes, factories or published parameter rows. pub=scene.find('publishSettings') for node in list(pub): if node.tag!='version':pub.remove(node) E.SubElement(pub,'target',object='10060',channel='./9000',name='大鱼调色') E.SubElement(pub,'target',object='10060',channel='./10001',name='混合') current=scene.find('currentObject') if current is None: current=E.Element('currentObject');scene.insert(list(scene).index(scene.find('currentFrame'))+1,current) current.text=project.get('id');scene.find('currentFrame').text='0 1 1 0' for node in scene.iter(): flag=node.find('baseFlags') if flag is not None and node.tag in CONTENT_TAGS: value=int(flag.text);flag.text=str(value|0x10000001 if node is project else value&~0x10000001) scene.find('sceneSettings/backgroundColor').set('alpha','0') E.indent(root,space='\t') data=b'\n\n'+E.tostring(root,encoding='utf-8')+b'\n' return data def verify(data,model): root=E.fromstring(data);scene=root.find('scene');factories={f.get('id'):f.get('uuid') for f in root.findall('factory')} assert root.get('version')==OUTPUT_VERSION and root.findtext('displayversion')==OUTPUT_DISPLAY_VERSION assert all(not list(root.iter(tag)) for tag in ['Object3DEnvironments','DRTSupport','onHDRDisplay','missingDynamicRangeType']) filters=root.findall('.//filter') assert len(filters)==1 and filters[0].get('pluginUUID')==PLUGIN_UUID f=filters[0];params={p.get('id'):p for p in f.findall('parameter')} assert len(params)==len(list(f.findall('parameter'))) assert params["10005"].get("value")=="1" and params["10005"].get("flags")=="8589934592" and f.get("pluginVersion")=="0" for row in model['parameters']: p=params[str(row['pid'])];assert float(p.get('default'))==float(row.get('hostDefault',row['default'])) and float(p.get('value'))==float(row['default']) # FCP also applies a changed dataValue to existing nil-state instances. # Keep both carriers at the original registered value; V3 is explicit opt-in. for pid in ['9000','9001','9002']: assert params[pid].findtext('defaultVal')==params[pid].findtext('dataValue')==custom_archive(model['archivesBase64'][pid])[0] assert all(not v in data for v in (b'CameraRawTables',b'1.png',b'relativeURL')) assert len(root.findall('.//behavior'))==0 and len(root.findall('.//keypoint'))==0 assert scene.find('.//scenenode[@name="效果源"]/parameter[@id="2"]/parameter[@id="321"]').get('value')=='3' urls=[n.text for n in root.iter() if n.tag in ('pathURL','relativeURL')] assert urls==['Drop Zone.tiff'] projects=[n for n in scene.findall('scenenode') if factories.get(n.get('factoryID'))==PROJECT_UUID];assert len(projects)==1 project=projects[0];selected=[] for node in scene.iter(): if node.tag in CONTENT_TAGS and node is not project and node.find('baseFlags') is not None and int(node.findtext('baseFlags'))&0x10000001:selected.append(node.get('id')) assert not selected and scene.findtext('currentObject')==project.get('id') pub=scene.find('publishSettings').findall('target') assert [(t.get('object'),t.get('channel'),t.get('name')) for t in pub]==[('10060','./9000','大鱼调色'),('10060','./10001','混合')] assert all(scene.find('.//scenenode[@id="'+identity+'"]') is None for identity in ['10080','10081','10082']) assert all(text.encode() not in data for text in ['FCP 版本作者','更多模板浏览器访问','大鱼先森Media','dayu.media']) assert not any(f.get('uuid')=='dd0036f96c9e4bfdadb82f71fbf5c9d8' for f in root.findall('factory')) assert len({n.get('id') for n in scene.iter() if n.tag in CONTENT_TAGS})==len([n for n in scene.iter() if n.tag in CONTENT_TAGS]) return {'passed':True,'sha256':sha(data),'version':root.get('version'),'displayversion':root.findtext('displayversion'),'filterCount':1,'nativeFloatParameters':len(model['parameters']),'customParameters':3,'publications':[dict(t.attrib) for t in pub],'effectSourceType':3,'externalMediaRequired':False,'placeholder':'native Drop Zone.tiff','animationObjects':0,'copyright':{'removedAtUserRequest':True,'publishedDisplayRows':0,'displayRigAbsent':True},'savedSelection':{'passed':True,'selectedContentCount':0,'currentObjectIsProject':True},'hostUIVerified':False,'hostRenderVerified':False} def main(): p=argparse.ArgumentParser(description=__doc__);p.add_argument('--output',type=Path,default=TEMPLATE/'大鱼调色.moef');p.add_argument('--overwrite',action='store_true');p.add_argument('--refresh-model',action='store_true');args=p.parse_args() if args.output.exists() and not args.overwrite:raise FileExistsError('Output exists; choose another file or explicitly --overwrite') model=refresh_metadata() if args.refresh_model else metadata() data=build(model);report=verify(data,model) args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_bytes(data) (TEMPLATE/'verification/StaticContract.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n') print(json.dumps(report,ensure_ascii=False,indent=2)) if __name__=='__main__':main()