Skip to content

Commit

Permalink
feat: additional support for ID3v2.2 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
eidoriantan committed Feb 15, 2024
1 parent cceb4e5 commit 726f15d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 3 deletions.
140 changes: 140 additions & 0 deletions src/id3v2/frames.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -831,3 +831,143 @@ export const TOR = {
write: writers.win1251Frame,
version: [2]
}

export const TXX = {
parse: parsers.txxxFrame,
validate: validators.txxxFrame,
write: writers.txxxFrame,
version: [2]
}

export const WAF = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WAR = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WAS = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WCM = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WCP = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WPB = {
parse: parsers.urlFrame,
validate: validators.urlFrame,
write: writers.urlFrame,
version: [2]
}

export const WXX = {
parse: parsers.wxxxFrame,
validate: validators.wxxxFrame,
write: writers.wxxxFrame,
version: [2]
}

export const IPL = {
parse: parsers.iplsFrame,
validate: validators.textFrame,
write: writers.iplsFrame,
version: [2]
}

export const MCI = {
parse: parsers.mcdiFrame,
validate: validators.mcdiFrame,
write: writers.mcdiFrame,
version: [2]
}

export const ETC = {
parse: parsers.etcoFrame,
validate: validators.etcoFrame,
write: writers.etcoFrame,
version: [2]
}

export const STC = {
parse: parsers.sytcFrame,
validate: validators.sytcFrame,
write: writers.sytcFrame,
version: [2]
}

export const ULT = {
parse: parsers.langDescFrame,
validate: validators.langDescFrame,
write: writers.langDescFrame,
version: [2]
}

export const SLT = {
parse: parsers.syltFrame,
validate: validators.syltFrame,
write: writers.syltFrame,
version: [2]
}

export const COM = {
parse: parsers.langDescFrame,
validate: validators.langDescFrame,
write: writers.langDescFrame,
version: [2]
}

export const RVA = {
parse: parsers.rvadFrame,
validate: validators.rvadFrame,
write: writers.rvadFrame,
version: [2]
}

export const PIC = {
parse: parsers.apicFrame,
validate: validators.apicFrame,
write: writers.apicFrame,
version: [2]
}

export const GEO = {
parse: parsers.geobFrame,
validate: validators.geobFrame,
write: writers.geobFrame,
version: [2]
}

export const CNT = {
parse: parsers.pcntFrame,
validate: validators.pcntFrame,
write: writers.pcntFrame,
version: [2]
}

export const POP = {
parse: parsers.popmFrame,
validate: validators.popmFrame,
write: writers.popmFrame,
version: [2]
}
2 changes: 1 addition & 1 deletion src/id3v2/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function setFrame (buffer, version) {
const encoding = ENCODINGS[view.getUint8(0)]
const len = view.byteLength - 1

return version === 3
return version === 3 || version === 2
? view.getCString(1, encoding).string
: view.getString(1, len, encoding).string.replace(/\0/g, '\\\\')
}
Expand Down
12 changes: 10 additions & 2 deletions src/id3v2/write.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function win1251Frame (value, options) {
let strBytes = []

switch (version) {
case 2:
case 3:
strBytes = encodeString(value.replace(/\\\\/g, '/') + '\0')
break
Expand All @@ -107,7 +108,7 @@ export function win1251Frame (value, options) {

export function setFrame (value, options) {
const { version } = options
if (version === 3) value = value.toString().split('\\\\')[0]
if (version === 2 || version === 3) value = value.toString().split('\\\\')[0]
else if (version === 4) value = value.toString().replace(/\\\\/g, '\0')

return win1251Frame(value, options)
Expand Down Expand Up @@ -135,6 +136,7 @@ export function txxxFrame (values, options) {
let descBytes, strBytes

switch (version) {
case 2:
case 3:
encoding = 1
descBytes = encodeString(txxx.description + '\0', 'utf-16')
Expand Down Expand Up @@ -172,6 +174,7 @@ export function wxxxFrame (values, options) {
let descBytes, strBytes

switch (version) {
case 2:
case 3:
encoding = 1
descBytes = encodeString(wxxx.description + '\0', 'utf-16')
Expand Down Expand Up @@ -215,6 +218,7 @@ export function langDescFrame (values, options) {
let descBytes, textBytes

switch (version) {
case 2:
case 3:
encoding = 1
descBytes = encodeString(langDesc.descriptor + '\0', 'utf-16')
Expand Down Expand Up @@ -254,6 +258,7 @@ export function apicFrame (values, options) {
let strBytes = []

switch (version) {
case 2:
case 3:
encoding = 1
strBytes = encodeString(apic.description + '\0', 'utf-16')
Expand Down Expand Up @@ -290,6 +295,7 @@ export function geobFrame (values, options) {
let encoding, filename, description

switch (version) {
case 2:
case 3:
encoding = 1
filename = encodeString(geob.filename + '\0', 'utf-16')
Expand Down Expand Up @@ -350,6 +356,7 @@ export function userFrame (value, options) {
let textBytes

switch (version) {
case 2:
case 3:
encoding = 1
textBytes = encodeString(value.text + '\0', 'utf-16')
Expand Down Expand Up @@ -384,6 +391,7 @@ export function owneFrame (value, options) {
let sellerBytes

switch (version) {
case 2:
case 3:
encoding = 1
sellerBytes = encodeString(value.seller, 'utf-16')
Expand Down Expand Up @@ -579,7 +587,7 @@ function parseLyrics (lyrics, encodingString) {
export function syltFrame (values, options) {
const { id, version, unsynch } = options
const bytes = []
const encoding = version === 3 ? 1 : version === 4 ? 3 : 0
const encoding = version === 3 || version === 2 ? 1 : version === 4 ? 3 : 0
const encodingString = ENCODINGS[encoding]

values.forEach(sylt => {
Expand Down

0 comments on commit 726f15d

Please sign in to comment.