diff options
author | towerofnix <towerofnix@gmail.com> | 2017-08-07 21:10:00 -0300 |
---|---|---|
committer | towerofnix <towerofnix@gmail.com> | 2017-08-07 21:12:19 -0300 |
commit | 588482d3dad9a3ff023b6a152c490e375eb6746a (patch) | |
tree | 5a78d0e2ac765d105718075ad7877e6d744130b4 /src/downloaders.js | |
parent | e70c189576a80a162a3183172aac74f288e66ccd (diff) |
Windows support!
(Hopefully this didn't break macOS/Linux.)
Diffstat (limited to 'src/downloaders.js')
-rw-r--r-- | src/downloaders.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/downloaders.js b/src/downloaders.js index 2df6655..c41efa5 100644 --- a/src/downloaders.js +++ b/src/downloaders.js @@ -3,10 +3,11 @@ const fs = require('fs') const fse = require('fs-extra') const fetch = require('node-fetch') -const promisifyProcess = require('./promisify-process') const tempy = require('tempy') const path = require('path') const sanitize = require('sanitize-filename') +const promisifyProcess = require('./promisify-process') +const commandExists = require('./command-exists') const { spawn } = require('child_process') const { promisify } = require('util') @@ -109,14 +110,24 @@ function makePowerfulDownloader(downloader, maxAttempts = 5) { } } -function makeConverterDownloader(downloader, type) { - return async function(arg) { - const inFile = await downloader(arg) +async function makeConverter(type) { + let binary + if (await commandExists('avconv')) { + binary = 'avconv' + } else if (await commandExists('ffmpeg')) { + binary = 'ffmpeg' + } else { + throw new Error('avconv or ffmpeg is required for converter downloader!') + } + + console.log(`Using ${binary} converter.`) + + return async function(inFile) { const base = path.basename(inFile, path.extname(inFile)) const tempDir = tempy.directory() const outFile = `${tempDir}/${base}.${type}` - await promisifyProcess(spawn('avconv', ['-i', inFile, outFile]), false) + await promisifyProcess(spawn(binary, ['-i', inFile, outFile]), false) return outFile } @@ -127,7 +138,7 @@ module.exports = { makeYouTubeDownloader, makeLocalDownloader, makePowerfulDownloader, - makeConverterDownloader, + makeConverter, byName: { 'http': makeHTTPDownloader, |