From d57d1d83c6a4d98a735b21f4e8e749a5c1e1a479 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Apr 2020 15:41:39 +0200 Subject: Support audio files import --- server/controllers/api/videos/import.ts | 5 ++++- server/controllers/api/videos/index.ts | 28 +++++----------------------- 2 files changed, 9 insertions(+), 24 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index ed223cbc9..da0832258 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -174,7 +174,10 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) videoImportId: videoImport.id, thumbnailUrl: youtubeDLInfo.thumbnailUrl, downloadThumbnail: !thumbnailModel, - downloadPreview: !previewModel + downloadPreview: !previewModel, + fileExt: youtubeDLInfo.fileExt + ? `.${youtubeDLInfo.fileExt}` + : '.mp4' } await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload }) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 9b19c394d..04d775cbf 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { extname } from 'path' import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' -import { getVideoFileFPS, getVideoFileResolution, getMetadataFromFile } from '../../../helpers/ffmpeg-utils' +import { getMetadataFromFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { logger } from '../../../helpers/logger' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' import { getFormattedObjects, getServerActor } from '../../../helpers/utils' @@ -32,13 +32,13 @@ import { paginationValidator, setDefaultPagination, setDefaultSort, + videoFileMetadataGetValidator, videosAddValidator, videosCustomGetValidator, videosGetValidator, videosRemoveValidator, videosSortValidator, - videosUpdateValidator, - videoFileMetadataGetValidator + videosUpdateValidator } from '../../../middlewares' import { TagModel } from '../../../models/video/tag' import { VideoModel } from '../../../models/video/video' @@ -62,12 +62,12 @@ import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' -import { VideoTranscodingPayload } from '../../../lib/job-queue/handlers/video-transcoding' import { Hooks } from '../../../lib/plugins/hooks' import { MVideoDetails, MVideoFullLight } from '@server/typings/models' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { getVideoFilePath } from '@server/lib/video-paths' import toInt from 'validator/lib/toInt' +import { addOptimizeOrMergeAudioJob } from '@server/lib/videos' const auditLogger = auditLoggerFactory('videos') const videosRouter = express.Router() @@ -296,25 +296,7 @@ async function addVideo (req: express.Request, res: express.Response) { Notifier.Instance.notifyOnNewVideoIfNeeded(videoCreated) if (video.state === VideoState.TO_TRANSCODE) { - // Put uuid because we don't have id auto incremented for now - let dataInput: VideoTranscodingPayload - - if (videoFile.isAudio()) { - dataInput = { - type: 'merge-audio' as 'merge-audio', - resolution: DEFAULT_AUDIO_RESOLUTION, - videoUUID: videoCreated.uuid, - isNewVideo: true - } - } else { - dataInput = { - type: 'optimize' as 'optimize', - videoUUID: videoCreated.uuid, - isNewVideo: true - } - } - - await JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }) + await addOptimizeOrMergeAudioJob(videoCreated, videoFile) } Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) -- cgit v1.2.3