-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
executable file
·80 lines (62 loc) · 1.85 KB
/
cli.js
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
#!/usr/bin/env node
/**
* srt2subtitles
* Generate editable video subtitles in Final Cut Pro/Premiere Pro from a SRT file.
*
* @author Sherry Wang <https://github.com/shaishaicookie>
*/
import fcpxml from './utils/fcpxml.js'
// import cli from './utils/cli.js';
import meow from 'meow'
import ora from 'ora'
import path from 'node:path'
import fs from 'node:fs'
const cli = meow(`
Usage
$ srt2subtitles <srt> <fps> [destination]
$ srt2subtitles <srt> <fps> [destination]
Examples
$ srt2subtitles TheImitationGame.srt 25
$ srt2subtitles TheImitationGame.srt 29.97 ./subtitles/
`, {});
const input = cli.input;
let [srt_path, fps, destination_path] = cli.input
if (!srt_path) {
console.error('Specify a SRT file')
process.exit(1)
}
if (srt_path && !srt_path.endsWith('.srt')) {
console.error('Enter correct SRT file')
process.exit(1)
}
if (!fps) {
console.error('Specify frame rate')
process.exit(1)
}
if (fps && !parseFloat(fps)) {
console.error('Enter correct fps number')
process.ext(1)
}
if (srt_path && !srt_path.endsWith('.srt') && fps && !parseFloat(fps)) {
console.error('Enter correct SRT file')
console.error('Enter correct fps number')
process.exit(1)
}
if (!destination_path) {
destination_path = process.cwd()
}
const spinner = ora('Creating editable subtitles XML files').start();
try {
fcpxml(srt_path, fps, destination_path)
const project_name = path.parse(srt_path).name
// check fcpxml file
const fcpxml_path = path.join(destination_path, `${project_name}.fcpxml`)
const has_fcpxml = fs.existsSync(fcpxml_path)
if (has_fcpxml) {
spinner.succeed(`Created ${project_name}.fcpxml`)
} else {
spinner.fail('An error occurred during fcpxml generation, Please check your SRT format is correct');
}
} catch (error) {
spinner.fail('An error occurred during fcpxml generation, Please check your SRT format is correct');
}