Skip to content
Merged
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 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module.exports = {
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "warn",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unsafe-enum-comparison": "error",
Comment thread
benrr101 marked this conversation as resolved.
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/restrict-template-expressions": 0,
"@typescript-eslint/triple-slash-reference": [
Expand Down
229 changes: 190 additions & 39 deletions src/id3v2/utilTypes.ts → src/id3v2/enums.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,51 @@
/**
* Specifies the type of text contained in a synchronized lyrics frame
* Type of channel data to get from or set to a {@link RelativeVolumeFrame} object
*/
export enum SynchronizedTextType {
export enum ChannelType {
/**
* Text is some other type of text
* Channel data for some other speaker
*/
Other = 0x00,

/**
* Text contains lyrical data
* Channel data for the master volume
*/
Lyrics = 0x01,
MasterVolume = 0x01,

/**
* Text contains a transcription
* Channel data for the front right speaker
*/
TextTranscription = 0x02,
FrontRight = 0x02,

/**
* Text lists the movements in the piece
* Channel data for front left speaker
*/
Movement = 0x03,
FrontLeft = 0x03,

/**
* Text describes events that occur
* Channel data for center right speaker
*/
Events = 0x04,
BackRight = 0x04,

/**
* Text contains chord changes that occur in the music
* Channel data for back left speaker
*/
Chord = 0x05,
BackLeft = 0x05,

/**
* Text contains trivia or "pop up" information about the media
* Channel data for front center speaker
*/
Trivia = 0x06,
FrontCentre = 0x06,

/**
* Text contains URLs for relevant webpages
* Channel data for back center speaker
*/
WebpageUrls = 0x07,
BackCenter = 0x07,

/**
* Text contains URLs for relevant images
* Channel data for subwoofer
*/
ImageUrls = 0x08
}

/**
* Specifies the timestamp format used by a few frame types.
*/
export enum TimestampFormat {
/**
* Timestamp is of unknown format
*/
Unknown = 0x00,

/**
* Timestamp represents the number of MPEG frames since the beginning of the audio stream
*/
AbsoluteMpegFrames = 0x01,

/**
* Timestamp represents the number of milliseconds since the beginning of the audio stream
*/
AbsoluteMilliseconds = 0x02
Subwoofer = 0x08
}

/**
Expand Down Expand Up @@ -197,3 +177,174 @@ export enum EventType {
*/
AudioFileEnd = 0xFE
}

/**
* Indicates the flags applied to a {@link Id3v2FrameHeader} object.
*/
export enum FrameFlags {
/**
* Header contains no flags.
*/
None = 0,

/**
* Frame is to be deleted if the tag is altered.
*/
TagAlterPreservation = 0x4000,

/**
* Frame is to be deleted if the file is altered.
*/
FileAlterPreservation = 0x2000,

/**
* Frame is read-only and should not be altered.
*/
ReadOnly = 0x1000,

/**
* Frame has a grouping identity.
*/
GroupingIdentity = 0x0040,

/**
* Frame data is compressed.
*/
Compression = 0x0008,

/**
* Frame data is encrypted.
*/
Encryption = 0x0004,

/**
* Frame data has been unsynchronized using the ID3v2 unsynchronization scheme.
*/
Unsynchronized = 0x0002,

/**
* Frame has a data length indicator.
*/
DataLengthIndicator = 0x0001
}

/**
* Indicates the flags applied to a {@link Id3v2TagHeader} object.
*/
export enum TagFlags {
/**
* The header contains no flags.
*/
None = 0x0,

/**
* The tag described by the header contains a footer.
*/
FooterPresent = 0x10,

/**
* The tag described by the header is experimental.
*/
ExperimentalIndicator = 0x20,

/**
* The tag described by the header contains an extended header.
*/
ExtendedHeader = 0x40,

/**
* The tag described by the header has been unsynchronized using the ID3v2 unsynchronization
* scheme.
*/
Unsynchronization = 0x80,
}

/**
* Indicates a major version of ID3v2.
*/
export enum Id3v2Version {
/**
* Indicates the ID3v2.2 version.
*/
V22 = 2,

/**
* Indicates the ID3v2.3 version.
*/
V23 = 3,

/**
* Indicates the ID3v2.4 version.
*/
V24 = 4
}

/**
* Specifies the type of text contained in a synchronized lyrics frame
*/
export enum SynchronizedTextType {
/**
* Text is some other type of text
*/
Other = 0x00,

/**
* Text contains lyrical data
*/
Lyrics = 0x01,

/**
* Text contains a transcription
*/
TextTranscription = 0x02,

/**
* Text lists the movements in the piece
*/
Movement = 0x03,

/**
* Text describes events that occur
*/
Events = 0x04,

/**
* Text contains chord changes that occur in the music
*/
Chord = 0x05,

/**
* Text contains trivia or "pop up" information about the media
*/
Trivia = 0x06,

/**
* Text contains URLs for relevant webpages
*/
WebpageUrls = 0x07,

/**
* Text contains URLs for relevant images
*/
ImageUrls = 0x08
}

/**
* Specifies the timestamp format used by a few frame types.
*/
export enum TimestampFormat {
/**
* Timestamp is of unknown format
*/
Unknown = 0x00,

/**
* Timestamp represents the number of MPEG frames since the beginning of the audio stream
*/
AbsoluteMpegFrames = 0x01,

/**
* Timestamp represents the number of milliseconds since the beginning of the audio stream
*/
AbsoluteMilliseconds = 0x02
}
11 changes: 5 additions & 6 deletions src/id3v2/frameIdentifiers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ByteVector, StringType} from "../byteVector";
import {NotSupportedError} from "../errors";
import {Id3v2Version} from "./enums";

/**
* Represents the identifier of a frame, depending on the version this may be 3 or 4
Expand Down Expand Up @@ -75,20 +76,18 @@ export class FrameIdentifier {
* @throws NotSupportedError Thrown if the frame identifier does not contain a string for the
* provided ID3v2 version.
*/
public render(version: number): ByteVector {
public render(version: Id3v2Version): ByteVector {
let bytesForVersion;
switch (version) {
case 2:
case Id3v2Version.V22:
bytesForVersion = this._version2;
break;
case 3:
case Id3v2Version.V23:
bytesForVersion = this._version3;
break;
case 4:
case Id3v2Version.V24:
bytesForVersion = this._version4;
break;
default:
throw new Error("Argument error: version must be a value between 2 and 4");
}

if (!bytesForVersion) {
Expand Down
Loading