Skip to content

Commit

Permalink
#196 Add support for unofficial ID3v2 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Apr 12, 2019
1 parent 1eae4a2 commit 039d025
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
15 changes: 2 additions & 13 deletions src/aiff/AiffParser.ts
Expand Up @@ -10,6 +10,7 @@ import { BasicParser } from '../common/BasicParser';

import * as AiffToken from './AiffToken';
import * as iff from '../iff';
import { ID3Stream } from "../id3v2/ID3Stream";

const debug = initDebug('music-metadata:parser:aiff');

Expand Down Expand Up @@ -82,7 +83,7 @@ export class AIFFParser extends BasicParser {
const id3_data = await this.tokenizer.readToken<Buffer>(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await ID3v2Parser.getInstance().parse(this.metadata, rst, this.options);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
return header.chunkSize;

case 'SSND': // Sound Data Chunk
Expand All @@ -97,15 +98,3 @@ export class AIFFParser extends BasicParser {
}

}

class ID3Stream extends Readable {

constructor(private buf: Buffer) {
super();
}

public _read() {
this.push(this.buf);
this.push(null); // push the EOF-signaling `null` chunk
}
}
10 changes: 10 additions & 0 deletions src/dsdiff/DsdiffParser.ts
Expand Up @@ -3,8 +3,11 @@ import * as Token from 'token-types';
import * as initDebug from 'debug';
import { FourCcToken } from '../common/FourCC';
import { BasicParser } from '../common/BasicParser';
import { ID3Stream } from '../id3v2/ID3Stream';

import {ChunkHeader, IChunkHeader} from "./DsdiffToken";
import * as strtok3 from "strtok3/lib/core";
import { ID3v2Parser } from "../id3v2/ID3v2Parser";

const debug = initDebug('music-metadata:parser:aiff');

Expand Down Expand Up @@ -62,6 +65,13 @@ export class DsdiffParser extends BasicParser {
await this.handleSoundPropertyChunks(header.chunkSize - FourCcToken.len);
break;

case 'ID3': // Unofficial ID3 tag support
const id3_data = await this.tokenizer.readToken<Buffer>(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
break;

default:
debug(`Ignore chunk[ID=${header.chunkID}, size=${header.chunkSize}]`);
break;
Expand Down
16 changes: 16 additions & 0 deletions src/id3v2/ID3Stream.ts
@@ -0,0 +1,16 @@
import { Readable } from "stream";

/**
* Utility to convert stream to buffer
*/
export class ID3Stream extends Readable {

constructor(private buf: Buffer) {
super();
}

public _read() {
this.push(this.buf);
this.push(null); // push the EOF-signaling `null` chunk
}
}
4 changes: 0 additions & 4 deletions src/id3v2/ID3v2Parser.ts
Expand Up @@ -30,10 +30,6 @@ interface IFrameHeader {

export class ID3v2Parser {

public static getInstance(): ID3v2Parser {
return new ID3v2Parser();
}

public static removeUnsyncBytes(buffer: Buffer): Buffer {
let readI = 0;
let writeI = 0;
Expand Down
16 changes: 2 additions & 14 deletions src/riff/WaveParser.ts
Expand Up @@ -2,7 +2,6 @@ import { endOfFile } from 'strtok3/lib/type';
import * as strtok3 from 'strtok3/lib/core';
import * as Token from 'token-types';
import * as initDebug from 'debug';
import { Readable } from 'stream';

import * as riff from './RiffChunk';
import * as WaveChunk from './../wav/WaveChunk';
Expand All @@ -11,6 +10,7 @@ import { ID3v2Parser } from '../id3v2/ID3v2Parser';
import Common from '../common/Util';
import { FourCcToken } from '../common/FourCC';
import { BasicParser } from '../common/BasicParser';
import { ID3Stream } from "../id3v2/ID3Stream";

const debug = initDebug('music-metadata:parser:RIFF');

Expand Down Expand Up @@ -95,7 +95,7 @@ export class WaveParser extends BasicParser {
const id3_data = await this.tokenizer.readToken<Buffer>(new Token.BufferType(header.chunkSize));
const id3stream = new ID3Stream(id3_data);
const rst = strtok3.fromStream(id3stream);
await ID3v2Parser.getInstance().parse(this.metadata, rst, this.options);
await new ID3v2Parser().parse(this.metadata, rst, this.options);
break;

case 'data': // PCM-data
Expand Down Expand Up @@ -157,15 +157,3 @@ export class WaveParser extends BasicParser {
}

}

class ID3Stream extends Readable {

constructor(private buf: Buffer) {
super();
}

public _read() {
this.push(this.buf);
this.push(null); // push the EOF-signaling `null` chunk
}
}

0 comments on commit 039d025

Please sign in to comment.