File size: 968 Bytes
3b81d2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { ClapSegment } from "@aitube/clap"

import { LayoutName } from "@/app/layouts"
import { layouts } from "@/app/layouts/settings"
import { getImageDimension } from "./getImageDimension"

export async function parseLayoutFromStoryboards(storyboards: ClapSegment[]): Promise<LayoutName> {

  let bestCandidate: LayoutName = "Layout0"

  for (const [layoutName, layoutPanels] of Object.entries(layouts)) {

    let nbMatchingStoryboards = 0
    let i = 0

    for (const { panel, orientation, width, height } of layoutPanels) {

      const storyboard = storyboards[i]

      if (!storyboard) { continue }
      if (!storyboard?.assetUrl) { continue }

      const imgDimension = await getImageDimension(storyboard.assetUrl)

      if (orientation === imgDimension.orientation) {
        nbMatchingStoryboards++
      }
      
      i++
    }

    if (nbMatchingStoryboards === 4) {
      bestCandidate = layoutName as LayoutName
    }
  }

  return bestCandidate
}