music-metadata-browser
Advanced tools
Comparing version 0.5.0 to 0.6.1
@@ -10,8 +10,16 @@ import * as mm from 'music-metadata/lib/core'; | ||
* @param stream | ||
* @param mimeType | ||
* @param options Parsing options | ||
* @param {string} contentType MIME-Type | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
export declare const parseStream: typeof mm.parseStream; | ||
export declare const parseNodeStream: typeof mm.parseStream; | ||
/** | ||
* Parse Web API ReadableStream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream | ||
* @param {ReadableStream} stream ReadableStream | ||
* @param {string} contentType MIME-Type | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
export declare function parseReadableStream(stream: ReadableStream, contentType: any, options?: IOptions): Promise<IAudioMetadata>; | ||
/** | ||
* Parse audio from Node Buffer | ||
@@ -18,0 +26,0 @@ * @param {Stream.Readable} stream Audio input stream |
@@ -11,8 +11,23 @@ "use strict"; | ||
* @param stream | ||
* @param mimeType | ||
* @param options Parsing options | ||
* @param {string} contentType MIME-Type | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
exports.parseStream = mm.parseStream; | ||
exports.parseNodeStream = mm.parseStream; | ||
/** | ||
* Parse Web API ReadableStream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream | ||
* @param {ReadableStream} stream ReadableStream | ||
* @param {string} contentType MIME-Type | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
function parseReadableStream(stream, contentType, options) { | ||
const ns = new Browser2NodeStream_1.Browser2NodeStream(stream); | ||
return exports.parseNodeStream(ns, contentType, options).then(res => { | ||
debug(`Completed parsing from stream 1bytesRead=${ns.bytesRead} / fileSize=${options && options.fileSize ? options.fileSize : '?'}`); | ||
return res; | ||
}); | ||
} | ||
exports.parseReadableStream = parseReadableStream; | ||
/** | ||
* Parse audio from Node Buffer | ||
@@ -53,6 +68,4 @@ * @param {Stream.Readable} stream Audio input stream | ||
if (response.body) { | ||
const stream = new Browser2NodeStream_1.Browser2NodeStream(response.body); | ||
return this.parseStream(stream, contentType, options).then(res => { | ||
debug(`Closing stream 1bytesRead=${stream.bytesRead} / fileSize=${options && options.fileSize ? options.fileSize : '?'}`); | ||
stream.destroy(); | ||
return this.parseReadableStream(response.body, contentType, options).then(res => { | ||
response.body.cancel(); | ||
return res; | ||
@@ -59,0 +72,0 @@ }); |
{ | ||
"name": "music-metadata-browser", | ||
"version": "0.5.0", | ||
"version": "0.6.1", | ||
"description": "Browserifed version of music-metadata", | ||
@@ -86,3 +86,3 @@ "main": "dist/index.js", | ||
"debug": "^4.0.1", | ||
"music-metadata": "^3.1.1", | ||
"music-metadata": "^3.1.4", | ||
"remove": "^0.1.5", | ||
@@ -89,0 +89,0 @@ "typedarray-to-buffer": "^3.1.5" |
@@ -61,4 +61,2 @@ [![Build Status](https://travis-ci.org/Borewit/music-metadata-browser.svg?branch=master)](https://travis-ci.org/Borewit/music-metadata-browser) | ||
## Usage | ||
### Installation | ||
@@ -90,5 +88,6 @@ Install via [npm](http://npmjs.org/): | ||
There are currently three ways to parse (read) audio tracks: | ||
1) parsing a Web API blob or file with the [parseBlob function](#parseBlob). | ||
2) Using [Node.js streams](https://nodejs.org/api/stream.html) using the [parseStream function](#parseStream). | ||
3) Provide a URL to [fetch the audio track from](#fetchUrl). | ||
1) parsing a Web API blob or file with the [parseBlob function](#parseblob-function). | ||
2) Using [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) using the [parseReadableStream function](#parsereadablestream-function). | ||
3) Using [Node.js streams](https://nodejs.org/api/stream.html) using the [parseNodeStream function](#parsenodestream-function). | ||
3) Provide a URL to [fetch the audio track from](#fetchurl-function). | ||
@@ -114,9 +113,9 @@ #### parseBlob function | ||
``` | ||
#### parseStream function | ||
#### parseReadableStream function | ||
```javascript | ||
import * as mm from 'music-metadata-browser'; | ||
mm.parseStream(readableStream) | ||
mm.parseReadableStream(readableStream) | ||
.then( metadata => { | ||
@@ -127,3 +126,3 @@ console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
``` | ||
The readable stream is derived from [Node's readable stream](https://nodejs.org/api/stream.html#stream_readable_streams). | ||
Parse from a Web API [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream). | ||
@@ -139,5 +138,32 @@ If available, pass the mime-type and file-size. Without the mime-type, the content will be audio type will be automatically detected. | ||
mm.parseStream(someReadStream, 'audio/mpeg', { fileSize: 26838 }) | ||
const readableStream = result.node; | ||
mm.parseReadableStream(readableStream, 'audio/mpeg', { fileSize: 26838 }) | ||
.then( metadata => { | ||
console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
someReadStream.cancel(); | ||
}); | ||
``` | ||
#### parseNodeStream function | ||
```javascript | ||
import * as mm from 'music-metadata-browser'; | ||
mm.parseNodeStream(readableStream) | ||
.then( metadata => { | ||
console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
readableStream.destroy(); | ||
}); | ||
``` | ||
The readable stream is derived from [Node's readable stream](https://nodejs.org/api/stream.html#stream_readable_streams). | ||
If available, pass the mime-type and file-size. Without the mime-type, the content will be audio type will be automatically detected. | ||
```javascript | ||
import * as mm from 'music-metadata-browser'; | ||
mm.parseNodeStream(someReadStream, 'audio/mpeg', { fileSize: 26838 }) | ||
.then( metadata => { | ||
console.log(util.inspect(metadata, { showHidden: false, depth: null })); | ||
someReadStream.close(); | ||
@@ -147,3 +173,3 @@ }); | ||
### fetchUrl | ||
### fetchUrl function | ||
@@ -179,3 +205,3 @@ If you wish to stream your audio track over HTTP you need can use `fetchFromUrl` which is using the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to retrieve the audio track: | ||
* `duration`: default: `false`, if set to `true`, it will parse the whole media file if required to determine the duration. | ||
* `fileSize`: only provide this in combination with `parseStream` function. | ||
* `fileSize`: provide this if parsing from a stream. | ||
* `loadParser: (moduleName: string) => Promise<ITokenParser>;`: default: lazy load using require, allows custom async lazy loading of parser modules. The resolved `ITokenParser` will not be cached. | ||
@@ -218,2 +244,8 @@ * `native`: default: `false`, if set to `true`, it will return native tags in addition to the `common` tags. | ||
#### Automated testing | ||
Automated unit tests are planned to be tested with different browsers. This service has been made available by: | ||
[<img src="https://svgshare.com/i/8i6.svg" width="250" alt="Windows Media logo">](http://browserstack.com/) | ||
## Licence | ||
@@ -220,0 +252,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
339363
353
257
Updatedmusic-metadata@^3.1.4