Untitled
unknown
javascript
5 years ago
808 B
16
Indexable
const fs = require("fs");
const fetch = require("node-fetch");
const { pipeline } = require("stream");
const { promisify } = require("util");
const DOWNLOAD_DIR = "./videos/"; // Onde o arquivo deve ser baixado a pasta deve existir
const DOWNLOAD_URL = "";
// Download video action
const downloadVideo = async (videoId, videoNum, page) => {
try {
const streamPipeline = promisify(pipeline);
// const unsecLink = /(([^\/]*\/){5})/.exec(link);
const res = await fetch(
`${DOWNLOAD_URL}/${videoId}/playlist.mp4`
);
if (!res.ok) {
throw new Error(`unexpected response ${res.statusText}`);
}
await streamPipeline(
res.body,
fs.createWriteStream(`${DOWNLOAD_DIR}/page${page}-video${videoNum}.mp4`)
);
} catch (err) {
console.log("err", err);
}
};Editor is loading...