From 3a8a8b51228070d8e6a01ea6e460534aa0a20efc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 3 May 2016 22:41:46 +0200 Subject: Video duration support (server) --- server/controllers/api/v1/videos.js | 45 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'server/controllers/api') 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 @@ 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') @@ -60,26 +61,37 @@ function addVideo (req, res, next) { return next(err) } - const video_data = { - name: video_infos.name, - namePath: video_file.filename, - description: video_infos.description, - magnetUri: torrent.magnetURI, - author: res.locals.oauth.token.user.username - } - - Videos.add(video_data, function (err) { + ffmpeg.ffprobe(video_file.path, function (err, metadata) { if (err) { - // TODO unseed the video - logger.error('Cannot insert this video in the database.') + // TODO: unseed the video + logger.error('Cannot retrieve metadata of the file') return next(err) } - // Now we'll add the video's meta data to our friends - friends.addVideoToFriends(video_data) + const duration = Math.floor(metadata.format.duration) - // TODO : include Location of the new video -> 201 - res.type('json').status(204).end() + const video_data = { + name: video_infos.name, + namePath: video_file.filename, + description: video_infos.description, + magnetUri: torrent.magnetURI, + author: res.locals.oauth.token.user.username, + duration: duration + } + + Videos.add(video_data, function (err) { + if (err) { + // TODO unseed the video + logger.error('Cannot insert this video in the database.') + return next(err) + } + + // Now we'll add the video's meta data to our friends + friends.addVideoToFriends(video_data) + + // TODO : include Location of the new video -> 201 + res.type('json').status(204).end() + }) }) }) } @@ -144,7 +156,8 @@ function getFormatedVideo (video_obj) { podUrl: video_obj.podUrl, isLocal: videos.getVideoState(video_obj).owned, magnetUri: video_obj.magnetUri, - author: video_obj.author + author: video_obj.author, + duration: video_obj.duration } return formated_video -- cgit v1.2.3