aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/lib/thumbnail.ts17
-rw-r--r--server/models/video/thumbnail.ts12
2 files changed, 23 insertions, 6 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts
index 55478299c..5d0c9f742 100644
--- a/server/lib/thumbnail.ts
+++ b/server/lib/thumbnail.ts
@@ -1,5 +1,6 @@
1import chaiJsonSchema = require('chai-json-schema')
2import { copy, move } from 'fs-extra'
1import { join } from 'path' 3import { join } from 'path'
2
3import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' 4import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
4import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' 5import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
5import { processImage } from '../helpers/image-utils' 6import { processImage } from '../helpers/image-utils'
@@ -69,7 +70,19 @@ function createVideoMiniatureFromUrl (options: {
69 ? null 70 ? null
70 : downloadUrl 71 : downloadUrl
71 72
72 const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) 73 // If the thumbnail URL did not change
74 const existingUrl = existingThumbnail
75 ? existingThumbnail.fileUrl
76 : null
77
78 // If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing
79 const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`)
80 const thumbnailCreator = () => {
81 if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
82
83 return copy(existingThumbnail.getPath(), ThumbnailModel.buildPath(type, filename))
84 }
85
73 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 86 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
74} 87}
75 88
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts
index 3d885f654..4185ec5f2 100644
--- a/server/models/video/thumbnail.ts
+++ b/server/models/video/thumbnail.ts
@@ -158,6 +158,12 @@ export class ThumbnailModel extends Model {
158 return ThumbnailModel.findOne(query) 158 return ThumbnailModel.findOne(query)
159 } 159 }
160 160
161 static buildPath (type: ThumbnailType, filename: string) {
162 const directory = ThumbnailModel.types[type].directory
163
164 return join(directory, filename)
165 }
166
161 getFileUrl (video: MVideoAccountLight) { 167 getFileUrl (video: MVideoAccountLight) {
162 const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename 168 const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
163 169
@@ -169,13 +175,11 @@ export class ThumbnailModel extends Model {
169 } 175 }
170 176
171 getPath () { 177 getPath () {
172 const directory = ThumbnailModel.types[this.type].directory 178 return ThumbnailModel.buildPath(this.type, this.filename)
173 return join(directory, this.filename)
174 } 179 }
175 180
176 getPreviousPath () { 181 getPreviousPath () {
177 const directory = ThumbnailModel.types[this.type].directory 182 return ThumbnailModel.buildPath(this.type, this.previousThumbnailFilename)
178 return join(directory, this.previousThumbnailFilename)
179 } 183 }
180 184
181 removeThumbnail () { 185 removeThumbnail () {