Browse Source

🎉 Initial commit

master
KaKi87 3 months ago
commit
d30ca84ffb
  1. 3
      .gitignore
  2. 67
      index.js
  3. 15
      package.json
  4. 23
      yarn.lock

3
.gitignore

@ -0,0 +1,3 @@
.idea
node_modules
exiftool*

67
index.js

@ -0,0 +1,67 @@
#!/usr/bin/env node
const fs = require('fs');
const
arg = require('arg'),
exif = require('exiftool'),
dayjs = require('dayjs'),
outdent = require('outdent');
const {
'--input': inputFilePath,
'--format': format,
'--locale': locale,
'--timezone': timezone
} = arg({
'--input': String,
'--format': String,
'--locale': String,
'--timezone': String,
'-i': '--input',
'-f': '--format',
'-l': '--locale',
'-t': '--timezone'
});
dayjs.extend(require('dayjs/plugin/customParseFormat'));
dayjs.extend(require('dayjs/plugin/utc'));
if(locale){
dayjs.locale(require(`dayjs/locale/${locale}`));
dayjs.extend(require('dayjs/plugin/localizedFormat'));
dayjs.locale(locale);
}
if(timezone){
dayjs.extend(require('dayjs/plugin/timezone'));
}
fs.readFile(inputFilePath, (fsError, fsData) => {
if(fsError) console.error(fsError);
else exif.metadata(fsData, (exifError, exifData) => {
if(exifError) console.error(exifError);
else {
const
startDate = dayjs(exifData['trackCreateDate'], 'YYYY:MM:DD HH:mm:ss'),
durationDate = dayjs(exifData['mediaDuration'], 'HH:mm:ss'),
endDate = dayjs(startDate)
.add(durationDate.hour(), 'hours')
.add(durationDate.minute(), 'minutes')
.add(durationDate.second(), 'seconds');
let srt = '';
for(let i = 0; i < endDate.diff(startDate, 'seconds'); i++){
let currentDate = dayjs(startDate).add(i, 'seconds');
if(timezone) currentDate = currentDate.tz(timezone);
if(i > 0) srt += '\n\n';
srt += outdent `
${i+1}
${dayjs(0).add(i, 'seconds').utc().format('HH:mm:ss,SSS')} --> ${dayjs(0).add(i+1, 'seconds').utc().format('HH:mm:ss,SSS')}
${currentDate.format(format)}
`;
}
console.log(srt);
}
});
});

15
package.json

@ -0,0 +1,15 @@
{
"name": "video-date-time-srt-generator",
"version": "1.0.0",
"main": "index.js",
"bin": {
"video-date-time-srt-generator": "./index.js"
},
"license": "MIT",
"dependencies": {
"arg": "^5.0.0",
"dayjs": "^1.10.5",
"exiftool": "^0.0.3",
"outdent": "^0.8.0"
}
}

23
yarn.lock

@ -0,0 +1,23 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
arg@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.0.tgz#a20e2bb5710e82950a516b3f933fee5ed478be90"
integrity sha512-4P8Zm2H+BRS+c/xX1LrHw0qKpEhdlZjLCgWy+d78T9vqa2Z2SiD2wMrYuWIAFy5IZUD7nnNXroRttz+0RzlrzQ==
dayjs@^1.10.5:
version "1.10.5"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.5.tgz#5600df4548fc2453b3f163ebb2abbe965ccfb986"
integrity sha512-BUFis41ikLz+65iH6LHQCDm4YPMj5r1YFLdupPIyM4SGcXMmtiLQ7U37i+hGS8urIuqe7I/ou3IS1jVc4nbN4g==
exiftool@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/exiftool/-/exiftool-0.0.3.tgz#f58a92bd77270adc54f3151ced61a4a3ab69d707"
integrity sha1-9YqSvXcnCtxU8xUc7WGko6tp1wc=
outdent@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/outdent/-/outdent-0.8.0.tgz#2ebc3e77bf49912543f1008100ff8e7f44428eb0"
integrity sha512-KiOAIsdpUTcAXuykya5fnVVT+/5uS0Q1mrkRHcF89tpieSmY33O/tmc54CqwA+bfhbtEfZUNLHaPUiB9X3jt1A==
Loading…
Cancel
Save