forked from RichardLitt/extract-id3-tags-from-mp3s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 765 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs')
const mm = require('musicmetadata')
const showMetadada = function (input) {
input = cleanInput(input)
return mm(fs.createReadStream(input), function (err, metadata) {
if (err) {
throw err
}
return mm(fs.createReadStream(input), { duration: true }, function (err, metadata) {
if (err) throw err
console.log(metadata)
})
})
}
const cleanInput = function (input) {
if (typeof input !== 'string' && !Buffer.isBuffer(input)) {
console.log('You need to povide a string or buffer as an argument!')
process.exit(1)
}
if (!input.endsWith('mp3')) {
console.log('You need to provide an .mp3 file!')
process.exit(1)
}
return input
}
module.exports = showMetadada(process.argv[2])