aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/job-queue/handlers/video-import.ts42
1 files changed, 7 insertions, 35 deletions
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index d8052da72..6cdae5b03 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -16,7 +16,7 @@ import { move, remove, stat } from 'fs-extra'
16import { Notifier } from '../../notifier' 16import { Notifier } from '../../notifier'
17import { CONFIG } from '../../../initializers/config' 17import { CONFIG } from '../../../initializers/config'
18import { sequelizeTypescript } from '../../../initializers/database' 18import { sequelizeTypescript } from '../../../initializers/database'
19import { createVideoMiniatureFromUrl, generateVideoMiniature } from '../../thumbnail' 19import { generateVideoMiniature } from '../../thumbnail'
20import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 20import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
21import { MThumbnail } from '../../../typings/models/video/thumbnail' 21import { MThumbnail } from '../../../typings/models/video/thumbnail'
22import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import' 22import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import'
@@ -27,9 +27,8 @@ type VideoImportYoutubeDLPayload = {
27 type: 'youtube-dl' 27 type: 'youtube-dl'
28 videoImportId: number 28 videoImportId: number
29 29
30 thumbnailUrl: string 30 generateThumbnail: boolean
31 downloadThumbnail: boolean 31 generatePreview: boolean
32 downloadPreview: boolean
33 32
34 fileExt?: string 33 fileExt?: string
35} 34}
@@ -64,9 +63,6 @@ async function processTorrentImport (job: Bull.Job, payload: VideoImportTorrentP
64 const options = { 63 const options = {
65 videoImportId: payload.videoImportId, 64 videoImportId: payload.videoImportId,
66 65
67 downloadThumbnail: false,
68 downloadPreview: false,
69
70 generateThumbnail: true, 66 generateThumbnail: true,
71 generatePreview: true 67 generatePreview: true
72 } 68 }
@@ -84,12 +80,8 @@ async function processYoutubeDLImport (job: Bull.Job, payload: VideoImportYoutub
84 const options = { 80 const options = {
85 videoImportId: videoImport.id, 81 videoImportId: videoImport.id,
86 82
87 downloadThumbnail: payload.downloadThumbnail, 83 generateThumbnail: payload.generateThumbnail,
88 downloadPreview: payload.downloadPreview, 84 generatePreview: payload.generatePreview
89 thumbnailUrl: payload.thumbnailUrl,
90
91 generateThumbnail: false,
92 generatePreview: false
93 } 85 }
94 86
95 return processFile(() => downloadYoutubeDLVideo(videoImport.targetUrl, payload.fileExt, VIDEO_IMPORT_TIMEOUT), videoImport, options) 87 return processFile(() => downloadYoutubeDLVideo(videoImport.targetUrl, payload.fileExt, VIDEO_IMPORT_TIMEOUT), videoImport, options)
@@ -107,10 +99,6 @@ async function getVideoImportOrDie (videoImportId: number) {
107type ProcessFileOptions = { 99type ProcessFileOptions = {
108 videoImportId: number 100 videoImportId: number
109 101
110 downloadThumbnail: boolean
111 downloadPreview: boolean
112 thumbnailUrl?: string
113
114 generateThumbnail: boolean 102 generateThumbnail: boolean
115 generatePreview: boolean 103 generatePreview: boolean
116} 104}
@@ -155,29 +143,13 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
155 143
156 // Process thumbnail 144 // Process thumbnail
157 let thumbnailModel: MThumbnail 145 let thumbnailModel: MThumbnail
158 if (options.downloadThumbnail && options.thumbnailUrl) { 146 if (options.generateThumbnail) {
159 try {
160 thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE)
161 } catch (err) {
162 logger.warn('Cannot generate video thumbnail %s for %s.', options.thumbnailUrl, videoImportWithFiles.Video.url, { err })
163 }
164 }
165
166 if (!thumbnailModel && (options.generateThumbnail || options.downloadThumbnail)) {
167 thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE) 147 thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE)
168 } 148 }
169 149
170 // Process preview 150 // Process preview
171 let previewModel: MThumbnail 151 let previewModel: MThumbnail
172 if (options.downloadPreview && options.thumbnailUrl) { 152 if (options.generatePreview) {
173 try {
174 previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW)
175 } catch (err) {
176 logger.warn('Cannot generate video preview %s for %s.', options.thumbnailUrl, videoImportWithFiles.Video.url, { err })
177 }
178 }
179
180 if (!previewModel && (options.generatePreview || options.downloadPreview)) {
181 previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW) 153 previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW)
182 } 154 }
183 155