diff options
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/video-import.ts | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index 8e8aa1597..3fa0dd65d 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts | |||
@@ -6,8 +6,7 @@ import { VideoImportState } from '../../../../shared/models/videos' | |||
6 | import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 6 | import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
7 | import { extname, join } from 'path' | 7 | import { extname, join } from 'path' |
8 | import { VideoFileModel } from '../../../models/video/video-file' | 8 | import { VideoFileModel } from '../../../models/video/video-file' |
9 | import { PREVIEWS_SIZE, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' | 9 | import { VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' |
10 | import { downloadImage } from '../../../helpers/requests' | ||
11 | import { VideoState } from '../../../../shared' | 10 | import { VideoState } from '../../../../shared' |
12 | import { JobQueue } from '../index' | 11 | import { JobQueue } from '../index' |
13 | import { federateVideoIfNeeded } from '../../activitypub' | 12 | import { federateVideoIfNeeded } from '../../activitypub' |
@@ -18,6 +17,9 @@ import { move, remove, stat } from 'fs-extra' | |||
18 | import { Notifier } from '../../notifier' | 17 | import { Notifier } from '../../notifier' |
19 | import { CONFIG } from '../../../initializers/config' | 18 | import { CONFIG } from '../../../initializers/config' |
20 | import { sequelizeTypescript } from '../../../initializers/database' | 19 | import { sequelizeTypescript } from '../../../initializers/database' |
20 | import { ThumbnailModel } from '../../../models/video/thumbnail' | ||
21 | import { createVideoThumbnailFromUrl, generateVideoThumbnail } from '../../thumbnail' | ||
22 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | ||
21 | 23 | ||
22 | type VideoImportYoutubeDLPayload = { | 24 | type VideoImportYoutubeDLPayload = { |
23 | type: 'youtube-dl' | 25 | type: 'youtube-dl' |
@@ -146,25 +148,19 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
146 | tempVideoPath = null // This path is not used anymore | 148 | tempVideoPath = null // This path is not used anymore |
147 | 149 | ||
148 | // Process thumbnail | 150 | // Process thumbnail |
149 | if (options.downloadThumbnail) { | 151 | let thumbnailModel: ThumbnailModel |
150 | if (options.thumbnailUrl) { | 152 | if (options.downloadThumbnail && options.thumbnailUrl) { |
151 | await downloadImage(options.thumbnailUrl, CONFIG.STORAGE.THUMBNAILS_DIR, videoImport.Video.getThumbnailName(), THUMBNAILS_SIZE) | 153 | thumbnailModel = await createVideoThumbnailFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.THUMBNAIL) |
152 | } else { | 154 | } else if (options.generateThumbnail || options.downloadThumbnail) { |
153 | await videoImport.Video.createThumbnail(videoFile) | 155 | thumbnailModel = await generateVideoThumbnail(videoImport.Video, videoFile, ThumbnailType.THUMBNAIL) |
154 | } | ||
155 | } else if (options.generateThumbnail) { | ||
156 | await videoImport.Video.createThumbnail(videoFile) | ||
157 | } | 156 | } |
158 | 157 | ||
159 | // Process preview | 158 | // Process preview |
160 | if (options.downloadPreview) { | 159 | let previewModel: ThumbnailModel |
161 | if (options.thumbnailUrl) { | 160 | if (options.downloadPreview && options.thumbnailUrl) { |
162 | await downloadImage(options.thumbnailUrl, CONFIG.STORAGE.PREVIEWS_DIR, videoImport.Video.getPreviewName(), PREVIEWS_SIZE) | 161 | previewModel = await createVideoThumbnailFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW) |
163 | } else { | 162 | } else if (options.generatePreview || options.downloadPreview) { |
164 | await videoImport.Video.createPreview(videoFile) | 163 | previewModel = await generateVideoThumbnail(videoImport.Video, videoFile, ThumbnailType.PREVIEW) |
165 | } | ||
166 | } else if (options.generatePreview) { | ||
167 | await videoImport.Video.createPreview(videoFile) | ||
168 | } | 164 | } |
169 | 165 | ||
170 | // Create torrent | 166 | // Create torrent |
@@ -184,6 +180,15 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide | |||
184 | video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED | 180 | video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED |
185 | await video.save({ transaction: t }) | 181 | await video.save({ transaction: t }) |
186 | 182 | ||
183 | if (thumbnailModel) { | ||
184 | thumbnailModel.videoId = video.id | ||
185 | video.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
186 | } | ||
187 | if (previewModel) { | ||
188 | previewModel.videoId = video.id | ||
189 | video.addThumbnail(await previewModel.save({ transaction: t })) | ||
190 | } | ||
191 | |||
187 | // Now we can federate the video (reload from database, we need more attributes) | 192 | // Now we can federate the video (reload from database, we need more attributes) |
188 | const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) | 193 | const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) |
189 | await federateVideoIfNeeded(videoForFederation, true, t) | 194 | await federateVideoIfNeeded(videoForFederation, true, t) |