Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Decoding done with iconv-lite, support for all idv3 text encoding types #4

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,403 changes: 1,403 additions & 0 deletions audio-metadata.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion audio-metadata.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions audio-metadata.min.js.map

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
{
"name": "audio-metadata",
"version": "0.3.0",
"version": "0.3.1",
"description": "Extract metadata from audio files",
"keywords": [ "id3", "metadata", "mp3", "ogg", "wav", "audio" ],

"keywords": [
"id3",
"metadata",
"mp3",
"ogg",
"wav",
"audio"
],
"author": "Tommy Montgomery <[email protected]> (http://tmont.com/)",
"repository": {
"type": "git",
"url": "https://github.com/tmont/audio-metadata.git"
},

"bin": "bin/audio-metadata.js",

"files": [
"index.js",
"audio-metadata.min.js",
"src",
"bin",
"README.md"
],

"license": "WTFPL",

"dependencies": {},
"devDependencies": {
"mocha": "1.16.2",
"should": "2.1.1",
"browserify": "3.19.1",
"uglify-js": "2.4.8",
"serve": "1.3.0"
"browserify": "^14.0.0",
"envify": "^4.0.0",
"mocha": "^1.16.2",
"serve": "^1.3.0",
"should": "^2.1.1",
"uglify-js2": "^2.1.11"
},

"scripts": {
"test": "./node_modules/.bin/mocha -R spec tests",
"start": "./node_modules/.bin/serve -p 24578 .",
"build": "./node_modules/.bin/browserify -s AudioMetadata -e index.js --bare > audio-metadata.js",
"minify": "npm run build && ./node_modules/.bin/uglifyjs audio-metadata.js > audio-metadata.min.js && rm audio-metadata.js"
"build": "./node_modules/.bin/browserify -t [ envify --NODE_ENV browserify ] -s AudioMetadata -e index.js -u src/iso_639_2.js --bare > audio-metadata.js",
"minify": "npm run build && ./node_modules/.bin/uglifyjs2 -m -c --source-map audio-metadata.min.js.map audio-metadata.js > audio-metadata.min.js"
}
}
}
28 changes: 15 additions & 13 deletions src/id3v1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var utils = require('./utils');

function checkMagicId3v1(view) {
Expand All @@ -6,20 +8,16 @@ function checkMagicId3v1(view) {
return id3Magic[0] === 84 && id3Magic[1] === 65 && id3Magic[2] === 71;
}

module.exports = function(buffer) {
module.exports = function(buffer, opts) {
//read last 128 bytes
var view = utils.createView(buffer);
if (!checkMagicId3v1(view)) {
return null;
}

function trim(value) {
return value.replace(/[\s\u0000]+$/, '');
}

try {
var offset = view.byteLength - 128 + 3,
readAscii = utils.readAscii;
readAscii = utils.readAscii.bind( utils );
var title = readAscii(view, offset, 30),
artist = readAscii(view, offset + 30, 30),
album = readAscii(view, offset + 60, 30),
Expand All @@ -39,15 +37,19 @@ module.exports = function(buffer) {

offset += 2;
var genre = view.getUint8(offset);
return {
title: trim(title),
artist: trim(artist),
album: trim(album),
year: trim(year),
comment: trim(comment),
var tag = {
title: title,
artist: artist,
album: album,
year: year,
comment: comment,
track: track,
genre: genre
};
}
if ( opts && opts.toId3v2 ) {
tag = utils.id3v2.transformTag( tag );
}
return tag;
} catch (e) {
return null;
}
Expand Down
Loading