« get me outta code hell

Merge branch 'main' into merge-socket-mtui - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/downloaders.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-16 22:41:33 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 22:41:33 -0300
commitcd91ccbea9e76ee1de1e3cbcfe17d8a2cb6ef9b4 (patch)
treed98e0b2a100170c7f913da57fb8e010c4b581603 /downloaders.js
parent2a270f20cc8e2f2a0754d28d6892bb1bd27e45ce (diff)
parenteb6a997df675fc8176fb15f34450a0c1b8416edc (diff)
Merge branch 'main' into merge-socket-mtui merge-socket-mtui
So we made this merge commit *after* going through a whole
fidanglin' bunch of steps to flat-out rebase socket-mtui...
but of course, that was pretty hopeless from the start to
get just quite right. After all, we didn't know the exact
point of each commit and how to test out the changes, so
we couldn't make sure all our rebased commits were working
the same way. (This is maybe the single coolest reason to
make sure that automated tests *pass with 100% coverage
at every commit*, but obviously this project doesn't have
that. Alas!)

This merge commit follows up a different merge commit we
actually made almost exactly one year ago to this day
(also: our birthday LOL). We figure the testing done at
that point was quite a bit more thorough than we'd do
today, and anyway there's little reason to repeat the
work we did in that commit. Comparatively, this merge
commit is way smaller!

It was still fun to go through the whole rebasing
process, even if it didn't practically bring us
anywhere. You know, assuming the merge commit from
last year didn't accidentally destroy any code or
todos lol........ *prays* ^____^
Diffstat (limited to 'downloaders.js')
-rw-r--r--downloaders.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/downloaders.js b/downloaders.js
index 9e7c786..8dbdea8 100644
--- a/downloaders.js
+++ b/downloaders.js
@@ -8,9 +8,9 @@ import url from 'node:url'
 import {mkdirp} from 'mkdirp'
 import fetch from 'node-fetch'
 import sanitize from 'sanitize-filename'
-import tempy from 'tempy'
 
 import {promisifyProcess} from './general-util.js'
+import temporaryDirectory from './tempdir.js'
 
 const copyFile = (source, target) => {
   // Stolen from https://stackoverflow.com/a/30405105/4633828
@@ -110,9 +110,10 @@ downloaders.http =
       return hostname + pathname
     },
     arg => {
-      const out = (
-        tempy.directory() + '/' +
-        sanitize(decodeURIComponent(path.basename(arg))))
+      const out =
+        path.join(
+          temporaryDirectory(),
+          sanitize(decodeURIComponent(path.basename(arg))))
 
       return fetch(arg)
         .then(response => response.buffer())
@@ -124,8 +125,8 @@ downloaders.youtubedl =
   cachify('youtubedl',
     arg => (arg.match(/watch\?v=(.*)/) || ['', arg])[1],
     arg => {
-      const outDir = tempy.directory()
-      const outFile = outDir + '/%(id)s-%(uploader)s-%(title)s.%(ext)s'
+      const outDir = temporaryDirectory()
+      const outFile = path.join(outDir, '%(id)s-%(uploader)s-%(title)s.%(ext)s')
 
       const opts = [
         '--quiet',
@@ -138,7 +139,7 @@ downloaders.youtubedl =
 
       return promisifyProcess(spawn('youtube-dl', opts))
         .then(() => readdir(outDir))
-        .then(files => outDir + '/' + files[0])
+        .then(files => path.join(outDir, files[0]))
     })
 
 downloaders.local =
@@ -166,7 +167,7 @@ downloaders.local =
       // TODO: Is it necessary to sanitize here?
       // Haha, the answer to "should I sanitize" is probably always YES..
       const base = path.basename(arg, path.extname(arg))
-      const out = tempy.directory() + '/' + sanitize(base) + path.extname(arg)
+      const out = path.join(temporaryDirectory(), sanitize(base) + path.extname(arg))
 
       return copyFile(arg, out)
         .then(() => out)
@@ -180,7 +181,7 @@ downloaders.locallink =
 
       arg = removeFileProtocol(arg)
       const base = path.basename(arg, path.extname(arg))
-      const out = tempy.directory() + '/' + sanitize(base) + path.extname(arg)
+      const out = path.join(temporaryDirectory(), sanitize(base) + path.extname(arg))
 
       return symlink(path.resolve(arg), out)
         .then(() => out)