fix: no exception when screenshot cannot be made for any files in torrent

This commit is contained in:
Feross Aboukhadijeh
2016-03-05 23:27:16 -08:00
committed by Nate Goldman
parent 4545a979cb
commit f1c1c72e63

View File

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