UNPKG

taglib-wasm

Version:

TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps

63 lines (62 loc) 1.91 kB
import { mapPropertiesToExtendedTag } from "../utils/tag-mapping.js"; async function processBatch(files, processor, concurrency) { const results = []; for (let i = 0; i < files.length; i += concurrency) { const chunk = files.slice(i, i + concurrency); const chunkResults = await Promise.all( chunk.map((file) => processor(file)) ); results.push(...chunkResults); } return results; } async function processFileWithTagLib(filePath, taglib, includeProperties, onProgress, processed, totalFound) { const audioFile = await taglib.open(filePath); try { const tags = mapPropertiesToExtendedTag(audioFile.properties()); let properties; if (includeProperties) { const props = audioFile.audioProperties(); if (props) { properties = props; } } const pictures = audioFile.getPictures(); const hasCoverArt = pictures.length > 0; const dynamics = {}; const fieldNames = [ "replayGainTrackGain", "replayGainTrackPeak", "replayGainAlbumGain", "replayGainAlbumPeak" ]; for (const field of fieldNames) { const value = audioFile.getProperty(field); if (value) { dynamics[field] = value; } } let appleSoundCheck = audioFile.getProperty("appleSoundCheck"); if (!appleSoundCheck && audioFile.isMP4()) { appleSoundCheck = audioFile.getMP4Item("----:com.apple.iTunes:iTunNORM"); } if (appleSoundCheck) dynamics.appleSoundCheck = appleSoundCheck; if (processed !== void 0 && totalFound !== void 0) { const current = ++processed.count; onProgress?.(current, totalFound, filePath); } return { path: filePath, tags, properties, hasCoverArt, dynamics: Object.keys(dynamics).length > 0 ? dynamics : void 0 }; } finally { audioFile.dispose(); } } export { processBatch, processFileWithTagLib };