]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/import.ts
stricter youtubedl format selectors (#3516)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / import.ts
index cd9ba046deed1656f821c9112b557cc89e20fe0f..9702e219aa0eae55b2b4c4063084d893c9a5fbb8 100644 (file)
@@ -1,4 +1,3 @@
-import * as Bluebird from 'bluebird'
 import * as express from 'express'
 import { move, readFile } from 'fs-extra'
 import * as magnetUtil from 'magnet-uri'
@@ -17,6 +16,7 @@ import {
 } from '@server/types/models'
 import { MVideoImport, MVideoImportFormattable } from '@server/types/models/video/video-import'
 import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
 import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
 import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
@@ -36,7 +36,6 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm
 import { VideoModel } from '../../../models/video/video'
 import { VideoCaptionModel } from '../../../models/video/video-caption'
 import { VideoImportModel } from '../../../models/video/video-import'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
 const auditLogger = auditLoggerFactory('video-imports')
 const videoImportsRouter = express.Router()
@@ -147,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)
@@ -220,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 })
 
@@ -314,7 +313,7 @@ function insertIntoDB (parameters: {
   tags: string[]
   videoImportAttributes: Partial<MVideoImport>
   user: MUser
-}): Bluebird<MVideoImportFormattable> {
+}): Promise<MVideoImportFormattable> {
   const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
 
   return sequelizeTypescript.transaction(async t => {