musicmetadata
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -91,2 +91,11 @@ 'use strict' | ||
exports.sum = function (arr) { | ||
var s = 0 | ||
var i | ||
for (i = 0; i < arr.length; i++) { | ||
s += arr[i] | ||
} | ||
return s | ||
} | ||
function swapBytes (buffer) { | ||
@@ -93,0 +102,0 @@ var l = buffer.length |
@@ -56,3 +56,3 @@ 'use strict' | ||
if (v.slice(0, 3).toString() === 'TAG') { | ||
return strtok.DONE | ||
return done() | ||
} | ||
@@ -59,0 +59,0 @@ |
@@ -6,2 +6,77 @@ 'use strict' | ||
module.exports = function (stream, callback, done) { | ||
var ApeDescriptor = { | ||
len: 44, | ||
get: function (buf, off) { | ||
return { | ||
ID: new strtok.StringType(4, 'ascii').get(buf, off), | ||
version: strtok.UINT32_LE.get(buf, off + 4) / 1000, | ||
descriptorBytes: strtok.UINT32_LE.get(buf, off + 8), | ||
headerDataBytes: strtok.UINT32_LE.get(buf, off + 12), | ||
APEFrameDataBytes: strtok.UINT32_LE.get(buf, off + 16), | ||
APEFrameDataBytesHigh: strtok.UINT32_LE.get(buf, off + 20), | ||
terminatingDataBytes: strtok.UINT32_LE.get(buf, off + 24), | ||
fileMD5: new strtok.BufferType(16).get(buf, 28) | ||
} | ||
} | ||
} | ||
// headerDataBytes = 24 | ||
var ApeHeader = { | ||
len: 24, | ||
get: function (buf, off) { | ||
return { | ||
compressionLevel: strtok.UINT16_LE.get(buf, off), | ||
formatFlags: strtok.UINT16_LE.get(buf, off + 2), | ||
blocksPerFrame: strtok.UINT32_LE.get(buf, off + 4), | ||
finalFrameBlocks: strtok.UINT32_LE.get(buf, off + 8), | ||
totalFrames: strtok.UINT32_LE.get(buf, off + 12), | ||
bitsPerSample: strtok.UINT16_LE.get(buf, off + 16), | ||
channel: strtok.UINT16_LE.get(buf, off + 18), | ||
sampleRate: strtok.UINT32_LE.get(buf, off + 20) | ||
} | ||
} | ||
} | ||
strtok.parse(stream, function (v, cb) { | ||
if (v === undefined) { | ||
cb.state = 0 | ||
return ApeDescriptor | ||
} | ||
switch (cb.state) { | ||
case 0: | ||
if (v.ID !== 'MAC ') { | ||
throw new Error('Expected MAC on beginning of file') | ||
} | ||
cb.state = 1 | ||
return new strtok.BufferType(v.descriptorBytes - 44) | ||
case 1: | ||
cb.state = 2 | ||
return ApeHeader | ||
case 2: | ||
callback('duration', calculateDuration(v)) | ||
return -1 | ||
} | ||
}) | ||
return readMetadata(stream, callback, done) | ||
} | ||
/** | ||
* Calculate the media file duration | ||
* @param ah ApeHeader | ||
* @return {number} duration in seconds | ||
*/ | ||
function calculateDuration (ah) { | ||
var duration = ah.totalFrames > 1 ? ah.blocksPerFrame * (ah.totalFrames - 1) : 0 | ||
duration += ah.finalFrameBlocks | ||
return duration / ah.sampleRate | ||
} | ||
function readMetadata (stream, callback, done) { | ||
var bufs = [] | ||
@@ -8,0 +83,0 @@ |
@@ -5,3 +5,3 @@ 'use strict' | ||
var common = require('./common') | ||
var sum = require('sum-component') | ||
var sum = common.sum | ||
@@ -8,0 +8,0 @@ module.exports = function (stream, callback, done, readDuration) { |
{ | ||
"name": "musicmetadata", | ||
"description": "Streaming music metadata parser for node and the browser.", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"author": "Lee Treveil", | ||
@@ -11,3 +11,2 @@ "dependencies": { | ||
"strtok2": "~1.0.0", | ||
"sum-component": "^0.1.1", | ||
"through": "~2.3.4" | ||
@@ -14,0 +13,0 @@ }, |
@@ -54,2 +54,11 @@ [![Build Status][travis-image]][travis-url] [![NPM version][npm-image]][npm-url] [![npm downloads][npm-downloads-image]][npm-url] | ||
Note, the stream is not closed by default. To prevent leaks, you must close it yourself: | ||
```javascript | ||
var readableStream = fs.createReadStream('sample.mp3'); | ||
var parser = mm(readableStream, function (err, metadata) { | ||
if (err) throw err; | ||
readableStream.close(); | ||
}); | ||
``` | ||
`musicmetadata` also emits all metadata it discovers during parsing. For example if you wanted to read the `TLEN` frame from an id3v2.x file you can do this: | ||
@@ -67,3 +76,3 @@ | ||
mm(fs.createReadStream('sample.mp3'), { duration: true }, function (err, metadata) { | ||
}); | ||
@@ -75,3 +84,3 @@ ``` | ||
mm(fs.createReadStream('sample.mp3'), { duration: true, fileSize: 26838 }, function (err, metadata) { | ||
}); | ||
@@ -85,3 +94,3 @@ ``` | ||
Copyright (c) 2015 Lee Treveil <leetreveil@gmail.com> | ||
Copyright (c) 2016 Lee Treveil <leetreveil@gmail.com> | ||
@@ -88,0 +97,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
319844
5
9275
105
0
- Removedsum-component@^0.1.1
- Removedcomponent-props@1.1.1(transitive)
- Removedsum-component@0.1.1(transitive)
- Removedto-function@2.0.6(transitive)