Move video duration logic in lib/
This commit is contained in:
parent
ae852eaf2d
commit
0ae6a09d40
2 changed files with 11 additions and 4 deletions
|
@ -3,7 +3,6 @@
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const ffmpeg = require('fluent-ffmpeg')
|
|
||||||
const multer = require('multer')
|
const multer = require('multer')
|
||||||
|
|
||||||
const logger = require('../../../helpers/logger')
|
const logger = require('../../../helpers/logger')
|
||||||
|
@ -61,15 +60,13 @@ function addVideo (req, res, next) {
|
||||||
return next(err)
|
return next(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ffmpeg.ffprobe(video_file.path, function (err, metadata) {
|
videos.getVideoDuration(video_file.path, function (err, duration) {
|
||||||
if (err) {
|
if (err) {
|
||||||
// TODO: unseed the video
|
// TODO: unseed the video
|
||||||
logger.error('Cannot retrieve metadata of the file')
|
logger.error('Cannot retrieve metadata of the file')
|
||||||
return next(err)
|
return next(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const duration = Math.floor(metadata.format.duration)
|
|
||||||
|
|
||||||
const video_data = {
|
const video_data = {
|
||||||
name: video_infos.name,
|
name: video_infos.name,
|
||||||
namePath: video_file.filename,
|
namePath: video_file.filename,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
|
const ffmpeg = require('fluent-ffmpeg')
|
||||||
const pathUtils = require('path')
|
const pathUtils = require('path')
|
||||||
const webtorrent = require('../lib/webtorrent')
|
const webtorrent = require('../lib/webtorrent')
|
||||||
|
|
||||||
|
@ -11,11 +12,20 @@ const Videos = require('../models/videos')
|
||||||
const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
|
const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
|
||||||
|
|
||||||
const videos = {
|
const videos = {
|
||||||
|
getVideoDuration: getVideoDuration,
|
||||||
getVideoState: getVideoState,
|
getVideoState: getVideoState,
|
||||||
seed: seed,
|
seed: seed,
|
||||||
seedAllExisting: seedAllExisting
|
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) {
|
function getVideoState (video) {
|
||||||
const exist = (video !== null)
|
const exist = (video !== null)
|
||||||
let owned = false
|
let owned = false
|
||||||
|
|
Loading…
Reference in a new issue