music-metadata-browser
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -32,2 +32,17 @@ import * as mm from 'music-metadata/lib/core'; | ||
/** | ||
* Parse fetched file, using the Web Fetch API | ||
* @param {string} audioTrackUrl URL to download the audio track from | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
export declare function fetchFromUrl(audioTrackUrl: string, options?: IOptions): Promise<IAudioMetadata>; | ||
/** | ||
* Parse audio from ITokenizer source | ||
* @param {strtok3.ITokenizer} Audio source implementing the tokenizer interface | ||
* @param {string} mimeType <string> Content specification MIME-type, e.g.: 'audio/mpeg' | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
export declare const parseFromTokenizer: typeof mm.parseFromTokenizer; | ||
/** | ||
* Create a dictionary ordered by their tag id (key) | ||
@@ -34,0 +49,0 @@ * @param {ITag[]} nativeTags list of tags |
@@ -1,5 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const initDebug = require("debug"); | ||
const mm = require("music-metadata/lib/core"); | ||
const toBuffer = require("typedarray-to-buffer"); | ||
const Browser2NodeStream_1 = require("./fetch/Browser2NodeStream"); | ||
const debug = initDebug('music-metadata-browser'); | ||
/** | ||
@@ -35,2 +38,45 @@ * Parse audio Stream | ||
/** | ||
* Parse fetched file, using the Web Fetch API | ||
* @param {string} audioTrackUrl URL to download the audio track from | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
function fetchFromUrl(audioTrackUrl, options) { | ||
return fetch(audioTrackUrl).then(response => { | ||
const contentType = response.headers.get('Content-Type'); | ||
const headers = []; | ||
response.headers.forEach(header => { | ||
headers.push(header); | ||
}); | ||
if (response.ok) { | ||
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 res; | ||
}); | ||
} | ||
else { | ||
// Fall back on Blob | ||
return response.blob().then(blob => { | ||
return this.parseBlob(blob, options); | ||
}); | ||
} | ||
} | ||
else { | ||
throw new Error(`HTTP error status=${response.status}: ${response.statusText}`); | ||
} | ||
}); | ||
} | ||
exports.fetchFromUrl = fetchFromUrl; | ||
/** | ||
* Parse audio from ITokenizer source | ||
* @param {strtok3.ITokenizer} Audio source implementing the tokenizer interface | ||
* @param {string} mimeType <string> Content specification MIME-type, e.g.: 'audio/mpeg' | ||
* @param {IOptions} options Parsing options | ||
* @returns {Promise<IAudioMetadata>} | ||
*/ | ||
exports.parseFromTokenizer = mm.parseFromTokenizer; | ||
/** | ||
* Convert Web API File to Node Buffer | ||
@@ -37,0 +83,0 @@ * @param {Blob} blob Web API Blob |
// Karma configuration file, see link for more information | ||
// https://karma-runner.github.io/1.0/config/configuration-file.html | ||
const path = require('path'); | ||
const path = require('path') | ||
@@ -13,3 +13,3 @@ module.exports = config => { | ||
files: [ | ||
{ pattern: 'src/**/*.spec.ts' } | ||
{pattern: 'src/**/*.spec.ts'} | ||
], | ||
@@ -22,5 +22,7 @@ preprocessors: { | ||
mode: 'development', | ||
entry: './src/index.ts', | ||
resolve: { | ||
extensions: [ '.tsx', '.ts', '.js' ] | ||
extensions: ['.tsx', '.ts', '.js'] | ||
}, | ||
devtool: 'inline-source-map', | ||
module: { | ||
@@ -31,14 +33,31 @@ rules: [ | ||
use: 'ts-loader', | ||
exclude: /node_modules/ | ||
include: path.resolve('src') | ||
}, | ||
{ | ||
test: /\.ts$/, | ||
use: {loader: 'istanbul-instrumenter-loader'}, | ||
enforce: 'post', | ||
include: path.resolve('src'), | ||
exclude: /\.spec\.ts$/ | ||
} | ||
] | ||
}, | ||
}, | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
reporters: ['progress', 'kjhtml', 'coverage-istanbul'], | ||
reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'spec'], | ||
// https://www.npmjs.com/package/karma-coverage-istanbul-reporter | ||
coverageIstanbulReporter: { | ||
dir: path.join(__dirname, 'coverage'), | ||
reports: ['html', 'lcovonly'], | ||
fixWebpackSourcePaths: true | ||
reports: ['text-summary', 'lcovonly', 'html'], | ||
fixWebpackSourcePaths: true, | ||
'report-config': { | ||
html: { | ||
// outputs the report in ./coverage/html | ||
subdir: 'html' | ||
} | ||
} | ||
}, | ||
@@ -49,4 +68,3 @@ //autoWatch: true, | ||
singleRun: false | ||
}) | ||
}; | ||
} |
{ | ||
"name": "music-metadata-browser", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Browserifed version of music-metadata", | ||
@@ -52,6 +52,8 @@ "main": "dist/index.js", | ||
"prepublishOnly": "yarn run build", | ||
"build": "npm run compile-dist && npm run compile-test", | ||
"build": "npm run compile-dist", | ||
"lint": "tslint 'src/**/*.ts' --exclude 'src/**/*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts'", | ||
"karma": "karma start", | ||
"travis-karma": "karma start --browsers Firefox --single-run", | ||
"karma-firefox": "karma start --browsers Firefox", | ||
"karma-once": "karma start --browsers Chrome --single-run", | ||
"travis-karma": "karma start --browsers Firefox --single-run --reporters coverage-istanbul,spec", | ||
"post-coveralls": "coveralls < coverage/lcov.info" | ||
@@ -65,2 +67,3 @@ }, | ||
"filereader-stream": "^2.0.0", | ||
"istanbul-instrumenter-loader": "^3.0.1", | ||
"jasmine-core": "^3.2.1", | ||
@@ -73,2 +76,3 @@ "karma": "^3.0.0", | ||
"karma-jasmine-html-reporter": "^1.3.1", | ||
"karma-spec-reporter": "^0.0.32", | ||
"karma-webpack": "^3.0.5", | ||
@@ -84,5 +88,7 @@ "stream-http": "^2.8.3", | ||
"buffer": "^5.2.1", | ||
"debug": "^4.0.1", | ||
"music-metadata": "^3.1.1", | ||
"remove": "^0.1.5", | ||
"typedarray-to-buffer": "^3.1.5" | ||
} | ||
} |
@@ -5,2 +5,3 @@ [![Build Status](https://travis-ci.org/Borewit/music-metadata-browser.svg?branch=master)](https://travis-ci.org/Borewit/music-metadata-browser) | ||
[![dependencies Status](https://david-dm.org/Borewit/music-metadata-browser/status.svg)](https://david-dm.org/Borewit/music-metadata-browser) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/Borewit/music-metadata/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/music-metadata-browser?targetFile=package.json) | ||
[![Coverage Status](https://coveralls.io/repos/github/Borewit/music-metadata-browser/badge.svg?branch=master)](https://coveralls.io/github/Borewit/music-metadata-browser?branch=master) | ||
@@ -88,5 +89,6 @@ ![NPM version](https://img.shields.io/bundlephobia/min/music-metadata-browser.svg) | ||
There are currently two ways to parse (read) audio tracks: | ||
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). | ||
@@ -97,2 +99,3 @@ #### parseBlob function | ||
[filereader-stream](https://www.npmjs.com/package/filereader-stream) is used. | ||
```javascript | ||
@@ -142,25 +145,13 @@ import * as mm from 'music-metadata-browser'; | ||
If you wish to stream your audio track over HTTP you need HTTP-client which provides a stream like [stream-http](https://www.npmjs.com/package/stream-stream): | ||
### fetchUrl | ||
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: | ||
```javascript | ||
import * as mm from 'music-metadata-browser'; | ||
import http from "stream-http"; | ||
/** | ||
* @param url Ensure the source the URL is pointing to, meets the CORS requirements | ||
*/ | ||
function httpToStream(url) { | ||
return new Promise(resolve => { | ||
http.get(url, stream => { | ||
resolve(stream); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Stream over HTTP from URL | ||
*/ | ||
httpToStream(url).then(stream => { | ||
mm.parseStream(stream, stream.headers["content-type"]); | ||
}); | ||
return mm.fetchFromUrl(audioTrackUrl, options) | ||
``` | ||
@@ -167,0 +158,0 @@ |
@@ -13,3 +13,3 @@ { | ||
"object-literal-sort-keys": [false], | ||
"max-line-length": [true, 150], | ||
"max-line-length": [true, 200], | ||
"switch-default": false, | ||
@@ -16,0 +16,0 @@ "prefer-for-of": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
337646
14
332
6
20
225
1
+ Addeddebug@^4.0.1
+ Addedremove@^0.1.5
+ Addedchainsaw@0.0.9(transitive)
+ Addedhashish@0.0.4(transitive)
+ Addedremove@0.1.5(transitive)
+ Addedseq@0.3.5(transitive)
+ Addedtraverse@0.3.9(transitive)