Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladzadvorny/743e2f49f0a3d7f89b4071593145acf7 to your computer and use it in GitHub Desktop.
Save vladzadvorny/743e2f49f0a3d7f89b4071593145acf7 to your computer and use it in GitHub Desktop.
const { read } = require("readdir");
const fs = require("fs");
const parser = require("subtitles-parser");
const stream = fs.createWriteStream("./file.txt");
read("/Users/vlad/Desktop/Node", ["**/*.srt"], (err, paths) =>
paths.forEach(item => {
const srt = fs.readFileSync("/Users/vlad/Desktop/Node/" + item, "utf8");
const data = parser.fromSrt(srt);
const arr = [];
arr.push(`\n\n${item}\n\n`);
data.forEach(item2 => {
arr.push(item2.text.replace(/\n/g, " "));
});
stream.write(arr.join(" "));
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment