Skip to content

Commit

Permalink
Fix Ogg multi-page-metadata-plugin workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Feb 4, 2018
1 parent f1a5620 commit cff5fbc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm install music-metadata
| flac | audio/flac | Vorbis |
| m4a, m4b, m4p, m4v, m4r, 3gp, mp4, aac | audio/aac, audio/aacp | QTFF |
| mp2, mp3, m2a | audio/mpeg | ID3v1.1, ID3v2 |
| ogv, oga, ogx, ogg | audio/ogg, application/ogg | Vorbis |
| ogv, oga, ogx, ogg, opus | audio/ogg, application/ogg | Vorbis |
| wav | audio/wav, audio/wave | ID3v2, RIFF/INFO (EXIF 2.3) |
| wv, wvp | audio/x-wavpack | APEv2 |

Expand Down
4 changes: 4 additions & 0 deletions src/ogg/OggParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class OggParser implements ITokenParser {
}
});
});
}).catch (err => {
if (err.message !== "End-Of-File") {
throw err;
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/opus/Opus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class IdHeader implements Token.IGetToken<IIdHeader> {

constructor(public len: number) {
if (len < 19) {
throw new Error("ID-header-page 0 should be at leader 19 bytes long");
throw new Error("ID-header-page 0 should be at least 19 bytes long");
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/test-mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const t = assert;

describe("MIME & extension mapping", () => {

const buf = new Buffer(16).fill(0);
const buf = new Buffer(30).fill(0);

const audioExtension = [".aac", ".mp3", ".ogg", ".wav", ".flac", ".m4a"]; // ToDo: ass ".ac3"

Expand All @@ -18,10 +18,8 @@ describe("MIME & extension mapping", () => {
case ".m4a":
case ".flac":
case ".wav":
t.strictEqual(err.message, "FourCC contains invalid characters", "Extension=" + extension);
break;
case ".ogg":
t.strictEqual(err.message, "End-Of-File", "Extension=" + extension);
t.strictEqual(err.message, "FourCC contains invalid characters", "Extension=" + extension);
break;

default:
Expand Down
4 changes: 1 addition & 3 deletions test/test-ogg-multipagemetadatabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import * as path from 'path';

const t = assert;

it("ogg-multipage-metadata-bug", function() {

this.skip();
it("ogg-multipage-metadata-bug", () => {

const filename = 'ogg-multipagemetadata-bug.ogg';
const filePath = path.join(__dirname, 'samples', filename);
Expand Down
15 changes: 14 additions & 1 deletion test/test-ogg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {} from "mocha";
import {assert} from 'chai';
import {assert, expect} from 'chai';
import * as mm from '../src';
import * as path from 'path';
import * as fs from 'fs-extra';
import {IdHeader} from "../src/opus/Opus";
import {OggParser} from "../src/ogg/OggParser";

describe("Parsing Ogg", function() {

Expand Down Expand Up @@ -81,6 +83,17 @@ describe("Parsing Ogg", function() {

describe("Parsing Ogg/Opus", () => {

describe("components", () => {

it("IdHeader should throw error if data is shorter than header", () => {
try {
const idHeader = new IdHeader(18);
} catch (err) {
expect(err.message).to.equal('ID-header-page 0 should be at least 19 bytes long');
}
});
});

describe("decode: Nirvana - In Bloom - 2-sec.opus", () => {

const filePath = path.join(__dirname, 'samples', "Nirvana - In Bloom - 2-sec.opus");
Expand Down

0 comments on commit cff5fbc

Please sign in to comment.