Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ytdl.getInfo(url).then(info => {
progress({'status': 'taking screenshot.', progress: 0.5})
const format = ytdl.chooseFormat(info.formats, { quality: 'highestvideo' })
const args = ['-i', format.url, '-frames:v', '1', '-an', '-y', outFile]
// if (!format.live && position) args.splice(0, 0, '-ss', position)
execFile(bin, args, (error, stdout, stderr) => {
if (error) return reject({ error, stdout, stderr })
resolve(outFile)
})
}).catch(reject)
})
ytdl.getInfo(url, { debug: opts.debug }, (err, info) => {
if (err) {
console.error(err.message);
process.exit(1);
return;
}
let format = ytdl.chooseFormat(info.formats, ytdlOptions);
if (format instanceof Error) {
console.error(format.message);
process.exit(1);
return;
}
console.log(format.url);
});
ytdl.getInfo(options.input, (err, info) => {
if (err) {
return reject('Unable to download from video');
}
const downloadOptions = {
quality: 'highestaudio',
filter: options.audioonly ? 'audioonly' : undefined
};
const format = ytdl.chooseFormat(info.formats, downloadOptions);
if ((format instanceof Error) || !format.container) {
return reject('Unable to find a suitable video format');
}
const fname = path.join(options.output, fileName(info.title, format.container));
emitter.emit('url', fname, info);
if (options.downloadCover) {
downloadCover(info, options);
}
fs.stat(fname, (err) => {
if (err) {
const stream = ytdl.downloadFromInfo(info, downloadOptions);
stream.pipe(fs.createWriteStream(fname));
stream.on('end', () => resolve(fname));
stream.on('abort', () => reject('An error has ocurred while downloading video'));
} else {
resolve(fname);
return ytdl.getInfo(this._options.input).then((info) => {
this._downloadOptions = { quality: this._options.quality, filter: this._options.audioonly ? 'audioonly' : undefined }
const format = ytdl.chooseFormat(info.formats, this._downloadOptions)
if ((format instanceof Error)) {
throw format
} else if (!format.container) {
throw new Error('Could not find a suitable download format')
}
this._inputFile = path.join(
this._options.output, this._fileName(info.title, format.container)
)
return Promise.all([
this._checkDownloadCache(format, info),
this._downloadCover(info)
])
})