« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/downloaders.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/downloaders.js')
-rw-r--r--src/downloaders.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index 04838c2..c3dc43d 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -102,11 +102,25 @@ function makePowerfulDownloader(downloader, maxAttempts = 5) {
   }
 }
 
+function makeConverterDownloader(downloader, type) {
+  return async function(arg) {
+    const inFile = await downloader(arg)
+    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)
+
+    return outFile
+  }
+}
+
 module.exports = {
   makeHTTPDownloader,
   makeYouTubeDownloader,
   makeLocalDownloader,
   makePowerfulDownloader,
+  makeConverterDownloader,
 
   getDownloaderFor(arg) {
     if (arg.startsWith('http://') || arg.startsWith('https://')) {