]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Move video duration logic in lib/
authorChocobozzz <florian.bigard@gmail.com>
Fri, 6 May 2016 12:44:09 +0000 (14:44 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 6 May 2016 12:44:09 +0000 (14:44 +0200)
server/controllers/api/v1/videos.js
server/lib/videos.js

index e696289619f9ac4f75a1286a88ff5fb507f466e2..7fdc50e5239d742ecd33d086237bc54afc8c018e 100644 (file)
@@ -3,7 +3,6 @@
 const config = require('config')
 const crypto = require('crypto')
 const express = require('express')
-const ffmpeg = require('fluent-ffmpeg')
 const multer = require('multer')
 
 const logger = require('../../../helpers/logger')
@@ -61,15 +60,13 @@ function addVideo (req, res, next) {
       return next(err)
     }
 
-    ffmpeg.ffprobe(video_file.path, function (err, metadata) {
+    videos.getVideoDuration(video_file.path, function (err, duration) {
       if (err) {
         // TODO: unseed the video
         logger.error('Cannot retrieve metadata of the file')
         return next(err)
       }
 
-      const duration = Math.floor(metadata.format.duration)
-
       const video_data = {
         name: video_infos.name,
         namePath: video_file.filename,
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