only produce poster image from valid file types

This commit is contained in:
Feross Aboukhadijeh
2016-03-03 23:37:41 -08:00
parent 75a33228e8
commit 3f60f1c7f2
2 changed files with 11 additions and 4 deletions

View File

@@ -216,7 +216,7 @@ function addTorrentEvents (torrent) {
function torrentReady (torrent) {
torrentPoster(torrent, function (err, buf) {
if (err) return onError(err)
if (err) return onWarning(err)
torrent.posterURL = URL.createObjectURL(new Blob([ buf ], { type: 'image/png' }))
update()
})

View File

@@ -1,12 +1,19 @@
module.exports = torrentPoster
var captureVideoFrame = require('./capture-video-frame')
var path = require('path')
function torrentPoster (torrent, cb) {
// use largest file
var index = torrent.files.indexOf(torrent.files.reduce(function (a, b) {
return a.length > b.length ? a : b
}))
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 index = torrent.files.indexOf(file)
var server = torrent.createServer(0)
server.listen(0, onListening)