]> 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 eb3a0125a8bbeec9612b5c179230d72125d387dd..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,19 +12,28 @@ 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 getVideoState (video, callback) {
+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
   if (exist === true) {
     owned = (video.namePath !== null)
   }
 
-  return callback({ exist: exist, owned: owned })
+  return { exist: exist, owned: owned }
 }
 
 function seed (path, callback) {