@infinito/id3
Version:
ID3 Tag Reader/Writer
33 lines (31 loc) • 1.09 kB
JavaScript
import getID3v2_2 from './get/id3.2.2.js';
import getID3v2_3 from './get/id3.2.3.js';
import getID3v2_4 from './get/id3.2.4.js';
import validID3 from './valid.js';
export default function getID3(path,buf) {
if(typeof path!='string') {
throw new TypeError('parameter path expects a string');
}
if(!(buf instanceof Uint8Array)) {
throw new TypeError('parameter buf expects a Uint8Array buffer');
}
/* Detect which id3 tag to find, prefer id3v2.3 */
try {
var taginfo = validID3(buf.buffer);
} catch(error) {
throw new Error(`${path} does not contain valid id3 tags`);
}
switch(taginfo.ver) {
case 4:
return getID3v2_4(path,buf.buffer,taginfo.subver,taginfo.flags,taginfo.size);
case 3:
return getID3v2_3(path,buf.buffer,taginfo.subver,taginfo.flags,taginfo.size);
case 2:
return getID3v2_2(path,buf.buffer,taginfo.subver,taginfo.flags,taginfo.size);
default:
console.log(path);
console.log(taginfo);
console.log(new Uint8Array(buf,0,20));
throw new Error("id3v"+taginfo.ver+"."+taginfo.subver+" not supported");
}
}