taglib-wasm
Version:
TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers
583 lines (582 loc) • 14.4 kB
JavaScript
const PROPERTIES = {
// Basic Properties
TITLE: {
key: "TITLE",
description: "The title of the track",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TIT2" },
vorbis: "TITLE",
mp4: "\xA9nam",
wav: "INAM"
}
},
ARTIST: {
key: "ARTIST",
description: "The primary performer(s) of the track",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TPE1" },
vorbis: "ARTIST",
mp4: "\xA9ART",
wav: "IART"
}
},
ALBUM: {
key: "ALBUM",
description: "The album/collection name",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TALB" },
vorbis: "ALBUM",
mp4: "\xA9alb",
wav: "IPRD"
}
},
DATE: {
key: "DATE",
description: "The date of recording (typically year)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TDRC" },
vorbis: "DATE",
mp4: "\xA9day",
wav: "ICRD"
}
},
TRACKNUMBER: {
key: "TRACKNUMBER",
description: "The track number within the album",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TRCK" },
vorbis: "TRACKNUMBER",
mp4: "trkn",
wav: "ITRK"
}
},
GENRE: {
key: "GENRE",
description: "The musical genre",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "TCON" },
vorbis: "GENRE",
mp4: "\xA9gen",
wav: "IGNR"
}
},
COMMENT: {
key: "COMMENT",
description: "Comments or notes about the track",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis", "WAV"],
mappings: {
id3v2: { frame: "COMM" },
vorbis: "COMMENT",
mp4: "\xA9cmt",
wav: "ICMT"
}
},
// Extended Properties
ALBUMARTIST: {
key: "ALBUMARTIST",
description: "The album artist (band/orchestra/ensemble)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TPE2" },
vorbis: "ALBUMARTIST",
mp4: "aART"
}
},
COMPOSER: {
key: "COMPOSER",
description: "The original composer(s) of the track",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TCOM" },
vorbis: "COMPOSER",
mp4: "\xA9wrt"
}
},
COPYRIGHT: {
key: "COPYRIGHT",
description: "Copyright information",
type: "string",
supportedFormats: ["ID3v2", "Vorbis"],
mappings: {
vorbis: "COPYRIGHT"
}
},
ENCODEDBY: {
key: "ENCODEDBY",
description: "The encoding software or person",
type: "string",
supportedFormats: ["ID3v2", "Vorbis"],
mappings: {
vorbis: "ENCODEDBY"
}
},
DISCNUMBER: {
key: "DISCNUMBER",
description: "The disc number for multi-disc sets",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TPOS" },
vorbis: "DISCNUMBER",
mp4: "disk"
}
},
BPM: {
key: "BPM",
description: "Beats per minute",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TBPM" },
vorbis: "BPM",
mp4: "tmpo"
}
},
// Sorting Properties
TITLESORT: {
key: "TITLESORT",
description: "Sort name for title (for alphabetization)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TSOT" },
vorbis: "TITLESORT",
mp4: "sonm"
}
},
ARTISTSORT: {
key: "ARTISTSORT",
description: "Sort name for artist (for alphabetization)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TSOP" },
vorbis: "ARTISTSORT",
mp4: "soar"
}
},
ALBUMSORT: {
key: "ALBUMSORT",
description: "Sort name for album (for alphabetization)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TSOA" },
vorbis: "ALBUMSORT",
mp4: "soal"
}
},
// MusicBrainz Identifiers
MUSICBRAINZ_ARTISTID: {
key: "MUSICBRAINZ_ARTISTID",
description: "MusicBrainz Artist ID (UUID)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "MusicBrainz Artist Id" },
vorbis: "MUSICBRAINZ_ARTISTID",
mp4: "----:com.apple.iTunes:MusicBrainz Artist Id"
}
},
MUSICBRAINZ_ALBUMID: {
key: "MUSICBRAINZ_ALBUMID",
description: "MusicBrainz Release ID (UUID)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "MusicBrainz Album Id" },
vorbis: "MUSICBRAINZ_ALBUMID",
mp4: "----:com.apple.iTunes:MusicBrainz Album Id"
}
},
MUSICBRAINZ_TRACKID: {
key: "MUSICBRAINZ_TRACKID",
description: "MusicBrainz Recording ID (UUID)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "UFID", description: "http://musicbrainz.org" },
vorbis: "MUSICBRAINZ_TRACKID",
mp4: "----:com.apple.iTunes:MusicBrainz Track Id"
}
},
MUSICBRAINZ_RELEASEGROUPID: {
key: "MUSICBRAINZ_RELEASEGROUPID",
description: "MusicBrainz Release Group ID (UUID)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "MusicBrainz Release Group Id" },
vorbis: "MUSICBRAINZ_RELEASEGROUPID",
mp4: "----:com.apple.iTunes:MusicBrainz Release Group Id"
}
},
// ReplayGain Properties
REPLAYGAIN_TRACK_GAIN: {
key: "REPLAYGAIN_TRACK_GAIN",
description: "ReplayGain track gain in dB (e.g., '-6.54 dB')",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Gain" },
vorbis: "REPLAYGAIN_TRACK_GAIN",
mp4: "----:com.apple.iTunes:replaygain_track_gain"
}
},
REPLAYGAIN_TRACK_PEAK: {
key: "REPLAYGAIN_TRACK_PEAK",
description: "ReplayGain track peak value (0.0-1.0)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "ReplayGain_Track_Peak" },
vorbis: "REPLAYGAIN_TRACK_PEAK",
mp4: "----:com.apple.iTunes:replaygain_track_peak"
}
},
REPLAYGAIN_ALBUM_GAIN: {
key: "REPLAYGAIN_ALBUM_GAIN",
description: "ReplayGain album gain in dB",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Gain" },
vorbis: "REPLAYGAIN_ALBUM_GAIN",
mp4: "----:com.apple.iTunes:replaygain_album_gain"
}
},
REPLAYGAIN_ALBUM_PEAK: {
key: "REPLAYGAIN_ALBUM_PEAK",
description: "ReplayGain album peak value (0.0-1.0)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "ReplayGain_Album_Peak" },
vorbis: "REPLAYGAIN_ALBUM_PEAK",
mp4: "----:com.apple.iTunes:replaygain_album_peak"
}
},
// AcoustID Properties
ACOUSTID_FINGERPRINT: {
key: "ACOUSTID_FINGERPRINT",
description: "AcoustID fingerprint (Chromaprint)",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "Acoustid Fingerprint" },
vorbis: "ACOUSTID_FINGERPRINT",
mp4: "----:com.apple.iTunes:Acoustid Fingerprint"
}
},
ACOUSTID_ID: {
key: "ACOUSTID_ID",
description: "AcoustID UUID",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "Acoustid Id" },
vorbis: "ACOUSTID_ID",
mp4: "----:com.apple.iTunes:Acoustid Id"
}
},
// Apple Sound Check
ITUNNORM: {
key: "ITUNNORM",
description: "Apple Sound Check normalization data",
type: "string",
supportedFormats: ["ID3v2", "MP4", "Vorbis"],
mappings: {
id3v2: { frame: "TXXX", description: "iTunNORM" },
vorbis: "ITUNNORM",
mp4: "----:com.apple.iTunes:iTunNORM"
}
},
// Additional common properties from existing Tags
LYRICIST: {
key: "LYRICIST",
description: "The lyrics/text writer(s)",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "LYRICIST"
}
},
CONDUCTOR: {
key: "CONDUCTOR",
description: "The conductor",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "CONDUCTOR"
}
},
REMIXEDBY: {
key: "REMIXEDBY",
description: "Person who remixed the track",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "REMIXEDBY"
}
},
LANGUAGE: {
key: "LANGUAGE",
description: "Language of vocals/lyrics",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "LANGUAGE"
}
},
PUBLISHER: {
key: "PUBLISHER",
description: "The publisher",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "PUBLISHER"
}
},
MOOD: {
key: "MOOD",
description: "The mood/atmosphere of the track",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "MOOD"
}
},
MEDIA: {
key: "MEDIA",
description: "Media type (CD, vinyl, etc.)",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "MEDIA"
}
},
GROUPING: {
key: "GROUPING",
description: "Content group/work",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "GROUPING"
}
},
WORK: {
key: "WORK",
description: "Work name",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "WORK"
}
},
LYRICS: {
key: "LYRICS",
description: "Lyrics content",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "LYRICS"
}
},
ISRC: {
key: "ISRC",
description: "International Standard Recording Code",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "ISRC"
}
},
CATALOGNUMBER: {
key: "CATALOGNUMBER",
description: "Catalog number",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "CATALOGNUMBER"
}
},
BARCODE: {
key: "BARCODE",
description: "Barcode (EAN/UPC)",
type: "string",
supportedFormats: ["Vorbis"],
mappings: {
vorbis: "BARCODE"
}
}
};
const Tags = {
// Basic Properties
Title: "TITLE",
Artist: "ARTIST",
Album: "ALBUM",
Date: "DATE",
TrackNumber: "TRACKNUMBER",
Genre: "GENRE",
Comment: "COMMENT",
// Extended Properties
AlbumArtist: "ALBUMARTIST",
Composer: "COMPOSER",
Copyright: "COPYRIGHT",
EncodedBy: "ENCODEDBY",
DiscNumber: "DISCNUMBER",
Bpm: "BPM",
Lyricist: "LYRICIST",
Conductor: "CONDUCTOR",
Remixer: "REMIXEDBY",
Language: "LANGUAGE",
Publisher: "PUBLISHER",
Mood: "MOOD",
Media: "MEDIA",
RadioStationOwner: "RADIOSTATIONOWNER",
Producer: "PRODUCER",
Subtitle: "SUBTITLE",
Label: "LABEL",
// Sorting Properties
TitleSort: "TITLESORT",
ArtistSort: "ARTISTSORT",
AlbumArtistSort: "ALBUMARTISTSORT",
AlbumSort: "ALBUMSORT",
ComposerSort: "COMPOSERSORT",
// Identifiers
Isrc: "ISRC",
Asin: "ASIN",
CatalogNumber: "CATALOGNUMBER",
Barcode: "BARCODE",
// MusicBrainz Identifiers
MusicBrainzArtistId: "MUSICBRAINZ_ARTISTID",
MusicBrainzReleaseArtistId: "MUSICBRAINZ_ALBUMARTISTID",
MusicBrainzWorkId: "MUSICBRAINZ_WORKID",
MusicBrainzReleaseId: "MUSICBRAINZ_ALBUMID",
MusicBrainzRecordingId: "MUSICBRAINZ_TRACKID",
MusicBrainzTrackId: "MUSICBRAINZ_TRACKID",
MusicBrainzReleaseGroupId: "MUSICBRAINZ_RELEASEGROUPID",
MusicBrainzReleaseTrackId: "MUSICBRAINZ_RELEASETRACKID",
// Podcast Properties
PodcastId: "PODCASTID",
PodcastUrl: "PODCASTURL",
// Grouping and Work
Grouping: "GROUPING",
Work: "WORK",
// Additional Metadata
Lyrics: "LYRICS",
AlbumGain: "REPLAYGAIN_ALBUM_GAIN",
AlbumPeak: "REPLAYGAIN_ALBUM_PEAK",
TrackGain: "REPLAYGAIN_TRACK_GAIN",
TrackPeak: "REPLAYGAIN_TRACK_PEAK",
// Special handling
OriginalArtist: "ORIGINALARTIST",
OriginalAlbum: "ORIGINALALBUM",
OriginalDate: "ORIGINALDATE",
Script: "SCRIPT",
InvolvedPeopleList: "INVOLVEDPEOPLELIST",
// Technical Properties
EncoderSettings: "ENCODERSETTINGS",
SourceMedia: "SOURCEMEDIA"
};
function isValidProperty(key) {
return key in PROPERTIES;
}
function getPropertyMetadata(key) {
return PROPERTIES[key];
}
function getAllPropertyKeys() {
return Object.keys(PROPERTIES);
}
function getAllProperties() {
return Object.entries(PROPERTIES);
}
function getPropertiesByFormat(format) {
return getAllPropertyKeys().filter(
(key) => PROPERTIES[key].supportedFormats.includes(format)
);
}
function isValidTagName(name) {
return Object.values(Tags).includes(name);
}
function getAllTagNames() {
return Object.values(Tags);
}
const FormatMappings = {
Title: {
id3v2: "TIT2",
mp4: "\xA9nam",
vorbis: "TITLE",
ape: "Title",
riff: "INAM"
},
Artist: {
id3v2: "TPE1",
mp4: "\xA9ART",
vorbis: "ARTIST",
ape: "Artist",
riff: "IART"
},
Album: {
id3v2: "TALB",
mp4: "\xA9alb",
vorbis: "ALBUM",
ape: "Album",
riff: "IPRD"
},
Date: {
id3v2: "TDRC",
mp4: "\xA9day",
vorbis: "DATE",
ape: "Year",
riff: "ICRD"
},
Genre: {
id3v2: "TCON",
mp4: "\xA9gen",
vorbis: "GENRE",
ape: "Genre",
riff: "IGNR"
},
Comment: {
id3v2: "COMM",
mp4: "\xA9cmt",
vorbis: "COMMENT",
ape: "Comment",
riff: "ICMT"
},
TrackNumber: {
id3v2: "TRCK",
mp4: "trkn",
vorbis: "TRACKNUMBER",
ape: "Track",
riff: "ITRK"
}
};
export {
FormatMappings,
PROPERTIES,
Tags,
getAllProperties,
getAllPropertyKeys,
getAllTagNames,
getPropertiesByFormat,
getPropertyMetadata,
isValidProperty,
isValidTagName
};