From c2a38bd4e063a6ccfbf9bcd63d95ff932f3aa44a Mon Sep 17 00:00:00 2001 From: Borewit Date: Mon, 13 Aug 2018 21:35:37 +0200 Subject: [PATCH] Ensure consistency between extension-categories, between torrent-player and torrent-poster. Add additional audio-file-extensions. --- src/renderer/lib/media-extensions.js | 8 ++++++++ src/renderer/lib/torrent-player.js | 30 ++++------------------------ src/renderer/lib/torrent-poster.js | 7 +------ 3 files changed, 13 insertions(+), 32 deletions(-) create mode 100644 src/renderer/lib/media-extensions.js diff --git a/src/renderer/lib/media-extensions.js b/src/renderer/lib/media-extensions.js new file mode 100644 index 0000000000..fefac0227c --- /dev/null +++ b/src/renderer/lib/media-extensions.js @@ -0,0 +1,8 @@ +const mediaExtensions = { + audio: ['.aac', '.asf', '.flac', '.m2a', '.m4a', '.m4b', '.mp2', '.mp4', '.mp3', '.oga', '.ogg', + '.opus', '.wma', '.wav', '.wv', '.wvp'], + video: ['.avi', '.mp4', '.m4v', '.webm', '.mov', '.mkv', 'mpg', 'mpeg', '.ogv', '.webm', '.wmv'], + image: ['.gif', '.jpg', '.jpeg', '.png'] +} + +module.exports = mediaExtensions diff --git a/src/renderer/lib/torrent-player.js b/src/renderer/lib/torrent-player.js index 723d2cfa32..ab0e9702d0 100644 --- a/src/renderer/lib/torrent-player.js +++ b/src/renderer/lib/torrent-player.js @@ -8,6 +8,8 @@ module.exports = { const path = require('path') +const mediaExtensions = require('./media-extensions') + // Checks whether a fileSummary or file path is audio/video that we can play, // based on the file extension function isPlayable (file) { @@ -16,36 +18,12 @@ function isPlayable (file) { // Checks whether a fileSummary or file path is playable video function isVideo (file) { - return [ - '.avi', - '.m4v', - '.mkv', - '.mov', - '.mp4', - '.mpg', - '.ogv', - '.webm', - '.wmv' - ].includes(getFileExtension(file)) + return mediaExtensions.video.includes(getFileExtension(file)) } // Checks whether a fileSummary or file path is playable audio function isAudio (file) { - return [ - '.aac', - '.aiff', - '.ape', - '.ac3', - '.flac', - '.m4a', - '.mp2', - '.mp3', - '.oga', - '.ogg', - '.opus', - '.wav', - '.wma' - ].includes(getFileExtension(file)) + return mediaExtensions.audio.includes(getFileExtension(file)) } // Checks if the argument is either: diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index 8672f3fb60..8f4d153d54 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -3,12 +3,7 @@ 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'] -} +const mediaExtensions = require('./media-extensions') function torrentPoster (torrent, cb) { // First, try to use a poster image if available