]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/videos.js
Move video duration logic in lib/
[github/Chocobozzz/PeerTube.git] / server / lib / videos.js
index 24178561d9c2dbcf0ea751b0c6893b5873f7809f..43d6c6b9992d6a46a8796787f53295a654fbdca7 100644 (file)
@@ -2,6 +2,7 @@
 
 const async = require('async')
 const config = require('config')
+const ffmpeg = require('fluent-ffmpeg')
 const pathUtils = require('path')
 const webtorrent = require('../lib/webtorrent')
 
@@ -11,11 +12,20 @@ const Videos = require('../models/videos')
 const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
 
 const videos = {
+  getVideoDuration: getVideoDuration,
   getVideoState: getVideoState,
   seed: seed,
   seedAllExisting: seedAllExisting
 }
 
+function getVideoDuration (video_path, callback) {
+  ffmpeg.ffprobe(video_path, function (err, metadata) {
+    if (err) return callback(err)
+
+    return callback(null, Math.floor(metadata.format.duration))
+  })
+}
+
 function getVideoState (video) {
   const exist = (video !== null)
   let owned = false