From 13902daedddce2b186518b8468ba22f1a689d54f Mon Sep 17 00:00:00 2001 From: DC Date: Mon, 21 Mar 2016 17:49:19 -0700 Subject: [PATCH] Use largest image in torrent as the poster ...as a fallback, if no the torrent doesn't contain any video files --- renderer/index.js | 5 +++-- renderer/lib/torrent-poster.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 01054815..810ace96 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -510,6 +510,7 @@ function updateTorrentProgress () { var changed = false state.client.torrents.forEach(function (torrent) { var torrentSummary = getTorrentSummary(torrent.infoHash) + if (!torrentSummary) return torrent.files.forEach(function (file, index) { var numPieces = file._endPiece - file._startPiece + 1 var numPiecesPresent = 0 @@ -530,12 +531,12 @@ function updateTorrentProgress () { } function generateTorrentPoster (torrent, torrentSummary) { - torrentPoster(torrent, function (err, buf) { + torrentPoster(torrent, function (err, buf, extension) { if (err) return onWarning(err) // save it for next time mkdirp(config.CONFIG_POSTER_PATH, function (err) { if (err) return onWarning(err) - var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + '.jpg') + var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + extension) fs.writeFile(posterFilePath, buf, function (err) { if (err) return onWarning(err) // show the poster diff --git a/renderer/lib/torrent-poster.js b/renderer/lib/torrent-poster.js index 9e0f7463..087c6d0f 100644 --- a/renderer/lib/torrent-poster.js +++ b/renderer/lib/torrent-poster.js @@ -4,19 +4,32 @@ var captureVideoFrame = require('./capture-video-frame') var path = require('path') function torrentPoster (torrent, cb) { - // filter out file formats that the