(filePath: string)
| 35 | * Detect the format of a transcript file from its extension and content. |
| 36 | */ |
| 37 | export function detectFormat(filePath: string): TranscriptFormat { |
| 38 | const ext = extname(filePath).toLowerCase(); |
| 39 | if (ext === ".srt") return "srt"; |
| 40 | if (ext === ".vtt") return "vtt"; |
| 41 | if (ext === ".json") return detectJsonFormat(JSON.parse(readFileSync(filePath, "utf-8"))); |
| 42 | throw new Error(`Unsupported transcript file extension: ${ext}. Use .json, .srt, or .vtt`); |
| 43 | } |
| 44 | |
| 45 | function detectJsonFormat(raw: unknown): TranscriptFormat { |
| 46 | if (raw && typeof raw === "object" && !Array.isArray(raw)) { |
no test coverage detected