jbilcke-hf HF staff commited on
Commit
cc43ec0
1 Parent(s): 080d350

fix formatSegmentForExport() for old .clap files

Browse files
src/components/dialogs/loader/LoadingDialog.tsx CHANGED
@@ -18,11 +18,6 @@ export function LoadingDialog({ className = '' }: { className?: string }) {
18
  const currentMessage = runningBlockerTasks[0]?.currentMessage || ''
19
  const progress = runningBlockerTasks[0]?.progress || 0
20
 
21
- console.log(`LoadingDialog:`, {
22
- runningBlockerTasks,
23
- isLoading,
24
- tasks,
25
- })
26
  return (
27
  <Dialog open={isLoading}>
28
  <DialogContent className="h-44">
 
18
  const currentMessage = runningBlockerTasks[0]?.currentMessage || ''
19
  const progress = runningBlockerTasks[0]?.progress || 0
20
 
 
 
 
 
 
21
  return (
22
  <Dialog open={isLoading}>
23
  <DialogContent className="h-44">
src/components/toolbars/top-menu/file/index.tsx CHANGED
@@ -99,14 +99,14 @@ export function TopMenuFile() {
99
  openClapUrl('/samples/claps/wasteland.clap')
100
  }}
101
  >
102
- [demo] Wasteland.clap
103
  </MenubarItem>
104
  <MenubarItem
105
  onClick={() => {
106
  openScreenplayUrl('/samples/scripts/The Apery.txt')
107
  }}
108
  >
109
- [demo] The Apery.txt
110
  </MenubarItem>
111
  <MenubarItem
112
  onClick={() => {
 
99
  openClapUrl('/samples/claps/wasteland.clap')
100
  }}
101
  >
102
+ [demo] Wasteland.clap
103
  </MenubarItem>
104
  <MenubarItem
105
  onClick={() => {
106
  openScreenplayUrl('/samples/scripts/The Apery.txt')
107
  }}
108
  >
109
+ [demo] The Apery.txt
110
  </MenubarItem>
111
  <MenubarItem
112
  onClick={() => {
src/lib/utils/formatSegmentForExport.ts CHANGED
@@ -2,6 +2,8 @@ import { ClapAssetSource, ClapSegmentCategory } from '@aitube/clap'
2
  import { TimelineSegment } from '@aitube/timeline'
3
 
4
  export type ExportableSegment = {
 
 
5
  segment: TimelineSegment
6
 
7
  // lowercase category name
@@ -41,7 +43,19 @@ export function formatSegmentForExport(
41
  ): ExportableSegment {
42
  const directory = `${segment.category}`.toLowerCase()
43
  const prefix = `shot_${String(index).padStart(4, '0')}_`
44
- let mimetype = `${segment.assetFileFormat || 'unknown/unknown'}`
 
 
 
 
 
 
 
 
 
 
 
 
45
  if (mimetype === 'audio/mpeg') {
46
  mimetype = 'audio/mp3'
47
  }
@@ -61,8 +75,9 @@ export function formatSegmentForExport(
61
  segment.assetUrl.startsWith('data:')
62
 
63
  const category = segment.category.toLocaleLowerCase()
64
-
65
  return {
 
66
  segment,
67
  category,
68
  shortId: `${category}${index}`,
 
2
  import { TimelineSegment } from '@aitube/timeline'
3
 
4
  export type ExportableSegment = {
5
+ id: string
6
+
7
  segment: TimelineSegment
8
 
9
  // lowercase category name
 
43
  ): ExportableSegment {
44
  const directory = `${segment.category}`.toLowerCase()
45
  const prefix = `shot_${String(index).padStart(4, '0')}_`
46
+
47
+
48
+ const notFoundFileFormat = 'unknown/unknown'
49
+ let fallbackFileFormat = notFoundFileFormat
50
+
51
+ if (segment.assetUrl.startsWith('data:')) {
52
+ const reg = new RegExp(/data:(.*);base64/gi)
53
+ fallbackFileFormat = `${reg.exec(segment.assetUrl)?.[1] || notFoundFileFormat}`
54
+ }
55
+
56
+ // old .clap files might not have the `assetFileFormat`
57
+ // which is why we perform a fallback check
58
+ let mimetype = `${segment.assetFileFormat || fallbackFileFormat}`
59
  if (mimetype === 'audio/mpeg') {
60
  mimetype = 'audio/mp3'
61
  }
 
75
  segment.assetUrl.startsWith('data:')
76
 
77
  const category = segment.category.toLocaleLowerCase()
78
+
79
  return {
80
+ id: segment.id,
81
  segment,
82
  category,
83
  shortId: `${category}${index}`,
src/services/io/useIO.ts CHANGED
@@ -12,7 +12,13 @@ import {
12
  parseClap,
13
  serializeClap,
14
  } from '@aitube/clap'
15
- import { TimelineStore, useTimeline, TimelineSegment } from '@aitube/timeline'
 
 
 
 
 
 
16
  import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
17
  import { IOStore, TaskCategory, TaskVisibility } from '@aitube/clapper-services'
18
  import { create } from 'zustand'
@@ -388,9 +394,16 @@ export const useIO = create<IOStore>((set, get) => ({
388
  value: 0,
389
  })
390
 
 
 
391
  const segments: ExportableSegment[] = timelineSegments
392
  .map((segment, i) => formatSegmentForExport(segment, i))
393
- .filter(({ isExportableToFile }) => isExportableToFile)
 
 
 
 
 
394
 
395
  const videos: FFMPegVideoInput[] = []
396
  const audios: FFMPegAudioInput[] = []
@@ -410,6 +423,7 @@ export const useIO = create<IOStore>((set, get) => ({
410
  assetSourceType = ClapAssetSource.PATH
411
 
412
  if (filePath.startsWith('video/')) {
 
413
  videos.push({
414
  data: base64DataUriToUint8Array(segment.assetUrl),
415
  startTimeInMs: segment.startTimeInMs,
@@ -420,8 +434,10 @@ export const useIO = create<IOStore>((set, get) => ({
420
 
421
  if (
422
  filePath.startsWith('music/') ||
 
423
  filePath.startsWith('dialogue/')
424
  ) {
 
425
  audios.push({
426
  data: base64DataUriToUint8Array(segment.assetUrl),
427
  startTimeInMs: segment.startTimeInMs,
 
12
  parseClap,
13
  serializeClap,
14
  } from '@aitube/clap'
15
+ import {
16
+ TimelineStore,
17
+ useTimeline,
18
+ TimelineSegment,
19
+ removeFinalVideosAndConvertToTimelineSegments,
20
+ getFinalVideo,
21
+ } from '@aitube/timeline'
22
  import { ParseScriptProgressUpdate, parseScriptToClap } from '@aitube/broadway'
23
  import { IOStore, TaskCategory, TaskVisibility } from '@aitube/clapper-services'
24
  import { create } from 'zustand'
 
394
  value: 0,
395
  })
396
 
397
+ const ignoreThisVideoSegmentId = (await getFinalVideo(clap))?.id || ''
398
+
399
  const segments: ExportableSegment[] = timelineSegments
400
  .map((segment, i) => formatSegmentForExport(segment, i))
401
+ .filter(
402
+ ({ id, isExportableToFile }) =>
403
+ isExportableToFile && id !== ignoreThisVideoSegmentId
404
+ )
405
+
406
+ console.log("segments:", segments)
407
 
408
  const videos: FFMPegVideoInput[] = []
409
  const audios: FFMPegAudioInput[] = []
 
423
  assetSourceType = ClapAssetSource.PATH
424
 
425
  if (filePath.startsWith('video/')) {
426
+ console.log('adding video')
427
  videos.push({
428
  data: base64DataUriToUint8Array(segment.assetUrl),
429
  startTimeInMs: segment.startTimeInMs,
 
434
 
435
  if (
436
  filePath.startsWith('music/') ||
437
+ filePath.startsWith('sound/') ||
438
  filePath.startsWith('dialogue/')
439
  ) {
440
+ console.log('adding audio')
441
  audios.push({
442
  data: base64DataUriToUint8Array(segment.assetUrl),
443
  startTimeInMs: segment.startTimeInMs,