From e3b4c084cd0935dd93b1d737c4fc88c65ab5bcc1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Feb 2021 09:37:01 +0100 Subject: [PATCH] Guess if we need to generate the thumbnail for imports --- server/controllers/api/videos/import.ts | 2 -- server/lib/job-queue/handlers/video-import.ts | 21 ++++++------------- shared/models/server/job.model.ts | 2 -- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 96499dffb..01f41e7bc 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -218,8 +218,6 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) const payload = { type: 'youtube-dl' as 'youtube-dl', videoImportId: videoImport.id, - generateThumbnail: !thumbnailModel, - generatePreview: !previewModel, fileExt: `.${youtubeDLInfo.ext || 'mp4'}` } await JobQueue.Instance.createJobWithPromise({ type: 'video-import', payload }) diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index 9125b50e1..1e5e52b58 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -57,10 +57,7 @@ async function processTorrentImport (job: Bull.Job, payload: VideoImportTorrentP const options = { type: payload.type, - videoImportId: payload.videoImportId, - - generateThumbnail: true, - generatePreview: true + videoImportId: payload.videoImportId } const target = { torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined, @@ -75,10 +72,7 @@ async function processYoutubeDLImport (job: Bull.Job, payload: VideoImportYoutub const videoImport = await getVideoImportOrDie(payload.videoImportId) const options = { type: payload.type, - videoImportId: videoImport.id, - - generateThumbnail: payload.generateThumbnail, - generatePreview: payload.generatePreview + videoImportId: videoImport.id } return processFile( @@ -100,9 +94,6 @@ async function getVideoImportOrDie (videoImportId: number) { type ProcessFileOptions = { type: VideoImportYoutubeDLPayloadType | VideoImportTorrentPayloadType videoImportId: number - - generateThumbnail: boolean - generatePreview: boolean } async function processFile (downloader: () => Promise, videoImport: MVideoImportDefault, options: ProcessFileOptions) { let tempVideoPath: string @@ -167,18 +158,18 @@ async function processFile (downloader: () => Promise, videoImport: MVid await move(tempVideoPath, videoDestFile) tempVideoPath = null // This path is not used anymore - // Process thumbnail + // Generate miniature if the import did not created it let thumbnailModel: MThumbnail let thumbnailSave: object - if (options.generateThumbnail) { + if (!videoImportWithFiles.Video.getMiniature()) { thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE) thumbnailSave = thumbnailModel.toJSON() } - // Process preview + // Generate preview if the import did not created it let previewModel: MThumbnail let previewSave: object - if (options.generatePreview) { + if (!videoImportWithFiles.Video.getPreview()) { previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW) previewSave = previewModel.toJSON() } diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 44f92abf1..07d7efe22 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts @@ -80,8 +80,6 @@ export type VideoImportYoutubeDLPayload = { type: VideoImportYoutubeDLPayloadType videoImportId: number - generateThumbnail: boolean - generatePreview: boolean fileExt?: string } export type VideoImportTorrentPayload = {