diff options
author | Kim <1877318+kimsible@users.noreply.github.com> | 2020-04-20 10:28:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 10:28:38 +0200 |
commit | b1770a0af464ad6350d156245b1abcc1395e142e (patch) | |
tree | 0712a2cd912ecd3f41084134d513920a6f723fb6 /server/lib/job-queue/handlers | |
parent | 8f31261f77c6e521917b3f629b223ccc8df50960 (diff) | |
download | PeerTube-b1770a0af464ad6350d156245b1abcc1395e142e.tar.gz PeerTube-b1770a0af464ad6350d156245b1abcc1395e142e.tar.zst PeerTube-b1770a0af464ad6350d156245b1abcc1395e142e.zip |
Add thumbnail / preview generation from url on the fly (#2646)
* Add thumbnails generation on the fly to URL import
* Display generated preview to import first edit
* Use ternary to get type inference
* Move preview/thumbnail test just after import
Co-authored-by: kimsible <kimsible@users.noreply.github.com>
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/video-import.ts | 42 |
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' | |||
16 | import { Notifier } from '../../notifier' | 16 | import { Notifier } from '../../notifier' |
17 | import { CONFIG } from '../../../initializers/config' | 17 | import { CONFIG } from '../../../initializers/config' |
18 | import { sequelizeTypescript } from '../../../initializers/database' | 18 | import { sequelizeTypescript } from '../../../initializers/database' |
19 | import { createVideoMiniatureFromUrl, generateVideoMiniature } from '../../thumbnail' | 19 | import { generateVideoMiniature } from '../../thumbnail' |
20 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 20 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
21 | import { MThumbnail } from '../../../typings/models/video/thumbnail' | 21 | import { MThumbnail } from '../../../typings/models/video/thumbnail' |
22 | import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import' | 22 | import { 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) { | |||
107 | type ProcessFileOptions = { | 99 | type 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 | ||