- let timer: NodeJS.Timeout
- const timeoutPromise = new Promise<string>((_, rej) => {
- timer = setTimeout(() => rej(new Error('YoutubeDL download timeout.')), timeout)
- })
-
- const downloadPromise = youtubeDL.download({
- url: this.url,
- format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions),
- output: pathWithoutExtension,
- processOptions
- }).then(() => clearTimeout(timer))
- .then(async () => {
- // If youtube-dl did not guess an extension for our file, just use .mp4 as default
- if (await pathExists(pathWithoutExtension)) {
- await move(pathWithoutExtension, pathWithoutExtension + '.mp4')
- }
-
- return this.guessVideoPathWithExtension(pathWithoutExtension, fileExt)
+ try {
+ await youtubeDL.download({
+ url: this.url,
+ format: YoutubeDLCLI.getYoutubeDLVideoFormat(this.enabledResolutions, this.useBestFormat),
+ output: pathWithoutExtension,
+ timeout,
+ processOptions