diff --git a/common/async.js b/common/async.js index 57b72c6..3f59a39 100644 --- a/common/async.js +++ b/common/async.js @@ -72,4 +72,15 @@ function askAsync (rl, q) { }) } -export default {getFiles, promiseExec, askAsync, insertDB} +function copyAsync (fsrc, fdst) { + return new Promise((resolve, reject) => { + let source = fs.createReadStream(path.resolve(fsrc)) + let dest = fs.createWriteStream(path.resolve(fdst)) + + source.pipe(dest) + source.on('end', resolve) + source.on('error', reject) + }) +} + +export default {getFiles, promiseExec, askAsync, insertDB, copyAsync} diff --git a/download.js b/download.js index a6767de..e55f726 100755 --- a/download.js +++ b/download.js @@ -49,7 +49,8 @@ async function download (furl) { } let fn = path.join(musicdir, filename) - await fs.rename(file.source, fn) + await asn.copyAsync(file.source, fn) + await fs.unlink(file.source) let id3 = await asn.promiseExec(`id3 -a "${clean.artist}" -t "${clean.title}" "${fn}"`)