Skip to content

Commit

Permalink
Merge pull request #1450 from webtorrent/reuse-media-extensions
Browse files Browse the repository at this point in the history
Reuse media extensions
  • Loading branch information
DiegoRBaquero authored Aug 15, 2018
2 parents cbbc61d + 8749135 commit 109accd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
11 changes: 11 additions & 0 deletions src/renderer/lib/media-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
30 changes: 4 additions & 26 deletions src/renderer/lib/torrent-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand Down
9 changes: 1 addition & 8 deletions src/renderer/lib/torrent-poster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ module.exports = torrentPoster
const captureFrame = require('capture-frame')
const path = require('path')

const mediaExtensions = {
audio: [
'.aac', '.asf', '.flac', '.m2a', '.m4a', '.m4b', '.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
Expand Down

0 comments on commit 109accd

Please sign in to comment.