From 454c20fa7cdb05eba7f1be3c83389b54807af0b3 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 15 Jan 2021 15:56:56 +0100 Subject: stricter youtubedl format selectors (#3516) * stricter youtubedl format selectors make sure selectors avoid av1, and otherwise match as closely to the maximum resolution enabled for transcoding * add support for merge formats in youtubedl * avoid vp9.2 in youtubedl to avoid any HDR * move getEnabledResolutions, safer replace of imported extension * add test for youtube-dl selectors --- server/controllers/api/config.ts | 12 +----------- server/controllers/api/videos/import.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 8bc3123bf..44f3d3ef7 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -10,6 +10,7 @@ import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '.. import { objectConverter } from '../../helpers/core-utils' import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' import { getServerCommit } from '../../helpers/utils' +import { getEnabledResolutions } from '../../lib/video-transcoding' import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' import { ClientHtml } from '../../lib/client-html' @@ -285,16 +286,6 @@ function getRegisteredThemes () { })) } -function getEnabledResolutions (type: 'vod' | 'live') { - const transcoding = type === 'vod' - ? CONFIG.TRANSCODING - : CONFIG.LIVE.TRANSCODING - - return Object.keys(transcoding.RESOLUTIONS) - .filter(key => transcoding.ENABLED && transcoding.RESOLUTIONS[key] === true) - .map(r => parseInt(r, 10)) -} - function getRegisteredPlugins () { return PluginManager.Instance.getRegisteredPlugins() .map(p => ({ @@ -345,7 +336,6 @@ function getExternalAuthsPlugins () { export { configRouter, - getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 82e084c54..9702e219a 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -146,9 +146,10 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) } catch (err) { logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) - return res.status(HttpStatusCode.BAD_REQUEST_400).json({ - error: 'Cannot fetch remote information of this URL.' - }).end() + return res.status(HttpStatusCode.BAD_REQUEST_400) + .json({ + error: 'Cannot fetch remote information of this URL.' + }) } const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) @@ -219,9 +220,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) videoImportId: videoImport.id, generateThumbnail: !thumbnailModel, generatePreview: !previewModel, - fileExt: youtubeDLInfo.fileExt - ? `.${youtubeDLInfo.fileExt}` - : '.mp4' + fileExt: `.${youtubeDLInfo.ext || 'mp4'}`, + mergeExt: youtubeDLInfo.mergeExt ? `.${youtubeDLInfo.mergeExt}` : '' } await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload }) -- cgit v1.2.3