-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
32 lines (27 loc) · 967 Bytes
/
utils.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
const fs = require("fs");
const formatSegmentsData = (segments) => {
return segments.map((segment) => {
const startText = `${String(Math.floor(segment.start / 60)).padStart(2, "0")}:${String(Math.floor(segment.start % 60)).padStart(2, "0")}`
const endText = `${String(Math.floor(segment.end / 60)).padStart(2, "0")}:${String(Math.floor(segment.end % 60)).padStart(2, "0")}`
return `${startText}~${endText}\n${segment.text}`
}).join('\n\n')
}
const isAudioFile = (file) => {
return file.toLowerCase().endsWith(".mp3");
};
const isMovieFile = (file) => {
return file.toLowerCase().endsWith(".mp4");
};
// MBでファイルサイズを取得する関数
const getFileSizeInMB = (filePath) => {
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileSizeInMB = fileSizeInBytes / (1024 * 1024);
return fileSizeInMB;
}
module.exports = {
formatSegmentsData,
isAudioFile,
isMovieFile,
getFileSizeInMB,
};