diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-11-11 11:52:24 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-11-16 20:29:26 +0100 |
commit | 6a94a109b4b89a97fe7bfeded3125fb7aad2ac3b (patch) | |
tree | 22397531c03da92be50e28703764405002acb926 /server/models | |
parent | 830bcd0f82c16b8b5f1259150a6d541a210693eb (diff) | |
download | PeerTube-6a94a109b4b89a97fe7bfeded3125fb7aad2ac3b.tar.gz PeerTube-6a94a109b4b89a97fe7bfeded3125fb7aad2ac3b.tar.zst PeerTube-6a94a109b4b89a97fe7bfeded3125fb7aad2ac3b.zip |
Server: add video preview
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video.js | 27 |
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 | ||
265 | function removeTorrent (video, callback) { | 270 | function 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 | ||
274 | function 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 | |||
280 | function 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 | |||
269 | function createThumbnail (videoPath, callback) { | 294 | function createThumbnail (videoPath, callback) { |
270 | const filename = pathUtils.basename(videoPath) + '.jpg' | 295 | const filename = pathUtils.basename(videoPath) + '.jpg' |
271 | ffmpeg(videoPath) | 296 | ffmpeg(videoPath) |