X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fyoutube-dl.ts;h=72d457bc1a0ae4d4cbdc31bc5382fea65a955e11;hb=2264c1ceedcf27998108b8f8b706e51ed910d4fb;hp=ebb788e8e23a30825f89708547bc8e66bfe282d3;hpb=454c20fa7cdb05eba7f1be3c83389b54807af0b3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index ebb788e8e..72d457bc1 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts @@ -55,6 +55,8 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise // this is a merge format and its extension will be appended if (info.ext === 'mp4') { info.mergeExt = 'mp4' + } else if (info.ext === 'webm') { + info.mergeExt = 'webm' } else { info.mergeExt = 'mkv' } @@ -126,16 +128,21 @@ function getYoutubeDLVideoFormat () { `bestvideo[vcodec!*=av01][vcodec!*=vp9.2][height=${resolution}]+bestaudio`, // case #2 `bestvideo[vcodec^=avc1][height<=${resolution}]+bestaudio[ext=m4a]`, // case #3 `bestvideo[vcodec!*=av01][vcodec!*=vp9.2]+bestaudio`, - 'best[vcodec!*=av01][vcodec!*=vp9.2]' // case fallback + 'best[vcodec!*=av01][vcodec!*=vp9.2]', // case fallback for known formats + 'best' // Ultimate fallback ].join('/') } function downloadYoutubeDLVideo (url: string, extension: string, timeout: number, mergeExtension?: string) { - const path = generateVideoImportTmpPath(url, extension) - const finalPath = mergeExtension ? path.replace(new RegExp(`${extension}$`), mergeExtension) : path + let path = generateVideoImportTmpPath(url, extension) + + path = mergeExtension + ? path.replace(new RegExp(`${extension}$`), mergeExtension) + : path + let timer - logger.info('Importing youtubeDL video %s to %s', url, finalPath) + logger.info('Importing youtubeDL video %s to %s', url, path) let options = [ '-f', getYoutubeDLVideoFormat(), '-o', path ] options = wrapWithProxyOptions(options) @@ -144,6 +151,8 @@ function downloadYoutubeDLVideo (url: string, extension: string, timeout: number options = options.concat([ '--ffmpeg-location', process.env.FFMPEG_PATH ]) } + logger.debug('YoutubeDL options for %s.', url, { options }) + return new Promise((res, rej) => { safeGetYoutubeDL() .then(youtubeDL => { @@ -157,7 +166,7 @@ function downloadYoutubeDLVideo (url: string, extension: string, timeout: number return rej(err) } - return res(finalPath) + return res(path) }) timer = setTimeout(() => {