-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
157 lines (141 loc) · 4.4 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
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
#!/usr/bin/env node
import * as R from "ramda";
import { intro, outro, select } from '@clack/prompts';
import {
convertAllFilesToGif,
convertVideoToGif,
cutVideo,
concatVideoFiles,
addStartingTitle,
addStartingTitleAndImage,
} from "./source/video-utils.js";
import { blit, blur, invert, flip, text, contain, mask, rotate, convertToVideoAddingTitleAndSubtitle } from "./source/image-utils.js";
import { createPDFWithDrawnText, addTextToPdf, embedJpgToPdf, readPdfMetadata } from "./source/pdf-utils.js";
const utils = {
video: {
convertVideoToGif,
convertAllFilesToGif,
cutVideo,
concatVideoFiles,
addStartingTitle,
addStartingTitleAndImage,
},
image: {
blit,
blur,
invert,
flip,
text,
contain,
mask,
rotate,
convertToVideoAddingTitleAndSubtitle,
},
pdf: {
createPDFWithDrawnText,
addTextToPdf,
embedJpgToPdf,
readPdfMetadata,
}
};
let options = [];
const imageOptionsMappings = {
blit: 'Blit an image onto another',
blur: 'Blur an image',
invert: "Invert an image's colors",
flip: "Flip an image along its x or y axis",
text: "Print text onto an image",
contain: "Contain an image within a height and width",
mask: "Mask a source image on to this image using average pixel colour",
rotate: "Rotate the image counter-clockwise by a number of degrees",
convertToVideoAddingTitleAndSubtitle: "Create a video by adding title and subtitle to image",
};
const videoOptionsMappings = {
convertVideoToGif: "Convert video file to gif",
convertAllFilesToGif: "Convert all video files in folder to gif",
cutVideo: "Cut up video",
concatVideoFiles: "Concat several video files",
addStartingTitle: "Add animated title to video",
addStartingTitleAndImage: "Add animated starting title and image to video",
};
intro(`Let's do some stuff`);
const mediaFileType = await select(
{
message: "What is the type of media file you want to operate on",
options: [
{ label: "Video file", value: "video" },
{ label: "Image file", value: "image" },
{ label: "PDF file", value: "pdf" },
],
},
);
if (mediaFileType === "video") {
options = R.concat(
R.map(R.applySpec({
label: R.flip(R.prop)(videoOptionsMappings),
value: R.identity,
}),
R.keys(videoOptionsMappings),
),
options,
);
} else if (mediaFileType === "image") {
options = R.concat(
R.map(R.applySpec({
label: R.flip(R.prop)(imageOptionsMappings),
value: R.identity,
}),
R.keys(imageOptionsMappings),
),
options
);
} else if (mediaFileType === 'pdf') {
options = R.concat(
[
{ label: "Create pdf with text", value: 'createPDFWithDrawnText' },
{ label: "Add text to pdf file", value: "addTextToPdf" },
{ label: 'Embed jpg image to pdf file', value: "embedJpgToPdf" },
{ label: 'Read pdf metadata', value: "readPdfMetadata" },
],
options,
);
}
const result = await select({
message: "What kind of util you want to use",
options,
});
const func = R.path([mediaFileType, result], utils);
await func();
outro(`Done!`);
// await items[result]();
// if (result === 'convertmp4togif') {
// }
// import {fdir} from 'fdir';
// import {execa} from 'execa';
// import fs from 'node:fs';
// import path from 'node:path';
// import pMap from 'p-map';
// import ora from 'ora';
// // const sourcesPath = "C:\\fep\\bckn\\cudi\\v2\\demos\\what-is-word-cli-game-rounds\\media\\categorized\\a";
// const sourcesPath = "C:\\fep\\bckn\\cudi\\v2\\demos\\what-is-word-cli-game-rounds\\media";
// const files = new fdir()
// .filter((path, _isDirectory) => path.endsWith('.mp4'))
// .withFullPaths()
// .crawl(sourcesPath)
// .sync();
// const converterMapper = async file => {
// const folder = path.dirname(file);
// const gifVersion = path.basename(file).replace(/\.mp4$/, '.gif');
// const gifFile = path.join(folder, gifVersion);
// if (!fs.existsSync(gifFile)) {
// const spinner = ora(`Converting ${path.basename(file)}...`).start();
// await execa('ffmpeg', ['-i', file, '-pix_fmt', 'rgb24', gifFile]);//.stdout.pipe(process.stdout);
// spinner.stop();
// console.log(`Created file ${gifFile}`);
// return `${file} already converted to gif format`;
// }
// return `${file} have been converted`;
// };
// const results = await pMap(files, converterMapper);
// console.log(results);
// console.log('Done!');