Skip to content

Commit b721b52

Browse files
committed
Update music-metadata in place
1 parent 875e334 commit b721b52

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

main/lib/artwork-cache/util.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var from = require('from2')
2-
var fs = require('fs')
32
var mm = require('music-metadata')
43
var get = require('lodash.get')
54

65
exports.fromBuffer = fromBuffer
76

87
function fromBuffer (buffer) {
8+
// TODO: Use https://github.com/rvagg/bl ?
99
return from(function (size, next) {
1010
if (buffer.length <= 0) return next(null, null)
1111
var chunk = buffer.slice(0, size)
@@ -15,21 +15,14 @@ function fromBuffer (buffer) {
1515
}
1616

1717
function metadata (path, cb) {
18-
var audioStream = fs.createReadStream(path)
19-
var returned = false // TODO clean up racy code
20-
audioStream.on('error', (err) => {
21-
if (!returned) {
22-
returned = true
23-
return cb(err)
24-
}
25-
})
26-
mm.parseStream(audioStream, {native: true}, function (err, metadata) {
27-
// important note, the stream is not closed by default. To prevent leaks, you must close it yourself
28-
audioStream.destroy()
29-
if (!returned) {
30-
returned = true
31-
return cb(err, err ? null : metadata)
32-
}
18+
mm.parseFile(path, {
19+
native: true,
20+
duration: true,
21+
skipCovers: false
22+
}).then(function (md) {
23+
return cb(null, md)
24+
}).catch(function (err) {
25+
return cb(err)
3326
})
3427
}
3528

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"lodash.throttle": "^4.1.1",
6262
"mkdirp": "^0.5.1",
6363
"mousetrap": "^1.6.1",
64-
"music-metadata": "^0.6.1",
64+
"music-metadata": "^0.8.7",
6565
"musicmetadata": "^2.0.4",
6666
"nanobus": "^4.1.0",
6767
"nanocomponent": "^6.0.0",

0 commit comments

Comments
 (0)