Switch to async-await in getTrackNameFromMediaTags
This commit is contained in:
parent
a98c084044
commit
468e512f94
|
@ -244,36 +244,24 @@ export const WireformatDict: { [k: string]: Wireformat } = {
|
|||
async function getTrackNameFromMediaTags(file: File, titleFormat: TitleFormatType) {
|
||||
const fileData = await file.arrayBuffer();
|
||||
const blob = new Blob([new Uint8Array(fileData)]);
|
||||
return await new Promise<string>(async (resolve, reject) => {
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await mm.parseBlob(blob);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
let metadata = await mm.parseBlob(blob);
|
||||
const title = metadata.common.title ?? 'Unknown Title';
|
||||
const artist = metadata.common.artist ?? 'Unknown Artist';
|
||||
const album = metadata.common.album ?? 'Unknown Album';
|
||||
switch (titleFormat) {
|
||||
case 'title': {
|
||||
resolve(title);
|
||||
break;
|
||||
return title;
|
||||
}
|
||||
case 'artist-title': {
|
||||
resolve(`${artist} - ${title}`);
|
||||
break;
|
||||
return `${artist} - ${title}`;
|
||||
}
|
||||
case 'album-title': {
|
||||
resolve(`${album} - ${title}`);
|
||||
break;
|
||||
return `${album} - ${title}`;
|
||||
}
|
||||
case 'artist-album-title': {
|
||||
resolve(`${artist} - ${album} - ${title}`);
|
||||
break;
|
||||
return `${artist} - ${album} - ${title}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function convertAndUpload(files: File[], format: string, titleSource: TitleSourceType, titleFormat: TitleFormatType) {
|
||||
|
@ -370,7 +358,7 @@ export function convertAndUpload(files: File[], format: string, titleSource: Tit
|
|||
let title = file.name;
|
||||
if (titleSource === 'media') {
|
||||
try {
|
||||
title = await getTrackNameFromMediaTags(file, titleFormat);
|
||||
title = (await getTrackNameFromMediaTags(file, titleFormat)) ?? file.name;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue