Merge pull request #47 from feross/screenshot-exception

fix: no exception when screenshot cannot be made for any files in torrent
This commit is contained in:
Nate Goldman
2016-03-06 11:17:33 -08:00

View File

@@ -4,13 +4,16 @@ var captureVideoFrame = require('./capture-video-frame')
var path = require('path') var path = require('path')
function torrentPoster (torrent, cb) { function torrentPoster (torrent, cb) {
// use largest file // filter out file formats that the <video> tag definitely can't play
var file = torrent.files var files = torrent.files.filter(function (file) {
.filter(function (file) {
var extname = path.extname(file.name) var extname = path.extname(file.name)
return ['.mp4', '.webm', '.mov', '.mkv'].indexOf(extname) !== -1 return ['.mp4', '.webm', '.mov', '.mkv'].indexOf(extname) !== -1
}) })
.reduce(function (a, b) {
if (files.length === 0) return cb(new Error('cannot make screenshot for any files in torrent'))
// use largest file
var file = files.reduce(function (a, b) {
return a.length > b.length ? a : b return a.length > b.length ? a : b
}) })