diff --git a/package.json b/package.json index ed4715785f..1d89fd7166 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "location-history": "^1.0.0", "material-ui": "^0.17.0", "mkdirp": "^0.5.1", - "music-metadata": "^0.9.8", + "music-metadata": "^0.9.15", "network-address": "^1.1.0", "parse-torrent": "^5.7.3", "prettier-bytes": "^1.0.1", diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index f05d1bb58b..ec10913510 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -3,39 +3,145 @@ module.exports = torrentPoster const captureFrame = require('capture-frame') const path = require('path') +const mediaExtensions = { + audio: ['.aac', '.asf', '.flac', '.m2a', '.m4a', '.mp2', '.mp4', '.mp3', '.oga', '.ogg', '.opus', + '.wma', '.wav', '.wv', '.wvp'], + video: ['.mp4', '.m4v', '.webm', '.mov', '.mkv'], + image: ['.gif', '.jpg', '.jpeg', '.png'] +} + function torrentPoster (torrent, cb) { // First, try to use a poster image if available const posterFile = torrent.files.filter(function (file) { return /^poster\.(jpg|png|gif)$/.test(file.name) })[0] - if (posterFile) return torrentPosterFromImage(posterFile, torrent, cb) + if (posterFile) return extractPoster(posterFile, cb) + + // 'score' each media type based on total size present in torrent + const bestScore = ['audio', 'video', 'image'].map(mediaType => { + return { + type: mediaType, + size: calculateDataLengthByExtension(torrent, mediaExtensions[mediaType])} + }).sort((a, b) => { // sort descending on size + return b.size - a.size + })[0] - // Second, try to use the largest video file - // Filter out file formats that the