aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/thumbnail.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r--server/lib/thumbnail.ts26
1 files changed, 20 insertions, 6 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts
index 18bdcded4..a59773f5a 100644
--- a/server/lib/thumbnail.ts
+++ b/server/lib/thumbnail.ts
@@ -12,12 +12,18 @@ import { VideoPlaylistModel } from '../models/video/video-playlist'
12 12
13type ImageSize = { height: number, width: number } 13type ImageSize = { height: number, width: number }
14 14
15function createPlaylistMiniatureFromExisting (inputPath: string, playlist: VideoPlaylistModel, keepOriginal = false, size?: ImageSize) { 15function createPlaylistMiniatureFromExisting (
16 inputPath: string,
17 playlist: VideoPlaylistModel,
18 automaticallyGenerated: boolean,
19 keepOriginal = false,
20 size?: ImageSize
21) {
16 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) 22 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
17 const type = ThumbnailType.MINIATURE 23 const type = ThumbnailType.MINIATURE
18 24
19 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) 25 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
20 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) 26 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
21} 27}
22 28
23function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) { 29function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) {
@@ -35,11 +41,17 @@ function createVideoMiniatureFromUrl (fileUrl: string, video: VideoModel, type:
35 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 41 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
36} 42}
37 43
38function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { 44function createVideoMiniatureFromExisting (
45 inputPath: string,
46 video: VideoModel,
47 type: ThumbnailType,
48 automaticallyGenerated: boolean,
49 size?: ImageSize
50) {
39 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) 51 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
40 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }) 52 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height })
41 53
42 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) 54 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
43} 55}
44 56
45function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) { 57function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) {
@@ -50,7 +62,7 @@ function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, t
50 ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) 62 ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true)
51 : () => generateImageFromVideoFile(input, basePath, filename, { height, width }) 63 : () => generateImageFromVideoFile(input, basePath, filename, { height, width })
52 64
53 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) 65 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated: true, existingThumbnail })
54} 66}
55 67
56function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { 68function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) {
@@ -134,10 +146,11 @@ async function createThumbnailFromFunction (parameters: {
134 height: number, 146 height: number,
135 width: number, 147 width: number,
136 type: ThumbnailType, 148 type: ThumbnailType,
149 automaticallyGenerated?: boolean,
137 fileUrl?: string, 150 fileUrl?: string,
138 existingThumbnail?: ThumbnailModel 151 existingThumbnail?: ThumbnailModel
139}) { 152}) {
140 const { thumbnailCreator, filename, width, height, type, existingThumbnail, fileUrl = null } = parameters 153 const { thumbnailCreator, filename, width, height, type, existingThumbnail, automaticallyGenerated = null, fileUrl = null } = parameters
141 154
142 const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() 155 const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel()
143 156
@@ -146,6 +159,7 @@ async function createThumbnailFromFunction (parameters: {
146 thumbnail.width = width 159 thumbnail.width = width
147 thumbnail.type = type 160 thumbnail.type = type
148 thumbnail.fileUrl = fileUrl 161 thumbnail.fileUrl = fileUrl
162 thumbnail.automaticallyGenerated = automaticallyGenerated
149 163
150 await thumbnailCreator() 164 await thumbnailCreator()
151 165