TelegramPWA/src/util/audio.ts
Alexander Zinchuk c3cc8b634f Message Media: Editing message media (#4202)
Co-authored-by: Alexander Zinchuk <alx.zinchuk@gmail.com>
Co-authored-by: zubiden <19638254+zubiden@users.noreply.github.com>
2024-02-23 14:05:46 +01:00

24 lines
684 B
TypeScript

type AudioMetadata = {
title?: string;
performer?: string;
duration?: number;
coverUrl?: string;
};
export async function parseAudioMetadata(url: string): Promise<AudioMetadata> {
const { fetchFromUrl, selectCover } = await import('../lib/music-metadata-browser');
const metadata = await fetchFromUrl(url);
const { common: { title, artist, picture }, format: { duration } } = metadata;
const cover = selectCover(picture);
const coverBlob = cover ? new Blob([cover.data], { type: cover.format }) : undefined;
const coverUrl = coverBlob ? URL.createObjectURL(coverBlob) : undefined;
return {
title,
performer: artist,
duration,
coverUrl,
};
}