diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-03 22:41:46 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-03 22:41:46 +0200 |
commit | 3a8a8b51228070d8e6a01ea6e460534aa0a20efc (patch) | |
tree | 00dadc882a50079ea29b28078ed45a8efc4fec3d /server/controllers | |
parent | 6d8ada5f24b245d3c84d29d65013f5315cbeff27 (diff) | |
download | PeerTube-3a8a8b51228070d8e6a01ea6e460534aa0a20efc.tar.gz PeerTube-3a8a8b51228070d8e6a01ea6e460534aa0a20efc.tar.zst PeerTube-3a8a8b51228070d8e6a01ea6e460534aa0a20efc.zip |
Video duration support (server)
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/v1/videos.js | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js index d25ca95f7..e69628961 100644 --- a/server/controllers/api/v1/videos.js +++ b/server/controllers/api/v1/videos.js | |||
@@ -3,6 +3,7 @@ | |||
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') | ||
6 | const multer = require('multer') | 7 | const multer = require('multer') |
7 | 8 | ||
8 | const logger = require('../../../helpers/logger') | 9 | const logger = require('../../../helpers/logger') |
@@ -60,26 +61,37 @@ function addVideo (req, res, next) { | |||
60 | return next(err) | 61 | return next(err) |
61 | } | 62 | } |
62 | 63 | ||
63 | const video_data = { | 64 | ffmpeg.ffprobe(video_file.path, function (err, metadata) { |
64 | name: video_infos.name, | ||
65 | namePath: video_file.filename, | ||
66 | description: video_infos.description, | ||
67 | magnetUri: torrent.magnetURI, | ||
68 | author: res.locals.oauth.token.user.username | ||
69 | } | ||
70 | |||
71 | Videos.add(video_data, function (err) { | ||
72 | if (err) { | 65 | if (err) { |
73 | // TODO unseed the video | 66 | // TODO: unseed the video |
74 | logger.error('Cannot insert this video in the database.') | 67 | logger.error('Cannot retrieve metadata of the file') |
75 | return next(err) | 68 | return next(err) |
76 | } | 69 | } |
77 | 70 | ||
78 | // Now we'll add the video's meta data to our friends | 71 | const duration = Math.floor(metadata.format.duration) |
79 | friends.addVideoToFriends(video_data) | ||
80 | 72 | ||
81 | // TODO : include Location of the new video -> 201 | 73 | const video_data = { |
82 | res.type('json').status(204).end() | 74 | name: video_infos.name, |
75 | namePath: video_file.filename, | ||
76 | description: video_infos.description, | ||
77 | magnetUri: torrent.magnetURI, | ||
78 | author: res.locals.oauth.token.user.username, | ||
79 | duration: duration | ||
80 | } | ||
81 | |||
82 | Videos.add(video_data, function (err) { | ||
83 | if (err) { | ||
84 | // TODO unseed the video | ||
85 | logger.error('Cannot insert this video in the database.') | ||
86 | return next(err) | ||
87 | } | ||
88 | |||
89 | // Now we'll add the video's meta data to our friends | ||
90 | friends.addVideoToFriends(video_data) | ||
91 | |||
92 | // TODO : include Location of the new video -> 201 | ||
93 | res.type('json').status(204).end() | ||
94 | }) | ||
83 | }) | 95 | }) |
84 | }) | 96 | }) |
85 | } | 97 | } |
@@ -144,7 +156,8 @@ function getFormatedVideo (video_obj) { | |||
144 | podUrl: video_obj.podUrl, | 156 | podUrl: video_obj.podUrl, |
145 | isLocal: videos.getVideoState(video_obj).owned, | 157 | isLocal: videos.getVideoState(video_obj).owned, |
146 | magnetUri: video_obj.magnetUri, | 158 | magnetUri: video_obj.magnetUri, |
147 | author: video_obj.author | 159 | author: video_obj.author, |
160 | duration: video_obj.duration | ||
148 | } | 161 | } |
149 | 162 | ||
150 | return formated_video | 163 | return formated_video |