From 3f60f1c7f2585ce3a8bc4f7c3db8e3a2cfeef64d Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 3 Mar 2016 23:37:41 -0800 Subject: [PATCH] only produce poster image from valid file types --- main/index.js | 2 +- main/lib/torrent-poster.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main/index.js b/main/index.js index 16d3f9dc..9ba00550 100644 --- a/main/index.js +++ b/main/index.js @@ -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() }) diff --git a/main/lib/torrent-poster.js b/main/lib/torrent-poster.js index e10cf8aa..0f6aeb85 100644 --- a/main/lib/torrent-poster.js +++ b/main/lib/torrent-poster.js @@ -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)