Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.use('/videoplayback', ensureLoggedIn(), (req, res) => {
const { v: videoId } = req.query;
// Default timeout is 5 minutes, which is too short for videos
req.setTimeout(10 * 60 * 60 * 1000);
if (!ytdl.validateID(videoId)) {
res.status(400).send({
error: 'VALIDATION_ERROR',
reason: 'Invalid video id',
});
return;
}
ytdl(`https://youtube.com/watch?v=${videoId}`).pipe(res);
});
createReadStream ( offset ) {
let options = { quality: 'highest', filter: format => format.container === 'mp4' };
if ( offset ) {
options.range = offset.start + '-' + offset.end;
}
console.log( options );
return ytdl( this.source, options );
}
download(video, filename) {
let url = `http://youtube.com/watch?v=${video.id}`;
let writeStream = fs.createWriteStream(filename);
let readStream = ytdl(url, {});
readStream.pipe(writeStream);
let download = {
id: video.id,
title: video.snippet.title,
path: filename,
stream: readStream
};
return new Promise((resolve, reject) => {
readStream.on('error', err => {
reject(err);
});
resolve(download);
});
eventChannel(emit => {
let progress = 0;
let fileSize = 0;
let dataRead = 0;
let newSound = {};
const tmpFile = path.join(pathConfig.userSoundDir, shortid.generate());
ytdl(`https://www.youtube.com/watch?v=${data.file}`, {
format: 'audioonly',
debug: true,
})
.on('response', ({ headers }) => {
fileSize = headers['content-length'];
})
.on(
'info',
(
{ title, keywords, thumbnail_url: img, video_id: videoID },
{ container }
) => {
newSound = {
...newSoundObj,
file: path.join(
pathConfig.userSoundDir,