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.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/server/models/video.js b/server/models/video.js
index 673ccabf8..bfa1fca15 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -82,6 +82,9 @@ VideoSchema.pre('remove', function (next) {
82 }, 82 },
83 function (callback) { 83 function (callback) {
84 removeTorrent(video, callback) 84 removeTorrent(video, callback)
85 },
86 function (callback) {
87 removePreview(video, callback)
85 } 88 }
86 ) 89 )
87 } 90 }
@@ -125,6 +128,9 @@ VideoSchema.pre('save', function (next) {
125 }, 128 },
126 function (callback) { 129 function (callback) {
127 createThumbnail(videoPath, callback) 130 createThumbnail(videoPath, callback)
131 },
132 function (callback) {
133 createPreview(videoPath, callback)
128 } 134 }
129 ) 135 )
130 136
@@ -261,11 +267,30 @@ function removeFile (video, callback) {
261 fs.unlink(constants.CONFIG.STORAGE.VIDEOS_DIR + video.filename, callback) 267 fs.unlink(constants.CONFIG.STORAGE.VIDEOS_DIR + video.filename, callback)
262} 268}
263 269
264// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process
265function removeTorrent (video, callback) { 270function removeTorrent (video, callback) {
266 fs.unlink(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', callback) 271 fs.unlink(constants.CONFIG.STORAGE.TORRENTS_DIR + video.filename + '.torrent', callback)
267} 272}
268 273
274function removePreview (video, callback) {
275 // Same name than video thumnail
276 // TODO: refractoring
277 fs.unlink(constants.CONFIG.STORAGE.PREVIEWS_DIR + video.thumbnail, callback)
278}
279
280function createPreview (videoPath, callback) {
281 const filename = pathUtils.basename(videoPath) + '.jpg'
282 ffmpeg(videoPath)
283 .on('error', callback)
284 .on('end', function () {
285 callback(null, filename)
286 })
287 .thumbnail({
288 count: 1,
289 folder: constants.CONFIG.STORAGE.PREVIEWS_DIR,
290 filename: filename
291 })
292}
293
269function createThumbnail (videoPath, callback) { 294function createThumbnail (videoPath, callback) {
270 const filename = pathUtils.basename(videoPath) + '.jpg' 295 const filename = pathUtils.basename(videoPath) + '.jpg'
271 ffmpeg(videoPath) 296 ffmpeg(videoPath)