Skip to content

Commit

Permalink
Fix endianness in Vorbis Identification header decoder
Browse files Browse the repository at this point in the history
Remove unused import
Code style fixes
  • Loading branch information
Borewit committed Jun 30, 2024
1 parent d53dd84 commit ccae86e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
1 change: 0 additions & 1 deletion lib/ParserFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { fileTypeFromBuffer } from 'file-type';
import ContentType from 'content-type';
import MimeType from 'media-typer';
import initDebug from 'debug';
import { Buffer } from 'node:buffer';

import { INativeMetadataCollector, MetadataCollector } from './common/MetadataCollector.js';
import { AIFFParser } from './aiff/AiffParser.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/aiff/AiffParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AIFFParser extends BasicParser {
public async readTextChunk(header: iff.IChunkHeader): Promise<number> {
const value = await this.tokenizer.readToken(new Token.StringType(header.chunkSize, 'ascii'));
const values = value.split('\0').map(v => v.trim()).filter(v => v && v.length);
await Promise.all(values.map((v) => this.metadata.addTag('AIFF', header.chunkID, v)));
await Promise.all(values.map(v => this.metadata.addTag('AIFF', header.chunkID, v)));
return header.chunkSize;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common/MetadataCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class MetadataCollector implements INativeMetadataCollector {

if (this.commonOrigin.artist === this.originPriority[tagType]) {
// Assume the artist field is used as artists
return await this.postMap('artificial', {id: 'artists', value: tag.value});
return this.postMap('artificial', {id: 'artists', value: tag.value});
}

if (!this.common.artists) {
Expand All @@ -171,7 +171,7 @@ export class MetadataCollector implements INativeMetadataCollector {
break;

case 'picture':
return await this.postFixPicture(tag.value as IPicture).then(picture => {
return this.postFixPicture(tag.value as IPicture).then(picture => {
if (picture !== null) {
tag.value = picture;
this.setGenericTag(tagType, tag);
Expand Down
8 changes: 4 additions & 4 deletions lib/flac/FlacParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class FlacParser extends AbstractID3Parser {
debug(`blockHeader type=${blockHeader.type}, length=${blockHeader.length}`);
switch (blockHeader.type) {
case BlockType.STREAMINFO:
return await this.parseBlockStreamInfo(blockHeader.length);
return this.parseBlockStreamInfo(blockHeader.length);
case BlockType.PADDING:
this.padding += blockHeader.length;
break;
Expand All @@ -81,12 +81,12 @@ export class FlacParser extends AbstractID3Parser {
case BlockType.SEEKTABLE:
break;
case BlockType.VORBIS_COMMENT:
return await this.parseComment(blockHeader.length);
return this.parseComment(blockHeader.length);
case BlockType.CUESHEET:
break;
case BlockType.PICTURE:
await this.parsePicture(blockHeader.length);
return
return;
default:
this.metadata.addWarning('Unknown block type: ' + blockHeader.type);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ export class FlacParser extends AbstractID3Parser {
const decoder = new VorbisDecoder(data, 0);
decoder.readStringUtf8(); // vendor (skip)
const commentListLength = decoder.readInt32();
const tags = new Array(commentListLength)
const tags = new Array(commentListLength);
for (let i = 0; i < commentListLength; i++) {
tags[i] = decoder.parseUserComment();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/id3v2/ID3v2Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class ID3v2Parser {
for (const tag of this.parseMetadata(uint8Array)) {
if (tag.id === 'TXXX') {
if (tag.value) {
await Promise.all(tag.value.text.map((text) =>
await Promise.all(tag.value.text.map(text =>
this.addTag(ID3v2Parser.makeDescriptionTagName(tag.id, tag.value.description), text)
));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/matroska/MatroskaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ export class MatroskaParser extends BasicParser {
}

if (matroska.segment.tags) {
await Promise.all(matroska.segment.tags.tag.map(async (tag) => {
await Promise.all(matroska.segment.tags.tag.map(async tag => {
const target = tag.target;
const targetType = target?.targetTypeValue ? TargetType[target.targetTypeValue] : (target?.targetType ? target.targetType : 'track');
await Promise.all(tag.simpleTags.map(async (simpleTag) => {
await Promise.all(tag.simpleTags.map(async simpleTag => {
const value = simpleTag.string ? simpleTag.string : simpleTag.binary;
await this.addTag(`${targetType}:${simpleTag.name}`, value);
}));
Expand Down
2 changes: 1 addition & 1 deletion lib/mp4/MP4Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class MP4Parser extends BasicParser {

case 1: // UTF-8: Without any count or NULL terminator
case 18: // Unknown: Found in m4b in combination with a '©gen' tag
await this.addTag(tagKey, dataAtom.value.toString('utf-8'));
await this.addTag(tagKey, dataAtom.value.toString('utf-8'));
break;

case 13: // JPEG
Expand Down
13 changes: 6 additions & 7 deletions lib/ogg/vorbis/Vorbis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ export const IdentificationHeader: IGetToken<IFormatInfo> = {
len: 23,

get: (uint8Array, off): IFormatInfo => {
const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset);
return {
version: dataView.getUint32(off + 0, true),
channelMode: dataView.getUint8(off + 4),
sampleRate: dataView.getUint32(off + 5, true),
bitrateMax: dataView.getUint32(off + 9, true),
bitrateNominal: dataView.getUint32(off + 13, true),
bitrateMin: dataView.getUint32(off + 17, true)
version: Token.UINT32_LE.get(uint8Array, off + 0),
channelMode: Token.UINT8.get(uint8Array, off + 4),
sampleRate: Token.UINT32_LE.get(uint8Array, off + 5),
bitrateMax: Token.UINT32_LE.get(uint8Array, off + 9),
bitrateNominal: Token.UINT32_LE.get(uint8Array, off + 13),
bitrateMin: Token.UINT32_LE.get(uint8Array, off + 17)
};
}
};
2 changes: 1 addition & 1 deletion lib/ogg/vorbis/VorbisParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class VorbisParser implements IPageConsumer {
switch (commonHeader.packetType) {

case 3: // type 3: comment header
return await this.parseUserCommentList(pageData, CommonHeader.len);
return this.parseUserCommentList(pageData, CommonHeader.len);

case 1: // type 1: the identification header
case 5: // type 5: setup header type
Expand Down

0 comments on commit ccae86e

Please sign in to comment.