diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-06 14:44:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-06 14:44:09 +0200 |
commit | 0ae6a09d40fd30c86a2e0bd953830020c56045cd (patch) | |
tree | 286fbbc6036cecead1219cd22cdd51d3e2d042a5 | |
parent | ae852eaf2da4dc88b638c79b8bbb07b91faf7dc7 (diff) | |
download | PeerTube-0ae6a09d40fd30c86a2e0bd953830020c56045cd.tar.gz PeerTube-0ae6a09d40fd30c86a2e0bd953830020c56045cd.tar.zst PeerTube-0ae6a09d40fd30c86a2e0bd953830020c56045cd.zip |
Move video duration logic in lib/
-rw-r--r-- | server/controllers/api/v1/videos.js | 5 | ||||
-rw-r--r-- | server/lib/videos.js | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index e69628961..7fdc50e52 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js | |||
@@ -3,7 +3,6 @@ | |||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const crypto = require('crypto') | 4 | const crypto = require('crypto') |
5 | const express = require('express') | 5 | const express = require('express') |
6 | const ffmpeg = require('fluent-ffmpeg') | ||
7 | const multer = require('multer') | 6 | const multer = require('multer') |
8 | 7 | ||
9 | const logger = require('../../../helpers/logger') | 8 | const logger = require('../../../helpers/logger') |
@@ -61,15 +60,13 @@ function addVideo (req, res, next) { | |||
61 | return next(err) | 60 | return next(err) |
62 | } | 61 | } |
63 | 62 | ||
64 | ffmpeg.ffprobe(video_file.path, function (err, metadata) { | 63 | videos.getVideoDuration(video_file.path, function (err, duration) { |
65 | if (err) { | 64 | if (err) { |
66 | // TODO: unseed the video | 65 | // TODO: unseed the video |
67 | logger.error('Cannot retrieve metadata of the file') | 66 | logger.error('Cannot retrieve metadata of the file') |
68 | return next(err) | 67 | return next(err) |
69 | } | 68 | } |
70 | 69 | ||
71 | const duration = Math.floor(metadata.format.duration) | ||
72 | |||
73 | const video_data = { | 70 | const video_data = { |
74 | name: video_infos.name, | 71 | name: video_infos.name, |
75 | namePath: video_file.filename, | 72 | namePath: video_file.filename, |
diff --git a/server/lib/videos.js b/server/lib/videos.js index 24178561d..43d6c6b99 100644 --- a/server/lib/videos.js +++ b/server/lib/videos.js | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | const async = require('async') | 3 | const async = require('async') |
4 | const config = require('config') | 4 | const config = require('config') |
5 | const ffmpeg = require('fluent-ffmpeg') | ||
5 | const pathUtils = require('path') | 6 | const pathUtils = require('path') |
6 | const webtorrent = require('../lib/webtorrent') | 7 | const webtorrent = require('../lib/webtorrent') |
7 | 8 | ||
@@ -11,11 +12,20 @@ const Videos = require('../models/videos') | |||
11 | const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads')) | 12 | const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads')) |
12 | 13 | ||
13 | const videos = { | 14 | const videos = { |
15 | getVideoDuration: getVideoDuration, | ||
14 | getVideoState: getVideoState, | 16 | getVideoState: getVideoState, |
15 | seed: seed, | 17 | seed: seed, |
16 | seedAllExisting: seedAllExisting | 18 | seedAllExisting: seedAllExisting |
17 | } | 19 | } |
18 | 20 | ||
21 | function getVideoDuration (video_path, callback) { | ||
22 | ffmpeg.ffprobe(video_path, function (err, metadata) { | ||
23 | if (err) return callback(err) | ||
24 | |||
25 | return callback(null, Math.floor(metadata.format.duration)) | ||
26 | }) | ||
27 | } | ||
28 | |||
19 | function getVideoState (video) { | 29 | function getVideoState (video) { |
20 | const exist = (video !== null) | 30 | const exist = (video !== null) |
21 | let owned = false | 31 | let owned = false |