mirror of
https://codeberg.org/armin/noiz.git
synced 2026-09-01 05:50:52 +02:00
feat: scan playtime duration when adding tracks
This commit is contained in:
parent
eb0fc9835e
commit
b4cae8eac2
1 changed files with 16 additions and 2 deletions
18
index.html
18
index.html
|
|
@ -929,6 +929,20 @@ async function readAudioInfo(file) {
|
||||||
} catch {}
|
} catch {}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
async function readDuration(file) {
|
||||||
|
try {
|
||||||
|
const url = URL.createObjectURL(file);
|
||||||
|
const dur = await new Promise((resolve) => {
|
||||||
|
const a = new Audio();
|
||||||
|
a.preload = 'metadata';
|
||||||
|
a.onloadedmetadata = () => { resolve(a.duration); };
|
||||||
|
a.onerror = () => { resolve(0); };
|
||||||
|
a.src = url;
|
||||||
|
});
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
return isFinite(dur) && dur > 0 ? dur : 0;
|
||||||
|
} catch { return 0; }
|
||||||
|
}
|
||||||
async function processFiles(files, paths) {
|
async function processFiles(files, paths) {
|
||||||
scanning.style.display = 'flex';
|
scanning.style.display = 'flex';
|
||||||
const total = files.length;
|
const total = files.length;
|
||||||
|
|
@ -940,7 +954,7 @@ async function processFiles(files, paths) {
|
||||||
prog++;
|
prog++;
|
||||||
const url = URL.createObjectURL(file);
|
const url = URL.createObjectURL(file);
|
||||||
const path = paths ? paths[i] : file.name;
|
const path = paths ? paths[i] : file.name;
|
||||||
const [tags, ainfo] = await Promise.all([readTags(file), readAudioInfo(file)]);
|
const [tags, ainfo, duration] = await Promise.all([readTags(file), readAudioInfo(file), readDuration(file)]);
|
||||||
const name = tags.title || file.name.replace(/\.[^.]+$/, '');
|
const name = tags.title || file.name.replace(/\.[^.]+$/, '');
|
||||||
found.push({
|
found.push({
|
||||||
name,
|
name,
|
||||||
|
|
@ -958,7 +972,7 @@ async function processFiles(files, paths) {
|
||||||
file,
|
file,
|
||||||
path,
|
path,
|
||||||
size: file.size,
|
size: file.size,
|
||||||
playtime: 0,
|
playtime: duration,
|
||||||
ainfo,
|
ainfo,
|
||||||
});
|
});
|
||||||
scanningText.textContent = `Processing ${prog}: ${name}`;
|
scanningText.textContent = `Processing ${prog}: ${name}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue