diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-01 16:54:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-01 16:54:24 +0200 |
commit | 65af03a241aa83ab7ba71278b6c99acd26428b8a (patch) | |
tree | 0cc04c31cdf631d11a915ae40389e8fa141f136b /server/lib/thumbnail.ts | |
parent | a21e25ff641854c8b01664cb18655aa420620af6 (diff) | |
download | PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.tar.gz PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.tar.zst PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.zip |
Automatically update playlist thumbnails
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 26 |
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 | ||
13 | type ImageSize = { height: number, width: number } | 13 | type ImageSize = { height: number, width: number } |
14 | 14 | ||
15 | function createPlaylistMiniatureFromExisting (inputPath: string, playlist: VideoPlaylistModel, keepOriginal = false, size?: ImageSize) { | 15 | function 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 | ||
23 | function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) { | 29 | function 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 | ||
38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { | 44 | function 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 | ||
45 | function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) { | 57 | function 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 | ||
56 | function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { | 68 | function 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 | ||