aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/remote.js12
-rw-r--r--server/models/video.js31
2 files changed, 24 insertions, 19 deletions
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js
index 4085deb2d..3e2aa6375 100644
--- a/server/controllers/api/remote.js
+++ b/server/controllers/api/remote.js
@@ -55,11 +55,15 @@ function remoteVideos (req, res, next) {
55function addRemoteVideo (videoToCreateData, callback) { 55function addRemoteVideo (videoToCreateData, callback) {
56 logger.debug('Adding remote video %s.', videoToCreateData.magnetUri) 56 logger.debug('Adding remote video %s.', videoToCreateData.magnetUri)
57 57
58 // Mongoose pre hook will automatically create the thumbnail on disk
59 videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64
60
61 const video = new Video(videoToCreateData) 58 const video = new Video(videoToCreateData)
62 video.save(callback) 59 Video.generateThumbnailFromBase64(video, videoToCreateData.thumbnailBase64, function (err) {
60 if (err) {
61 logger.error('Cannot generate thumbnail from base 64 data.', { error: err })
62 return callback(err)
63 }
64
65 video.save(callback)
66 })
63} 67}
64 68
65function removeRemoteVideo (videoToRemoveData, fromHost, callback) { 69function removeRemoteVideo (videoToRemoveData, fromHost, callback) {
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,