Skip to content
Browse files

Bug fixes. v0.0.1

  • Loading branch information...
1 parent eac8ac3 commit ba19a095cb46bfca0c5fa402284c2df615f411be @tim-smart tim-smart committed Sep 1, 2010
Showing with 34 additions and 16 deletions.
  1. +6 −6 lib/id3/common.js
  2. +7 −4 lib/id3/id3v2.js
  3. +6 −1 lib/id3/id3v2_frames.js
  4. +15 −5 lib/id3/index.js
View
12 lib/id3/common.js
@@ -20,7 +20,7 @@ exports.getInt24 = function getInt24 (b, offset, big_endian) {
byte3 = b[offset + 2];
var int = big_endian ?
- (((byte1 << 8) + byte2) << 8) + byte3:
+ (((byte1 << 8) + byte2) << 8) + byte3 :
(((byte3 << 8) + byte2) << 8) + byte1;
if (int < 0) int += 16777216;
return int;
@@ -64,7 +64,7 @@ var readUTF16String = function readUTF16String (bytes) {
var ix = 0,
offset1 = 1,
offset2 = 0,
- maxBytes = Math.min(maxBytes || bytes.length, bytes.length);
+ maxBytes = bytes.length;
if (bytes[0] === 0xFE && bytes[1] === 0xFF) {
bigEndian = true;
@@ -76,7 +76,7 @@ var readUTF16String = function readUTF16String (bytes) {
ix = 2;
}
- var arr = [];
+ var str = '';
for (var j = 0; ix < maxBytes; j++) {
var byte1 = bytes[ix + offset1],
byte2 = bytes[ix + offset2],
@@ -86,14 +86,14 @@ var readUTF16String = function readUTF16String (bytes) {
if (word1 === 0x0000) {
break;
} else if (byte1 < 0xD8 || byte1 >= 0xE0) {
- arr[j] = String.fromCharCode(word1);
+ str += String.fromCharCode(word1);
} else {
var byte3 = bytes[ix+offset1],
byte4 = bytes[ix+offset2],
word2 = (byte3 << 8) + byte4;
ix += 2;
- arr[j] = String.fromCharCode(word1, word2);
+ str += String.fromCharCode(word1, word2);
}
}
- return arr.join('');
+ return str;
};
View
11 lib/id3/id3v2.js
@@ -37,15 +37,13 @@ var readFrames = function readFrames (b, id3, offset, end) {
var frames = {},
frame_data_size,
major = id3.major,
- readFrameFunc,
flags,
frame,
frame_header_size,
frame_offset,
parsed_data;
while (offset < end) {
- readFrameFunc = null;
flags = null;
frame_offset = offset;
frame = {
@@ -99,10 +97,15 @@ var readFrames = function readFrames (b, id3, offset, end) {
}
// Parse data
- frame.data = parser.readData(b, frame.id, frame_offset, frame.size, flags, major);
+ try {
+ frame.data = parser.readData(b, frame.id, frame_offset, frame.size, flags, major);
+ } catch (error) {
+ // Couldn't parse frame :/
+ continue;
+ }
frame.description = FRAMES[frame.id] || 'Unknown';
- if (Object.hasOwnProperty(frames, frame.id)) {
+ if (frames.hasOwnProperty(frame.id)) {
if (frames[frame.id].id) {
frames[frame.id] = [frames[frame.id]];
}
View
7 lib/id3/id3v2_frames.js
@@ -40,7 +40,12 @@ exports.readData = function readData (b, type, offset, length, flags, major) {
offset += 1 + pic.description.length;
pic.description = pic.description.text;
- pic.data = b.slice(offset, start + length);
+ var data;
+ Object.defineProperty(pic, 'data', {
+ get: function () {
+ return data || (data = b.slice(offset, start + length));
+ }
+ });
return pic;
case 'COM':
View
20 lib/id3/index.js
@@ -21,11 +21,19 @@ ID3File.prototype.getID3Version = function getID3Version () {
};
ID3File.prototype.parse = function parse () {
- this.tags = this.getTags();
- this;
+ try {
+ this.tags = this.getTags();
+ } catch (error) {
+ try {
+ this.tags = this.getTags();
+ } catch (error) {
+ return false;
+ }
+ }
+ return true;
};
-ID3File.prototype.get = function get (name, def) {
+ID3File.prototype.get = function get (name, arr_first) {
if (!this.tags) return null;
if (this.version === 'id3v1' ||
@@ -42,11 +50,13 @@ ID3File.prototype.get = function get (name, def) {
if (name instanceof Array) {
for (length = name.length; i < length; i++) {
if (this.tags.hasOwnProperty(name[i])) {
- return this.tags[name[i]].data;
+ var data = this.tags[name[i]].data;
+ return arr_first && data instanceof Array ? data[0] : data;
}
}
} else if (this.tags.hasOwnProperty(name)) {
- return this.tags[name].data;
+ var data = this.tags[name].data;
+ return arr_first && data instanceof Array ? data[0] : data;
}
}

0 comments on commit ba19a09

Please sign in to comment.
Something went wrong with that request. Please try again.