aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/videos/import.ts46
1 files changed, 40 insertions, 6 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index f4630375e..fb2de5dc0 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -23,7 +23,7 @@ import { move, readFile } from 'fs-extra'
23import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 23import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
24import { CONFIG } from '../../../initializers/config' 24import { CONFIG } from '../../../initializers/config'
25import { sequelizeTypescript } from '../../../initializers/database' 25import { sequelizeTypescript } from '../../../initializers/database'
26import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 26import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail'
27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
28import { 28import {
29 MChannelAccountDefault, 29 MChannelAccountDefault,
@@ -153,8 +153,25 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
153 153
154 const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) 154 const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
155 155
156 const thumbnailModel = await processThumbnail(req, video) 156 let thumbnailModel: MThumbnail
157 const previewModel = await processPreview(req, video) 157
158 // Process video thumbnail from request.files
159 thumbnailModel = await processThumbnail(req, video)
160
161 // Process video thumbnail from url if processing from request.files failed
162 if (!thumbnailModel) {
163 thumbnailModel = await processThumbnailFromUrl(youtubeDLInfo.thumbnailUrl, video)
164 }
165
166 let previewModel: MThumbnail
167
168 // Process video preview from request.files
169 previewModel = await processPreview(req, video)
170
171 // Process video preview from url if processing from request.files failed
172 if (!previewModel) {
173 previewModel = await processPreviewFromUrl(youtubeDLInfo.thumbnailUrl, video)
174 }
158 175
159 const tags = body.tags || youtubeDLInfo.tags 176 const tags = body.tags || youtubeDLInfo.tags
160 const videoImportAttributes = { 177 const videoImportAttributes = {
@@ -200,9 +217,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
200 const payload = { 217 const payload = {
201 type: 'youtube-dl' as 'youtube-dl', 218 type: 'youtube-dl' as 'youtube-dl',
202 videoImportId: videoImport.id, 219 videoImportId: videoImport.id,
203 thumbnailUrl: youtubeDLInfo.thumbnailUrl, 220 generateThumbnail: !thumbnailModel,
204 downloadThumbnail: !thumbnailModel, 221 generatePreview: !previewModel,
205 downloadPreview: !previewModel,
206 fileExt: youtubeDLInfo.fileExt 222 fileExt: youtubeDLInfo.fileExt
207 ? `.${youtubeDLInfo.fileExt}` 223 ? `.${youtubeDLInfo.fileExt}`
208 : '.mp4' 224 : '.mp4'
@@ -261,6 +277,24 @@ async function processPreview (req: express.Request, video: VideoModel) {
261 return undefined 277 return undefined
262} 278}
263 279
280async function processThumbnailFromUrl (url: string, video: VideoModel) {
281 try {
282 return createVideoMiniatureFromUrl(url, video, ThumbnailType.MINIATURE)
283 } catch (err) {
284 logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err })
285 return undefined
286 }
287}
288
289async function processPreviewFromUrl (url: string, video: VideoModel) {
290 try {
291 return createVideoMiniatureFromUrl(url, video, ThumbnailType.PREVIEW)
292 } catch (err) {
293 logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err })
294 return undefined
295 }
296}
297
264function insertIntoDB (parameters: { 298function insertIntoDB (parameters: {
265 video: MVideoThumbnailAccountDefault 299 video: MVideoThumbnailAccountDefault
266 thumbnailModel: MThumbnail 300 thumbnailModel: MThumbnail