« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--backend.js3
-rw-r--r--downloaders.js4
-rw-r--r--guess.js3
3 files changed, 6 insertions, 4 deletions
diff --git a/backend.js b/backend.js
index 7ee6873..379a16b 100644
--- a/backend.js
+++ b/backend.js
@@ -7,6 +7,7 @@ const { getDownloaderFor } = require('./downloaders')
 const { getMetadataReaderFor } = require('./metadata-readers')
 const { getPlayer } = require('./players')
 const RecordStore = require('./record-store')
+const os = require('os')
 
 const {
   getTimeStringsFromSec,
@@ -568,7 +569,7 @@ class Backend extends EventEmitter {
     this.throttleMetadata = throttlePromise(10)
     this.metadataDictionary = {}
 
-    this.rootDirectory = process.env.HOME + '/.mtui'
+    this.rootDirectory = os.homedir() + '/.mtui'
     this.metadataPath = this.rootDirectory + '/track-metadata.json'
   }
 
diff --git a/downloaders.js b/downloaders.js
index 4c1ce38..e18c8e0 100644
--- a/downloaders.js
+++ b/downloaders.js
@@ -6,6 +6,7 @@ const mkdirp = promisify(require('mkdirp'))
 const fs = require('fs')
 const fetch = require('node-fetch')
 const tempy = require('tempy')
+const os = require('os')
 const path = require('path')
 const sanitize = require('sanitize-filename')
 
@@ -104,8 +105,7 @@ const removeFileProtocol = arg => {
 const downloaders = {
   extension: 'mp3', // Generally target file extension, used by youtube-dl
 
-  // TODO: Cross-platform stuff
-  rootCacheDir: process.env.HOME + '/.mtui/downloads',
+  rootCacheDir: os.homedir() + '/.mtui/downloads',
 
   http: cachify('http',
     arg => {
diff --git a/guess.js b/guess.js
index 56c614a..0748ce8 100644
--- a/guess.js
+++ b/guess.js
@@ -1,6 +1,7 @@
 'use strict'
 
 const Backend = require('./backend')
+const os = require('os')
 const processSmartPlaylist = require('./smart-playlist')
 
 const {
@@ -46,7 +47,7 @@ async function game() {
     }
   })
 
-  const sourcePath = process.argv[2] || process.env.HOME + '/Music'
+  const sourcePath = process.argv[2] || os.homedir() + '/Music'
   let grouplike = {source: ['crawl-local', sourcePath]}
   grouplike = await processSmartPlaylist(grouplike)