MCPcopy
hub / github.com/mifi/editly / parseConfig

Function parseConfig

parseConfig.js:37–292  ·  view source on GitHub ↗
({ defaults: defaultsIn = {}, clips, arbitraryAudio: arbitraryAudioIn, backgroundAudioPath, backgroundAudioVolume, loopAudio, allowRemoteRequests, ffprobePath })

Source from the content-addressed store, hash-verified

35}
36
37export default async function parseConfig({ defaults: defaultsIn = {}, clips, arbitraryAudio: arbitraryAudioIn, backgroundAudioPath, backgroundAudioVolume, loopAudio, allowRemoteRequests, ffprobePath }) {
38 const defaults = {
39 duration: 4,
40 ...defaultsIn,
41 transition: defaultsIn.transition === null ? null : {
42 duration: 0.5,
43 name: 'random',
44 audioOutCurve: 'tri',
45 audioInCurve: 'tri',
46 ...defaultsIn.transition,
47 },
48 };
49
50 async function handleLayer(layer) {
51 const { type, ...restLayer } = layer;
52
53 // https://github.com/mifi/editly/issues/39
54 if (['image', 'image-overlay'].includes(type)) {
55 await assertFileValid(restLayer.path, allowRemoteRequests);
56 } else if (type === 'gl') {
57 await assertFileValid(restLayer.fragmentPath, allowRemoteRequests);
58 }
59
60 if (['fabric', 'canvas'].includes(type)) assert(typeof layer.func === 'function', '"func" must be a function');
61
62 if (['image', 'image-overlay', 'fabric', 'canvas', 'gl', 'radial-gradient', 'linear-gradient', 'fill-color'].includes(type)) return layer;
63
64 // TODO if random-background radial-gradient linear etc
65 if (type === 'pause') return handleLayer({ ...restLayer, type: 'fill-color' });
66
67 if (type === 'rainbow-colors') return handleLayer({ type: 'gl', fragmentPath: join(dirname, 'shaders/rainbow-colors.frag') });
68
69 if (type === 'editly-banner') {
70 const { fontPath } = layer;
71 return [
72 await handleLayer({ type: 'linear-gradient' }),
73 await handleLayer({ fontPath, type: 'title', text: 'Made with\nEDITLY\nmifi.no' }),
74 ];
75 }
76
77 // For convenience
78 if (type === 'title-background') {
79 const { text, textColor, background, fontFamily, fontPath } = layer;
80 const outLayers = [];
81 if (background) {
82 if (background.type === 'radial-gradient') outLayers.push(await handleLayer({ type: 'radial-gradient', colors: background.colors }));
83 else if (background.type === 'linear-gradient') outLayers.push(await handleLayer({ type: 'linear-gradient', colors: background.colors }));
84 else if (background.color) outLayers.push(await handleLayer({ type: 'fill-color', color: background.color }));
85 } else {
86 const backgroundTypes = ['radial-gradient', 'linear-gradient', 'fill-color'];
87 const randomType = backgroundTypes[Math.floor(Math.random() * backgroundTypes.length)];
88 outLayers.push(await handleLayer({ type: randomType }));
89 }
90 outLayers.push(await handleLayer({ type: 'title', fontFamily, fontPath, text, textColor }));
91 return outLayers;
92 }
93
94 if (['title', 'subtitle', 'news-title', 'slide-in-text'].includes(type)) {

Callers 2

EditlyFunction · 0.85
renderSingleFrameFunction · 0.85

Calls 6

checkTransitionFunction · 0.90
calcTransitionFunction · 0.90
readVideoFileInfoFunction · 0.90
readAudioFileInfoFunction · 0.90
handleLayerFunction · 0.85
validateArbitraryAudioFunction · 0.85

Tested by

no test coverage detected