Skip to content

Commit 6cdb83f

Browse files
committed
Use music-metadata instead of musicmetadata
On some large songs, this slows down like crazy, but in general its a lot faster. We will have to dig in to why this is.
1 parent 4c9f62a commit 6cdb83f

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

main/lib/audio-library/sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function sort ([keyA, aObj], [keyB, bObj]) {
44
// if (aObj.albumartist[0] > bObj.albumartist[0]) return 1
55

66
// sort by artist
7-
if (aObj.artist[0] < bObj.artist[0]) return -1
8-
if (aObj.artist[0] > bObj.artist[0]) return 1
7+
if (aObj.artist < bObj.artist) return -1
8+
if (aObj.artist > bObj.artist) return 1
99

1010
// then by album
1111
if (aObj.album < bObj.album) return -1

main/track-dict.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
var fs = require('fs')
21
var path = require('path')
32
var walker = require('folder-walker')
4-
var mm = require('musicmetadata')
3+
var mm = require('music-metadata')
54
var writer = require('flush-write-stream')
65
var filter = require('through2-filter')
76
var pump = require('pump')
@@ -18,6 +17,7 @@ function makeTrackDict (paths, cb) {
1817

1918
function handleEos (err) {
2019
if (err) return cb(err)
20+
console.log('')
2121
cb(null, newTrackDict)
2222
}
2323
}
@@ -35,7 +35,7 @@ function concatTrackDict (obj) {
3535
parseMetadata(data, handleMeta)
3636

3737
function handleMeta (err, meta) {
38-
if (err) return cb(err)
38+
if (err) throw err
3939
obj[meta.filepath] = meta
4040
cb(null)
4141
}
@@ -45,25 +45,11 @@ function concatTrackDict (obj) {
4545

4646
function parseMetadata (data, cb) {
4747
var { filepath } = data
48-
var readableStream = fs.createReadStream(filepath)
49-
mm(readableStream, { duration: true }, (err, meta) => {
50-
readableStream.destroy()
51-
if (err) {
52-
switch (err.message) {
53-
case 'Could not find metadata header':
54-
console.warn(err.message += ` (file: ${filepath})`)
55-
break
56-
case 'expected frame header but was not found':
57-
console.warn(err.message += ` (file: ${filepath})`)
58-
break
59-
default:
60-
// Ignore errors
61-
console.warn(err.message += ` (file: ${filepath})`)
62-
return cb(null)
63-
}
64-
}
65-
// delete meta.picture
66-
// console.dir(meta, {colors: true, depth: 5})
48+
mm.parseFile(filepath, {
49+
duration: true,
50+
native: false,
51+
skipCovers: true
52+
}).then(meta => {
6753
var {
6854
albumartist,
6955
title,
@@ -72,17 +58,17 @@ function parseMetadata (data, cb) {
7258
year,
7359
track,
7460
disk,
75-
genre,
76-
duration
77-
} = meta
61+
genre
62+
} = meta.common
7863

64+
var { duration } = meta.format
7965
if (!title) {
8066
var { basename } = data
8167
var ext = path.extname(basename)
8268
title = path.basename(basename, ext)
8369
}
8470

85-
cb(null, {
71+
return Promise.resolve({
8672
albumartist,
8773
title,
8874
artist,
@@ -94,5 +80,14 @@ function parseMetadata (data, cb) {
9480
disk,
9581
genre
9682
})
83+
}).catch(err => {
84+
// Ignore errors
85+
console.log(err.message += ` (file: ${filepath})`)
86+
var { basename } = data
87+
var ext = path.extname(basename)
88+
var title = path.basename(basename, ext)
89+
return Promise.resolve({ title, filepath })
90+
}).then(meta => {
91+
cb(null, meta)
9792
})
9893
}

0 commit comments

Comments
 (0)