aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video.js')
-rw-r--r--server/models/video.js31
1 files changed, 16 insertions, 15 deletions
diff --git a/server/models/video.js b/server/models/video.js
index d7d99acd6..527652230 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -57,6 +57,7 @@ VideoSchema.methods = {
57} 57}
58 58
59VideoSchema.statics = { 59VideoSchema.statics = {
60 generateThumbnailFromBase64,
60 getDurationFromFile, 61 getDurationFromFile,
61 listForApi, 62 listForApi,
62 listByHostAndRemoteId, 63 listByHostAndRemoteId,
@@ -136,10 +137,10 @@ VideoSchema.pre('save', function (next) {
136 } 137 }
137 ) 138 )
138 139
139 parallel(tasks, next) 140 return parallel(tasks, next)
140 } else {
141 generateThumbnailFromBase64(video, video.thumbnail, next)
142 } 141 }
142
143 return next()
143}) 144})
144 145
145mongoose.model('Video', VideoSchema) 146mongoose.model('Video', VideoSchema)
@@ -251,6 +252,18 @@ function toRemoteJSON (callback) {
251 252
252// ------------------------------ STATICS ------------------------------ 253// ------------------------------ STATICS ------------------------------
253 254
255function generateThumbnailFromBase64 (video, thumbnailData, callback) {
256 // Creating the thumbnail for a remote video
257
258 const thumbnailName = video.getThumbnailName()
259 const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
260 fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
261 if (err) return callback(err)
262
263 return callback(null, thumbnailName)
264 })
265}
266
254function getDurationFromFile (videoPath, callback) { 267function getDurationFromFile (videoPath, callback) {
255 ffmpeg.ffprobe(videoPath, function (err, metadata) { 268 ffmpeg.ffprobe(videoPath, function (err, metadata) {
256 if (err) return callback(err) 269 if (err) return callback(err)
@@ -333,18 +346,6 @@ function createThumbnail (video, videoPath, callback) {
333 generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback) 346 generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback)
334} 347}
335 348
336function generateThumbnailFromBase64 (video, thumbnailData, callback) {
337 // Creating the thumbnail for this remote video)
338
339 const thumbnailName = video.getThumbnailName()
340 const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
341 fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
342 if (err) return callback(err)
343
344 return callback(null, thumbnailName)
345 })
346}
347
348function generateImage (video, videoPath, folder, imageName, size, callback) { 349function generateImage (video, videoPath, folder, imageName, size, callback) {
349 const options = { 350 const options = {
350 filename: imageName, 351 filename: imageName,