style: auto-fix linting issues
This commit is contained in:
parent
cddf318d19
commit
60d61f74d2
1 changed files with 15 additions and 19 deletions
|
|
@ -169,7 +169,7 @@ async function readFlacMetadata(file, metadata) {
|
||||||
|
|
||||||
if (streamInfo) {
|
if (streamInfo) {
|
||||||
const offset = streamInfo.offset;
|
const offset = streamInfo.offset;
|
||||||
|
|
||||||
// Sample Rate is 20 bits spanning bytes 10, 11, and the first 4 bits of 12
|
// Sample Rate is 20 bits spanning bytes 10, 11, and the first 4 bits of 12
|
||||||
const byte10 = dataView.getUint8(offset + 10);
|
const byte10 = dataView.getUint8(offset + 10);
|
||||||
const byte11 = dataView.getUint8(offset + 11);
|
const byte11 = dataView.getUint8(offset + 11);
|
||||||
|
|
@ -177,14 +177,14 @@ async function readFlacMetadata(file, metadata) {
|
||||||
|
|
||||||
// since data for some reason spans across multiple bytes, we need to combine them into one int
|
// since data for some reason spans across multiple bytes, we need to combine them into one int
|
||||||
const sampleRate = (byte10 << 12) | (byte11 << 4) | (byte12 >> 4);
|
const sampleRate = (byte10 << 12) | (byte11 << 4) | (byte12 >> 4);
|
||||||
|
|
||||||
const byte13 = dataView.getUint8(offset + 13);
|
const byte13 = dataView.getUint8(offset + 13);
|
||||||
const tsHigh = byte13 & 0x0f;
|
const tsHigh = byte13 & 0x0f;
|
||||||
const tsLow = dataView.getUint32(offset + 14, false);
|
const tsLow = dataView.getUint32(offset + 14, false);
|
||||||
|
|
||||||
// same thing for total samples
|
// same thing for total samples
|
||||||
const totalSamples = (tsHigh * 0x100000000) + tsLow;
|
const totalSamples = tsHigh * 0x100000000 + tsLow;
|
||||||
|
|
||||||
if (sampleRate > 0) {
|
if (sampleRate > 0) {
|
||||||
// beatiful
|
// beatiful
|
||||||
metadata.duration = totalSamples / sampleRate;
|
metadata.duration = totalSamples / sampleRate;
|
||||||
|
|
@ -234,16 +234,15 @@ async function readM4aMetadata(file, metadata) {
|
||||||
const moovData = new DataView(view.buffer, moovStart, moovLen);
|
const moovData = new DataView(view.buffer, moovStart, moovLen);
|
||||||
const moovAtoms = parseMp4Atoms(moovData);
|
const moovAtoms = parseMp4Atoms(moovData);
|
||||||
|
|
||||||
|
|
||||||
// mvhd metadata tag
|
// mvhd metadata tag
|
||||||
const mvhd = moovAtoms.find((a) => a.type === 'mvhd');
|
const mvhd = moovAtoms.find((a) => a.type === 'mvhd');
|
||||||
if (mvhd) {
|
if (mvhd) {
|
||||||
const mvhdStart = moovStart + mvhd.offset + 8;
|
const mvhdStart = moovStart + mvhd.offset + 8;
|
||||||
const version = view.getUint8(mvhdStart);
|
const version = view.getUint8(mvhdStart);
|
||||||
|
|
||||||
// resolution and length, basically
|
// resolution and length, basically
|
||||||
let timeScale, duration;
|
let timeScale, duration;
|
||||||
|
|
||||||
if (version === 0) {
|
if (version === 0) {
|
||||||
// 32-bit format
|
// 32-bit format
|
||||||
timeScale = view.getUint32(mvhdStart + 12, false);
|
timeScale = view.getUint32(mvhdStart + 12, false);
|
||||||
|
|
@ -253,9 +252,9 @@ async function readM4aMetadata(file, metadata) {
|
||||||
timeScale = view.getUint32(mvhdStart + 20, false);
|
timeScale = view.getUint32(mvhdStart + 20, false);
|
||||||
const durHigh = view.getUint32(mvhdStart + 24, false);
|
const durHigh = view.getUint32(mvhdStart + 24, false);
|
||||||
const durLow = view.getUint32(mvhdStart + 28, false);
|
const durLow = view.getUint32(mvhdStart + 28, false);
|
||||||
duration = (durHigh * 0x100000000) + durLow;
|
duration = durHigh * 0x100000000 + durLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeScale > 0) {
|
if (timeScale > 0) {
|
||||||
metadata.duration = duration / timeScale;
|
metadata.duration = duration / timeScale;
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +263,6 @@ async function readM4aMetadata(file, metadata) {
|
||||||
const udta = moovAtoms.find((a) => a.type === 'udta');
|
const udta = moovAtoms.find((a) => a.type === 'udta');
|
||||||
if (!udta) return;
|
if (!udta) return;
|
||||||
|
|
||||||
|
|
||||||
const udtaStart = moovStart + udta.offset + 8;
|
const udtaStart = moovStart + udta.offset + 8;
|
||||||
const udtaLen = udta.size - 8;
|
const udtaLen = udta.size - 8;
|
||||||
const udtaData = new DataView(view.buffer, udtaStart, udtaLen);
|
const udtaData = new DataView(view.buffer, udtaStart, udtaLen);
|
||||||
|
|
@ -422,7 +420,7 @@ async function readMp3Metadata(file, metadata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!metadata.duration || metadata.duration === 0) {
|
if (!metadata.duration || metadata.duration === 0) {
|
||||||
metadata.duration = await calculateMp3Duration(file, tagSize);
|
metadata.duration = await calculateMp3Duration(file, tagSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,7 +452,6 @@ async function readMp3Metadata(file, metadata) {
|
||||||
// since mp3 file don't have metadata about duration, estimating it
|
// since mp3 file don't have metadata about duration, estimating it
|
||||||
// uses evil bitwise magic
|
// uses evil bitwise magic
|
||||||
async function calculateMp3Duration(file, startOffset) {
|
async function calculateMp3Duration(file, startOffset) {
|
||||||
|
|
||||||
const buffer = await file.slice(startOffset, startOffset + 32768).arrayBuffer();
|
const buffer = await file.slice(startOffset, startOffset + 32768).arrayBuffer();
|
||||||
const view = new DataView(buffer);
|
const view = new DataView(buffer);
|
||||||
const uint8 = new Uint8Array(buffer);
|
const uint8 = new Uint8Array(buffer);
|
||||||
|
|
@ -486,12 +483,11 @@ async function calculateMp3Duration(file, startOffset) {
|
||||||
|
|
||||||
// this xing header is present in many mp3 files and contains total frame count, which allows for accurate duration calculation
|
// this xing header is present in many mp3 files and contains total frame count, which allows for accurate duration calculation
|
||||||
const channelMode = (header >> 6) & 3; // mono or stereo
|
const channelMode = (header >> 6) & 3; // mono or stereo
|
||||||
const xingOffset = offset + 4 + (mpegVer === 3 ? (channelMode === 3 ? 17 : 32) : (channelMode === 3 ? 9 : 17)); // the position of xing header
|
const xingOffset = offset + 4 + (mpegVer === 3 ? (channelMode === 3 ? 17 : 32) : channelMode === 3 ? 9 : 17); // the position of xing header
|
||||||
|
|
||||||
if (xingOffset + 8 <= view.byteLength) {
|
if (xingOffset + 8 <= view.byteLength) {
|
||||||
const sig = view.getUint32(xingOffset, false);
|
const sig = view.getUint32(xingOffset, false);
|
||||||
if ((sig === 0x58696e67 || sig === 0x496e666f) && (view.getUint32(xingOffset + 4, false) & 1)) {
|
if ((sig === 0x58696e67 || sig === 0x496e666f) && view.getUint32(xingOffset + 4, false) & 1) {
|
||||||
|
|
||||||
const frames = view.getUint32(xingOffset + 8, false);
|
const frames = view.getUint32(xingOffset + 8, false);
|
||||||
// basically, duration = frames * samples per frame / sample rate
|
// basically, duration = frames * samples per frame / sample rate
|
||||||
return (frames * (mpegVer === 3 ? 1152 : 576)) / sampleRate;
|
return (frames * (mpegVer === 3 ? 1152 : 576)) / sampleRate;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue