File size: 36,837 Bytes
c1f12bf
 
 
 
 
5bd8810
 
c1f12bf
5bd8810
c1f12bf
 
 
 
 
 
 
5bd8810
c1f12bf
cc43ec0
 
 
 
 
 
86259b4
5bd8810
cc43ec0
c1f12bf
 
 
6024951
2068834
c1f12bf
d079437
c1f12bf
 
 
9c63d01
c1f12bf
 
 
2068834
c1f12bf
 
 
 
 
 
86259b4
 
5bd8810
86259b4
 
5bd8810
 
2068834
 
 
 
89b09eb
 
 
c1f12bf
89b09eb
 
 
 
2068834
5bd8810
bb4f86a
 
89b09eb
 
c1f12bf
2068834
 
89b09eb
c1f12bf
 
 
2068834
c1f12bf
89b09eb
2068834
c1f12bf
2068834
89b09eb
 
c1f12bf
89b09eb
 
 
 
 
 
c1f12bf
89b09eb
 
 
 
 
c1f12bf
 
2068834
 
c1f12bf
2068834
bb4f86a
 
c1f12bf
5bd8810
 
bb4f86a
2068834
 
c1f12bf
86259b4
5bd8810
 
 
 
 
 
 
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86259b4
5bd8810
 
86259b4
5bd8810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86259b4
5bd8810
86259b4
5bd8810
86259b4
5bd8810
 
 
 
86259b4
5bd8810
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
 
 
86259b4
5bd8810
 
 
 
 
 
 
2068834
5bd8810
 
2068834
c1f12bf
 
 
 
 
89b09eb
c1f12bf
 
 
 
89b09eb
 
 
 
299bd34
89b09eb
 
 
 
c1f12bf
 
89b09eb
 
d0d7bbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f12bf
 
 
 
 
 
 
 
 
 
 
 
299bd34
c1f12bf
89b09eb
 
c1f12bf
 
89b09eb
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
c1f12bf
 
89b09eb
 
5bd8810
89b09eb
8e2e66f
 
c1f12bf
 
 
 
 
8e2e66f
 
 
c1f12bf
8e2e66f
 
 
 
 
c1f12bf
 
8e2e66f
 
 
 
 
 
c1f12bf
 
 
 
 
 
 
 
 
 
 
 
8e2e66f
c1f12bf
8e2e66f
 
c1f12bf
 
8e2e66f
 
 
 
 
c1f12bf
 
8e2e66f
 
 
 
c1f12bf
8e2e66f
5bd8810
8e2e66f
2068834
 
 
 
 
c1f12bf
2068834
c1f12bf
2068834
 
 
 
 
 
c1f12bf
2068834
 
 
 
89b09eb
2068834
89b09eb
 
 
c1f12bf
 
 
 
89b09eb
 
 
c1f12bf
89b09eb
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
 
 
c1f12bf
89b09eb
5bd8810
89b09eb
 
 
 
 
 
 
 
c1f12bf
89b09eb
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
 
 
c1f12bf
 
89b09eb
 
 
 
 
 
c1f12bf
89b09eb
5bd8810
2068834
 
 
86f40f5
2068834
c1f12bf
 
 
2068834
89b09eb
c1f12bf
89b09eb
 
 
 
c1f12bf
89b09eb
 
 
 
c1f12bf
2068834
 
 
 
 
 
 
86f40f5
 
 
 
89b09eb
 
 
 
c1f12bf
2068834
89b09eb
 
 
2068834
 
 
 
 
 
9c21091
 
 
 
 
 
 
 
 
 
 
 
cc43ec0
 
9c21091
 
cc43ec0
 
 
 
 
ecec80b
9c21091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc43ec0
9c21091
 
 
 
 
 
 
 
 
 
cc43ec0
9c21091
 
cc43ec0
9c21091
 
 
 
 
 
 
 
2068834
 
 
9c21091
 
 
 
 
 
 
 
fd1df5e
9c21091
 
 
 
 
 
2068834
 
 
9c21091
c1f12bf
 
 
 
 
 
 
 
 
2068834
c1f12bf
 
2068834
 
 
 
c1f12bf
 
 
 
 
 
 
 
 
 
 
 
2068834
 
fd1df5e
 
c1f12bf
2068834
 
6024951
9c63d01
6024951
 
 
 
 
c1f12bf
6024951
 
 
 
985a523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c21091
 
985a523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c21091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
985a523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f12bf
985a523
c1f12bf
9c21091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
985a523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6024951
 
5bd8810
 
 
c1f12bf
9c63d01
 
083ce88
c1f12bf
083ce88
9c63d01
 
1425c47
c1f12bf
 
 
 
 
 
 
 
 
 
 
1425c47
c1f12bf
 
 
1425c47
c1f12bf
 
 
9c63d01
 
 
1425c47
9c63d01
1425c47
 
 
9c63d01
 
 
 
 
1425c47
 
 
 
 
9c63d01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f12bf
 
 
9c63d01
1425c47
9c63d01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f12bf
 
9c63d01
 
 
 
 
c1f12bf
 
 
9c63d01
 
1425c47
c1f12bf
 
 
1425c47
 
 
 
 
c1f12bf
 
 
1425c47
 
 
 
c1f12bf
 
 
9c63d01
1425c47
9c63d01
 
 
c1f12bf
 
 
9c63d01
c1f12bf
 
1425c47
 
 
 
 
 
 
 
 
c1f12bf
1425c47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1f12bf
 
1425c47
 
 
c1f12bf
 
1425c47
 
 
 
 
c1f12bf
 
1425c47
 
 
 
c1f12bf
 
1425c47
 
 
 
 
c1f12bf
 
1425c47
 
 
 
c1f12bf
 
1425c47
 
 
 
 
c1f12bf
 
1425c47
9c63d01
 
 
 
 
 
 
 
1425c47
9c63d01
 
1425c47
 
 
 
9c63d01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1425c47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c63d01
 
2068834
 
5bd8810
 
 
2068834
 
 
 
d0d7bbe
2068834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bd8810
 
 
2068834
c1f12bf
c35e031
 
 
 
 
 
 
 
c1f12bf
c35e031
77030e1
c1f12bf
 
c35e031
 
c1f12bf
c35e031
 
 
 
 
5bd8810
 
 
c35e031
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
'use client'

import {
  ClapAssetSource,
  ClapEntity,
  ClapMediaOrientation,
  ClapOutputType,
  ClapProject,
  ClapSegment,
  ClapSegmentCategory,
  ClapSegmentStatus,
  getClapAssetSourceType,
  newClap,
  newSegment,
  parseClap,
  serializeClap,
  UUID,
} from '@aitube/clap'
import {
  TimelineStore,
  useTimeline,
  TimelineSegment,
  removeFinalVideosAndConvertToTimelineSegments,
  getFinalVideo,
  DEFAULT_DURATION_IN_MS_PER_STEP,
  clapSegmentToTimelineSegment,
} from '@aitube/timeline'
import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
import { IOStore, TaskCategory, TaskVisibility } from '@aitube/clapper-services'
import { create } from 'zustand'
import * as fflate from 'fflate'

import { getDefaultIOState } from './getDefaultIOState'

import { blobToBase64DataUri } from '@/lib/utils/blobToBase64DataUri'
import { parseFileIntoSegments } from './parseFileIntoSegments'
import { useTasks } from '@/components/tasks/useTasks'

import { parseFileName } from './parseFileName'
import { useRenderer } from '../renderer'
import { base64DataUriToUint8Array } from '@/lib/utils/base64DataUriToUint8Array'

import { formatDuration } from '@/lib/utils/formatDuration'
import {
  ExportableSegment,
  formatSegmentForExport,
} from '@/lib/utils/formatSegmentForExport'
import { sleep } from '@/lib/utils/sleep'
import { FFMPegAudioInput, FFMPegVideoInput } from './ffmpegUtils'
import { createFullVideo } from './createFullVideo'
import { extractScenesFromVideo } from './extractScenesFromVideo'
import { extractCaptionsFromFrames } from './extractCaptionsFromFrames'
import { base64DataUriToFile } from '@/lib/utils/base64DataUriToFile'
import { useUI } from '../ui'
import { getTypeAndExtension } from '@/lib/utils/getTypeAndExtension'

export const useIO = create<IOStore>((set, get) => ({
  ...getDefaultIOState(),

  clear: () => {
    const renderer = useRenderer.getState()
    const timeline: TimelineStore = useTimeline.getState()

    // reset various things
    renderer.clear()
    timeline.clear()
  },
  openFiles: async (files: File[]) => {
    const { openClapBlob, openScreenplay, openVideo } = get()
    const timeline: TimelineStore = useTimeline.getState()
    const { segments, addSegments } = timeline

    if (Array.isArray(files)) {
      console.log('user tried to drop some files:', files)

      // for now let's simplify things, and only import the first file
      const file: File | undefined = files.at(0)
      if (!file) {
        return
      }

      const input = `${file.name || ''}`
      const { fileName, projectName, extension } = parseFileName(input)

      const fileType = `${file.type || ''}`

      console.log(`file type: ${fileType}`)

      const isClapFile = extension === 'clap'

      if (isClapFile) {
        await openClapBlob(projectName, fileName, file)
        return
      }

      const isTextFile = fileType.startsWith('text/')
      if (isTextFile) {
        await openScreenplay(projectName, fileName, file)
        return
      }

      const isAudioFile = fileType.startsWith('audio/')

      // TODO: detect the type of file, and do a different treatment based on this
      // screenplay files: -> analyze (if there is existing data, show a modal asking to save or not)
      // mp3 file: ->
      if (isAudioFile) {
        const newSegments = await parseFileIntoSegments({ file })

        console.log('calling  timeline.addSegments with:', newSegments)
        await timeline.addSegments({ segments: newSegments })

        return
      }

      const isVideoFile = fileType.startsWith('video/')
      if (isVideoFile) {
        await openVideo(projectName, fileName, file)
        return
      }
    }
    useUI.getState().setShowWelcomeScreen(false)
  },
  openVideo: async (
    projectName: string,
    fileName: string,
    fileContent: string | Blob
  ): Promise<void> => {
    const timeline: TimelineStore = useTimeline.getState()

    const sceneExtractionTask = useTasks.getState().add({
      category: TaskCategory.IMPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Starting up, can take a few minutes..`,
      successMessage: `Extracting scenes.. 100%`,
      value: 0,
    })

    const file =
      typeof fileContent === 'string'
        ? base64DataUriToFile(fileContent, fileName)
        : fileContent

    const scenes = await extractScenesFromVideo(file, {
      frameFormat: 'png', // in theory we could also use 'jpg', but this freezes FFmpeg
      maxWidth: 1024,
      maxHeight: 576,
      framesPerScene: 1,
      autoCrop: true,
      sceneThreshold: 0.1,
      minSceneDuration: 1,
      debug: true,
      onProgress: (progress: number) => {
        sceneExtractionTask.setProgress({
          message: `Extracting scenes.. ${progress}%`,
          value: progress,
        })
      },
    })

    // optional: reset the project
    // await timeline.setClap(newClap())

    let currentStoryboardIndex = 0
    let startTimeInMs = 0
    const durationInSteps = 4
    const durationInMs = durationInSteps * DEFAULT_DURATION_IN_MS_PER_STEP
    let endTimeInMs = startTimeInMs + durationInMs

    // TODO: extract info from the original video to determine things like
    // the orientation, duration..
    timeline.setClap(
      newClap({
        meta: {
          id: UUID(),
          title: projectName,
          description: `${projectName} (${fileName})`,
          synopsis: '',
          licence:
            "This OpenClap file is just a conversion from the original screenplay and doesn't claim any copyright or intellectual property. All rights reserved to the original intellectual property and copyright holders. Using OpenClap isn't piracy.",

          orientation: ClapMediaOrientation.LANDSCAPE,
          durationInMs: frames.length * durationInMs,

          // TODO: those should come from the Clapper user settings

          width: 1024,
          height: 576,

          defaultVideoModel: '', // <-- we should deprecate this no?
          extraPositivePrompt: '',
          screenplay: '',
          isLoop: false,
          isInteractive: false,
        },
      })
    )

    for (const scene of scenes) {
      console.log('parsing scene:', scene)
      try {
        const frameFile = base64DataUriToFile(
          scene.frames[0],
          `storyboard_${++currentStoryboardIndex}.png`
        )

        const assetDurationInMs = scene.endTimeInMs - scene.startTimeInMs

        // this returns multiple segments (video, image..)
        const newSegments = await parseFileIntoSegments({
          file: frameFile,
          startTimeInMs: scene.startTimeInMs,
          endTimeInMs: scene.endTimeInMs,
        })

        for (const newSegment of newSegments) {
          newSegment.assetDurationInMs = assetDurationInMs
          if (newSegment.category === ClapSegmentCategory.VIDEO) {
            const { assetFileFormat, outputType } = getTypeAndExtension(
              scene.video
            )
            newSegment.assetFileFormat = assetFileFormat
            newSegment.assetUrl = scene.video
            newSegment.status = ClapSegmentStatus.COMPLETED
            newSegment.outputType = outputType
          }
        }
        await timeline.addSegments({ segments: newSegments })
      } catch (err) {
        console.error(`failed to process scene:`, scene)
        console.error(err)
      }
    }

    sceneExtractionTask.success()

    const enableCaptioning = false

    if (enableCaptioning) {
      const captioningTask = useTasks.getState().add({
        category: TaskCategory.IMPORT,
        // visibility: TaskVisibility.BLOCKER,

        // since this is very long task, we can run it in the background
        visibility: TaskVisibility.BACKGROUND,
        initialMessage: `Analyzing storyboards..`,
        successMessage: `Analyzing storyboards.. 100% done`,
        value: 0,
      })

      console.log('calling extractCaptionsFromFrames() with:', frames)
      /*
      const captions = await extractCaptionsFromFrames(
        frames,
        (progress: number, storyboardIndex: number, nbStoryboards: number) => {
          captioningTask.setProgress({
            message: `Analyzing storyboards (${progress}%)`,
            value: progress,
          })
        }
      )
  
      console.log('captions:', captions)
      */
      // TODO: add

      captioningTask.success()
    }

    useUI.getState().setShowWelcomeScreen(false)
  },
  openScreenplay: async (
    projectName: string,
    fileName: string,
    fileContent: string | Blob
  ): Promise<void> => {
    const plainText =
      typeof fileContent === 'string'
        ? fileContent
        : await new Response(fileContent).text()

    const timeline: TimelineStore = useTimeline.getState()
    const task = useTasks.getState().add({
      category: TaskCategory.IMPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Loading ${fileName}`,
      successMessage: `Successfully loaded the screenplay!`,
      value: 0,
    })
    task.setProgress({
      message: 'Analyzing screenplay..',
      value: 10,
    })

    try {
      // this is the old way, based on a call to a separate API hosted on HF
      // obviously this wasn't very practical and easy to scale, so I'm dropping it
      //
      // const res = await fetch("https://jbilcke-hf-broadway-api.hf.space", {
      //   method: "POST",
      //   headers: { 'Content-Type': 'text/plain' },
      //   body: plainText,
      // })
      // const blob = await res.blob()
      // task.setProgress({
      //   message: "Loading scenes..",
      //   value: 50
      // })
      // const clap = await parseClap(blob)

      // new way: we analyze the screenplay on browser side
      const clap = await parseScriptToClap(
        plainText,
        async ({ value, sleepDelay, message }) => {
          const relativeProgressRatio = value / 100
          const totalProgress = 10 + relativeProgressRatio * 80
          task.setProgress({
            message,
            value: totalProgress,
          })
          await sleep(sleepDelay || 25)
        }
      )

      clap.meta.title = `${projectName || ''}`

      task.setProgress({
        message: 'Loading rendering engine..',
        value: 90,
      })

      await timeline.setClap(clap)

      task.setProgress({
        message: 'Nearly there..',
        value: 98,
      })

      task.success()
    } catch (err) {
      console.error('failed to import the screenplay:', err)
      task.fail(`${err || 'unknown screenplay import error'}`)
    } finally {
    }
    useUI.getState().setShowWelcomeScreen(false)
  },
  openScreenplayUrl: async (url: string) => {
    const timeline: TimelineStore = useTimeline.getState()

    const { fileName, projectName } = parseFileName(
      `${url.split('/').pop() || url}`
    )

    const task = useTasks.getState().add({
      category: TaskCategory.IMPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Loading ${fileName}`,
      successMessage: `Successfully downloaded the screenplay!`,
      value: 0,
    })

    task.setProgress({
      message: 'Downloading screenplay..',
      value: 10,
    })

    try {
      const res = await fetch(url)
      const plainText = await res.text()
      // new way: we analyze the screenplay on browser side
      const clap = await parseScriptToClap(
        plainText,
        async ({ value, sleepDelay, message }) => {
          const relativeProgressRatio = value / 100
          const totalProgress = 10 + relativeProgressRatio * 80
          task.setProgress({
            message,
            value: totalProgress,
          })
          await sleep(sleepDelay || 25)
        }
      )

      clap.meta.title = `${projectName || ''}`

      task.setProgress({
        message: 'Loading rendering engine..',
        value: 90,
      })

      await timeline.setClap(clap)

      task.setProgress({
        message: 'Nearly there..',
        value: 98,
      })

      task.success()
    } catch (err) {
      task.fail(`${err || 'unknown error'}`)
    }
    useUI.getState().setShowWelcomeScreen(false)
  },
  saveAnyFile: (blob: Blob, fileName: string) => {
    // Create an object URL for the compressed clap blob
    // object urls are short-lived urls, with the benefit of having a short id too

    const objectUrl = URL.createObjectURL(blob)

    // Create an anchor element and force browser download
    const anchor = document.createElement('a')
    anchor.href = objectUrl

    anchor.download = fileName

    document.body.appendChild(anchor) // Append to the body (could be removed once clicked)
    anchor.click() // Trigger the download

    // Cleanup: revoke the object URL and remove the anchor element
    URL.revokeObjectURL(objectUrl)
    document.body.removeChild(anchor)
  },

  openClapUrl: async (url: string) => {
    const timeline: TimelineStore = useTimeline.getState()
    const { setClap } = timeline

    const { fileName, projectName } = parseFileName(
      `${url.split('/').pop() || url}`
    )

    const task = useTasks.getState().add({
      category: TaskCategory.IMPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Loading ${fileName}`,
      successMessage: `Successfully downloaded the project!`,
      value: 0,
    })

    task.setProgress({
      message: 'Downloading file..',
      value: 10,
    })

    try {
      const res = await fetch(url)
      const blob = await res.blob()

      task.setProgress({
        message: 'Loading scenes..',
        value: 30,
      })

      const clap = await parseClap(blob)
      clap.meta.title = `${projectName}`

      task.setProgress({
        message: 'Loading rendering engine..',
        value: 70,
      })

      await setClap(clap)

      task.success()
    } catch (err) {
      task.fail(`${err || 'unknown error'}`)
    }
    useUI.getState().setShowWelcomeScreen(false)
  },
  openClapBlob: async (projectName: string, fileName: string, blob: Blob) => {
    const timeline: TimelineStore = useTimeline.getState()
    const { setClap } = timeline

    const task = useTasks.getState().add({
      category: TaskCategory.IMPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Loading ${fileName}`,
      successMessage: `Successfully loaded the project!`,
      value: 0,
    })
    try {
      task.setProgress({
        message: 'Loading scenes..',
        value: 30,
      })

      const clap = await parseClap(blob)
      clap.meta.title = `${projectName}`

      task.setProgress({
        message: 'Loading rendering engine..',
        value: 70,
      })

      await setClap(clap)

      task.success()
    } catch (err) {
      task.fail(`${err || 'unknown error'}`)
    }
    useUI.getState().setShowWelcomeScreen(false)
  },
  saveClap: async () => {
    const { saveAnyFile } = get()
    const { clap, entities, entityIndex } = useTimeline.getState()

    if (!clap) {
      throw new Error(`cannot save a clap.. if there is no clap`)
    }

    const tasks = useTasks.getState()

    const task = tasks.add({
      category: TaskCategory.EXPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Exporting project to OpenClap..`,
      successMessage: `Successfully exported the project!`,
      // mode: "percentage", // default
      // min: 0, // default
      // max: 100 // default
    })

    // make sure we update the total duration
    for (const s of clap.segments) {
      if (s.endTimeInMs > clap.meta.durationInMs) {
        clap.meta.durationInMs = s.endTimeInMs
      }
    }

    // update the clap with the in-memory versions of the entities
    clap.entities = entities
    clap.entityIndex = entityIndex

    // TODO: serializeClap should have a progress callback, so that we can
    // track the progression.
    //
    // also, I'm 100% aware that at some point we will just want to use the
    // desktop version of Clapper, so that we can write the gzip stream directly to the disk
    const blob: Blob = await serializeClap(clap)
    saveAnyFile(blob, `my_project.clap`) // <-- TODO use the project filename

    task.success()
  },

  saveVideoFile: async () => {
    const { saveAnyFile } = get()
    console.log(`rendering project using the free community server..`)

    const timeline: TimelineStore = useTimeline.getState()

    const { clap, totalDurationInMs, segments: timelineSegments } = timeline

    const task = useTasks.getState().add({
      category: TaskCategory.EXPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Rendering the project to MP4..`,
      successMessage: `Successfully exported the MP4 video!`,
      value: 0,
    })

    const ignoreThisVideoSegmentId = (await getFinalVideo(clap))?.id || ''

    const segments: ExportableSegment[] = timelineSegments
      .map((segment, i) => formatSegmentForExport(segment, i))
      .filter(
        ({ id, isExportableToFile }) =>
          isExportableToFile && id !== ignoreThisVideoSegmentId
      )

    console.log('segments:', segments)

    const videos: FFMPegVideoInput[] = []
    const audios: FFMPegAudioInput[] = []

    segments.forEach(
      ({
        segment,
        prefix,
        filePath,
        assetUrl,
        assetSourceType,
        isExportableToFile,
      }) => {
        // we extract the base64 files
        if (isExportableToFile) {
          assetUrl = filePath
          assetSourceType = ClapAssetSource.PATH

          if (filePath.startsWith('video/')) {
            console.log('adding video')
            videos.push({
              data: base64DataUriToUint8Array(segment.assetUrl),
              startTimeInMs: segment.startTimeInMs,
              endTimeInMs: segment.endTimeInMs,
              durationInSecs: segment.assetDurationInMs / 1000,
            })
          }

          if (
            filePath.startsWith('music/') ||
            filePath.startsWith('sound/') ||
            filePath.startsWith('dialogue/')
          ) {
            console.log('adding audio')
            audios.push({
              data: base64DataUriToUint8Array(segment.assetUrl),
              startTimeInMs: segment.startTimeInMs,
              endTimeInMs: segment.endTimeInMs,
              durationInSecs: segment.assetDurationInMs / 1000,
            })
          }
        }
      }
    )

    const fullVideo = await createFullVideo(
      videos,
      audios,
      1024,
      576,
      totalDurationInMs,
      (progress, message) => {
        task.setProgress({
          message: `Rendering video (${Math.round(progress)}%)`,
          value: progress * 0.9,
        })
      }
    )

    const videoBlob = new Blob([fullVideo], { type: 'video/mp4' })

    const videoDataUrl = await blobToBase64DataUri(videoBlob)

    const alreadyAnEmbeddedFinalVideo = timelineSegments
      .filter(
        (s) =>
          s.category === ClapSegmentCategory.VIDEO &&
          s.status === ClapSegmentStatus.COMPLETED &&
          s.startTimeInMs === 0 &&
          s.endTimeInMs === clap.meta.durationInMs &&
          s.assetUrl
      )
      .at(0)

    // inject the final mp4 video file into the .clap
    if (alreadyAnEmbeddedFinalVideo) {
      console.log(`editing the clap to update the final video`)
      alreadyAnEmbeddedFinalVideo.assetUrl = videoDataUrl
    } else {
      console.log(`editing the clap to add a new final video`)
      clap.segments.push(
        newSegment({
          category: ClapSegmentCategory.VIDEO,
          status: ClapSegmentStatus.COMPLETED,
          startTimeInMs: 0,
          endTimeInMs: clap.meta.durationInMs,
          assetUrl: videoDataUrl,
          assetDurationInMs: clap.meta.durationInMs,
          assetSourceType: getClapAssetSourceType(videoDataUrl),
          outputGain: 1.0,
        })
      )
    }

    task.success()

    saveAnyFile(videoBlob, 'my_project.mp4')
  },

  saveZipFile: async () => {
    const { saveAnyFile, generateMLT } = get()
    console.log(`exporting project to ZIP..`)

    const task = useTasks.getState().add({
      category: TaskCategory.EXPORT,
      visibility: TaskVisibility.BLOCKER,
      initialMessage: `Exporting project to ZIP..`,
      successMessage: `Successfully exported the project!`,
      value: 0,
    })

    try {
      const timeline: TimelineStore = useTimeline.getState()
      const { clap, segments: timelineSegments } = timeline
      const segments: ExportableSegment[] = timelineSegments
        .map((segment, i) => formatSegmentForExport(segment, i))
        .filter(({ isExportableToFile }) => isExportableToFile)

      let files: fflate.AsyncZippable = {}

      files['screenplay.txt'] = fflate.strToU8(clap.meta.screenplay)

      files['meta.json'] = fflate.strToU8(JSON.stringify(clap.meta, null, 2))

      const shotcutMltXml = await generateMLT()
      files['shotcut_project.mlt'] = fflate.strToU8(shotcutMltXml)

      const videos: FFMPegVideoInput[] = []
      const audios: FFMPegAudioInput[] = []

      const includeFullVideo = false

      segments.forEach(
        ({
          segment,
          prefix,
          filePath,
          assetUrl,
          assetSourceType,
          isExportableToFile,
        }) => {
          // we extract the base64 files
          if (isExportableToFile) {
            files[filePath] = [
              // we don't compress assets since normally they already use
              // some form of compression (PNG, JPEG, MP3, MP4 etc..)
              base64DataUriToUint8Array(segment.assetUrl),
              { level: 0 },
            ]
            assetUrl = filePath
            assetSourceType = ClapAssetSource.PATH

            if (includeFullVideo) {
              if (filePath.startsWith('video/')) {
                videos.push({
                  data: base64DataUriToUint8Array(segment.assetUrl),
                  startTimeInMs: segment.startTimeInMs,
                  endTimeInMs: segment.endTimeInMs,
                  durationInSecs: segment.assetDurationInMs / 1000,
                })
              }

              if (
                filePath.startsWith('music/') ||
                filePath.startsWith('dialogue/')
              ) {
                audios.push({
                  data: base64DataUriToUint8Array(segment.assetUrl),
                  startTimeInMs: segment.startTimeInMs,
                  endTimeInMs: segment.endTimeInMs,
                  durationInSecs: segment.assetDurationInMs / 1000,
                })
              }
            }
          }

          // segment metadata
          files[`segments/${prefix}${segment.id}.json`] = fflate.strToU8(
            JSON.stringify(
              {
                ...segment,
                assetUrl,
                assetSourceType,
              },
              null,
              2
            )
          )
        }
      )

      if (includeFullVideo) {
        const fullVideo = await createFullVideo(
          videos,
          audios,
          clap.meta.width,
          clap.meta.height,
          timeline.totalDurationInMs,
          (progress, message) => {
            task.setProgress({
              message,
              value: progress * 0.9,
            })
          }
        )

        files['video/full.mp4'] = [
          // we don't compress assets since normally they already use
          // some form of compression (PNG, JPEG, MP3, MP4 etc..)
          fullVideo as Uint8Array,
          { level: 0 },
        ]
      }

      fflate.zip(
        files,
        {
          // options
        },
        (error, zipFile) => {
          task.setProgress({
            message: 'Saving to file..',
            value: 100,
          })
          saveAnyFile(new Blob([zipFile]), 'my_project.zip')
          task.success()
        }
      )
    } catch (err) {
      console.error(err)
      task.fail(`${err || 'unknown error'}`)
    }
  },

  openMLT: async (file: File) => {
    useUI.getState().setShowWelcomeScreen(false)
  },
  saveMLT: async () => {},
  generateMLT: async (): Promise<string> => {
    const timeline: TimelineStore = useTimeline.getState()
    const { clap, segments: timelineSegments } = timeline

    const segments: ExportableSegment[] = timelineSegments
      .map((segment, i) => formatSegmentForExport(segment, i))
      .filter(({ isExportableToFile }) => isExportableToFile)

    const videos: ExportableSegment[] = segments.filter(
      ({ segment }) => segment.category === ClapSegmentCategory.VIDEO
    )

    const storyboards: ExportableSegment[] = segments.filter(
      ({ segment }) => segment.category === ClapSegmentCategory.STORYBOARD
    )

    const dialogues: ExportableSegment[] = segments.filter(
      ({ segment }) => segment.category === ClapSegmentCategory.DIALOGUE
    )

    const sounds: ExportableSegment[] = segments.filter(
      ({ segment }) => segment.category === ClapSegmentCategory.SOUND
    )

    const music: ExportableSegment[] = segments.filter(
      ({ segment }) => segment.category === ClapSegmentCategory.MUSIC
    )

    // want to see some colors? install es6-string-html in your VSCode
    return /* HTML*/ `<?xml version="1.0" standalone="no"?>
<mlt LC_NUMERIC="C" version="7.24.0" title="${clap.meta.title}" producer="main_bin">
  <profile
    description="${clap.meta.width}:${clap.meta.height}"
    width="${clap.meta.width}"
    height="${clap.meta.height}"
    progressive="0"
    sample_aspect_num="1"
    sample_aspect_den="1"
    display_aspect_num="16"
    display_aspect_den="9"

    ${
      ''
      // a good reminder we should add a feature to keep track of the FPS in Clapper
    }
    frame_rate_num="25"
    frame_rate_den="1"
    colorspace="709"
  />
  <playlist id="main_bin">
    <property name="xml_retain">1</property>
  </playlist>
  <producer id="black" in="00:00:00.000" out="${formatDuration(clap.meta.durationInMs)}">
    <property name="length">${formatDuration(clap.meta.durationInMs)}</property>
    <property name="eof">pause</property>
    <property name="resource">0</property>
    <property name="aspect_ratio">1</property>
    <property name="mlt_service">color</property>
    <property name="mlt_image_format">rgba</property>
    <property name="set.test_audio">0</property>
  </producer>
  <playlist id="background">
    <entry producer="black" in="00:00:00.000" out="${formatDuration(clap.meta.durationInMs)}" />
  </playlist>
  ${segments
    .map(
      ({ segment, shortId, fileName, filePath, index }) => /* HTML*/ `
  <producer
    id="${shortId}"
    in="${formatDuration(0)}"
    out="${formatDuration(clap.meta.durationInMs)}">
    <property name="length">${formatDuration(clap.meta.durationInMs)}</property>
    <property name="eof">pause</property>
    <property name="resource">${filePath}</property>
    <property name="ttl">1</property>
    <property name="aspect_ratio">1</property>
    <property name="meta.media.progressive">1</property>
    <property name="seekable">1</property>
    <property name="format">1</property>
    <property name="meta.media.width">${clap.meta.width}</property>
    <property name="meta.media.height">${clap.meta.height}</property>
    <property name="mlt_service">qimage</property>
    <property name="creation_time">${
      segment.createdAt || new Date().toISOString()
    }</property>
    <property name="shotcut:skipConvert">1</property>
    ${
      // uh, okay.. do we really need this?..
      // <property name="shotcut:hash">b22b329e4916bda3ada2ed544c9ba2b9</property>
      ''
    }
    <property name="shotcut:caption">${fileName}</property>
    ${
      ''
      // not sure what  <property name="xml">was here</property
      // is supposed to be
    }
    <property name="xml">was here</property>
  </producer>
  `
    )
    .join('')}
  <playlist id="playlist0">
    <property name="shotcut:video">1</property>
    <property name="shotcut:name">Video clips</property>
    ${videos
      .map(
        ({ segment, shortId }) => /* HTML*/ `
    <entry
      producer="${shortId}"
      in="${formatDuration(0)}"
      out="${formatDuration(segment.assetDurationInMs)}"
    />
`
      )
      .join('')}
  </playlist>
  <playlist id="playlist1">
    <property name="shotcut:video">1</property>
    <property name="shotcut:name">Storyboards</property>
    ${storyboards
      .map(
        ({ segment, shortId }) => /* HTML*/ `
    <entry
      producer="${shortId}"
      in="${formatDuration(0)}"
      out="${formatDuration(segment.assetDurationInMs)}"
    />
`
      )
      .join('')}
  </playlist>
  ${[...dialogues, ...sounds, ...music].map(
    ({ segment, filePath, fileName, shortId }) => /* HTML*/ `
  <chain id="${shortId}" out="${formatDuration(clap.meta.durationInMs)}">
    <property name="length">${formatDuration(clap.meta.durationInMs)}</property>
    <property name="eof">pause</property>
    <property name="resource">${filePath}</property>
    <property name="mlt_service">avformat-novalidate</property>
    <property name="meta.media.nb_streams">1</property>
    <property name="meta.media.0.stream.type">audio</property>
    ${
      ''
      /*
    I don't think we absolutely need to provide those as this is just meta

    <property name="meta.media.0.codec.sample_fmt">fltp</property>
    <property name="meta.media.0.codec.sample_rate">44100</property>
    <property name="meta.media.0.codec.channels">2</property>
    <property name="meta.media.0.codec.layout">stereo</property>
    <property name="meta.media.0.codec.name">mp3float</property>
    <property name="meta.media.0.codec.long_name">MP3 (MPEG audio layer 3)</property>
    <property name="meta.media.0.codec.bit_rate">150551</property>
    <property name="meta.attr.0.stream.encoder.markup">Lavc60.3.</property>
    <property name="meta.attr.encoder.markup">Lavf60.3.100</property>
    */
    }
    <property name="seekable">1</property>
    <property name="audio_index">0</property>
    <property name="video_index">-1</property>
    <property name="creation_time">${segment.createdAt}</property>
    <property name="astream">0</property>
    <property name="shotcut:skipConvert">1</property>
    ${
      ''
      // yeah well, let's skip this one as well
      // <property name="shotcut:hash">ee26f27a566e64d5ed116f433012e3d6</property>
    }
    <property name="shotcut:caption">${fileName}</property>
  </chain>`
  )}
  <playlist id="playlist2">
    <property name="shotcut:audio">1</property>
    <property name="shotcut:name">Dialogues & speech</property>
    ${dialogues.map(
      ({ segment, shortId }) => /* HTML*/ `
    <entry
      producer="${shortId}"
      in="${segment.startTimeInMs}"
      out="${segment.endTimeInMs}"
    />
    `
    )}
  </playlist>
  <playlist id="playlist3">
    <property name="shotcut:audio">1</property>
    <property name="shotcut:name">Sound effects</property>
    ${sounds.map(
      ({ segment, shortId }) => /* HTML*/ `
    <entry
      producer="${shortId}"
      in="${segment.startTimeInMs}"
      out="${segment.endTimeInMs}"
    />
    `
    )}
  </playlist>
  <playlist id="playlist4">
    <property name="shotcut:audio">1</property>
    <property name="shotcut:name">Music</property>
    ${music.map(
      ({ segment, shortId }) => /* HTML*/ `
    <entry
      producer="${shortId}"
      in="${segment.startTimeInMs}"
      out="${segment.endTimeInMs}"
    />
    `
    )}
  </playlist>
  <tractor
    id="tractor0"
    title="Shotcut version 24.04.28"
    in="00:00:00.000"
    out="${formatDuration(clap.meta.durationInMs)}">
    <property name="shotcut">1</property>
    <property name="shotcut:projectAudioChannels">2</property>
    <property name="shotcut:projectFolder">1</property>
    <property name="shotcut:skipConvert">0</property>
    <track producer="background"/>
    <track producer="playlist0"/>
    <track producer="playlist1"/>
    <track producer="playlist2" hide="video" />
    <track producer="playlist3" hide="video" />
    <track producer="playlist4" hide="video" />
    <transition id="transition0">
      <property name="a_track">0</property>
      <property name="b_track">1</property>
      <property name="mlt_service">mix</property>
      <property name="always_active">1</property>
      <property name="sum">1</property>
    </transition>
    <transition id="transition1">
      <property name="a_track">0</property>
      <property name="b_track">1</property>
      <property name="version">0.1</property>
      <property name="mlt_service">frei0r.cairoblend</property>
      <property name="threads">0</property>
      <property name="disable">1</property>
    </transition>
    <transition id="transition2">
    <property name="a_track">0</property>
    <property name="b_track">1</property>
    <property name="version">0.1</property>
    <property name="mlt_service">frei0r.cairoblend</property>
    <property name="threads">0</property>
    <property name="disable">1</property>
  </transition>
    <transition id="transition3">
      <property name="a_track">0</property>
      <property name="b_track">2</property>
      <property name="mlt_service">mix</property>
      <property name="always_active">1</property>
      <property name="sum">1</property>
    </transition>
    <transition id="transition4">
    <property name="a_track">0</property>
    <property name="b_track">3</property>
    <property name="mlt_service">mix</property>
    <property name="always_active">1</property>
    <property name="sum">1</property>
  </transition>
  <transition id="transition5">
  <property name="a_track">0</property>
  <property name="b_track">3</property>
  <property name="mlt_service">mix</property>
  <property name="always_active">1</property>
  <property name="sum">1</property>
</transition>
  </tractor>
</mlt>`
  },

  openKdenline: async (file: File) => {
    useUI.getState().setShowWelcomeScreen(false)
  },

  saveKdenline: async () => {
    const { saveAnyFile } = get()
    const clap: ClapProject = useTimeline.getState().clap
    // const tracks: ClapTracks = useTimeline.getState().tracks

    throw new Error(`cannot run in a browser, unfortunately`)

    /*
    // hum.. we should add FPS to the ClapProject metadata
    const fps = 30 // clap.meta

    // for documentation, look at the example test file in:
    // https://www.npmjs.com/package/kdenlive?activeTab=code
    const project = new Project(fps)

    const cameraSegments = clap.segments.filter(s => s.category === ClapSegmentCategory.CAMERA)
 
    const segmentsWithNonEmptyAssets = clap.segments.filter(s => s.assetUrl)

    // const videoSegments = clap.segments.filter(s => s.category === ClapSegmentCategory.VIDEO && s.assetUrl)
    const videoTractor = project.addVideoTractor()

    // const soundSegments = clap.segments.filter(s => s.category === ClapSegmentCategory.SOUND && s.assetUrl)
    const soundTractor = project.addAudioTractor()

    // const voiceSegments = clap.segments.filter(s => s.category === ClapSegmentCategory.DIALOGUE && s.assetUrl)
    const voiceTractor = project.addAudioTractor()

    // const musicSegments = clap.segments.filter(s => s.category === ClapSegmentCategory.MUSIC && s.assetUrl)
    const musicTractor = project.addAudioTractor()

    for (const shot of cameraSegments) {
      const videoSegments = filterSegments(
        ClapSegmentFilteringMode.ANY,
        shot,
        segmentsWithNonEmptyAssets,
        ClapSegmentCategory.VIDEO
      )
      const videoSegment = videoSegments.at(0)
      if (videoSegment) { continue }

      const producer = project.addProducer(`${videoSegment.id}.mp4`)
			
      const entry = new Entry(
        producer,
        formatDuration(shot.startTimeInMs),
        formatDuration(shot.endTimeInMs)
      )
			videoTractor.addEntry(entry)
			// audio_track.addEntry(entry)
    }

    const xml = await project.toXML()
    const blob = new Blob([xml], { type: "text/xml" })
    saveAnyFile(blob, `my_project.kdenlive`)

    */
  },

  openOpenTimelineIO: async (file: File) => {
    useUI.getState().setShowWelcomeScreen(false)
  },

  saveOpenTimelineIO: async () => {},

  saveEntitiesToClap: async (entities: ClapEntity[]): Promise<void> => {
    const blob = await serializeClap(newClap({ entities }))
    get().saveAnyFile(blob, `my_entities.clap`)
  },

  openEntitiesFromClap: async (file: File): Promise<ClapEntity[]> => {
    if (!file) {
      throw new Error('openEntities: no file provided')
    }

    const input = `${file.name || ''}`
    const fileType = `${file.type || ''}`
    console.log(`file type: ${fileType}`)

    const isClapFile = parseFileName(input).extension === 'clap'
    if (!isClapFile) {
      throw new Error(`openEntities: cannot open this file type: ${fileType}`)
    }

    const { entities } = await parseClap(file)

    useUI.getState().setShowWelcomeScreen(false)

    return entities
  },
}))