|
|
@ -93,6 +93,7 @@ export function GetMetaFromFile( |
|
|
|
|
|
|
|
const items = filename.split(separator); |
|
|
|
if (items.length > 1) { |
|
|
|
//由文件名和原metadata共同决定歌手tag(有时从文件名看有多个歌手,而metadata只有一个)
|
|
|
|
if (!meta.artist || meta.artist.split(split_regex).length < items[0].trim().split(split_regex).length) meta.artist = items[0].trim(); |
|
|
|
if (!meta.title) meta.title = items[1].trim(); |
|
|
|
} else if (items.length === 1) { |
|
|
@ -136,7 +137,9 @@ export function WriteMetaToMp3(audioData: Buffer, info: IMusicMeta, original: IA |
|
|
|
if (frame.id !== 'TPE1' && frame.id !== 'TIT2' && frame.id !== 'TALB') { |
|
|
|
try { |
|
|
|
writer.setFrame(frame.id, frame.value); |
|
|
|
} catch (e) {} |
|
|
|
} catch (e) { |
|
|
|
console.warn(`failed to write ID3 tag '${frame.id}'`); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
@ -176,7 +179,7 @@ export function WriteMetaToFlac(audioData: Buffer, info: IMusicMeta, original: I |
|
|
|
export function RewriteMetaToMp3(audioData: Buffer, info: IMusicMeta, original: IAudioMetadata) { |
|
|
|
const writer = new ID3Writer(audioData); |
|
|
|
|
|
|
|
// reserve original data
|
|
|
|
// preserve original data
|
|
|
|
const frames = original.native['ID3v2.4'] || original.native['ID3v2.3'] || original.native['ID3v2.2'] || []; |
|
|
|
frames.forEach((frame) => { |
|
|
|
if (frame.id !== 'TPE1' |
|
|
@ -188,7 +191,7 @@ export function RewriteMetaToMp3(audioData: Buffer, info: IMusicMeta, original: |
|
|
|
try { |
|
|
|
writer.setFrame(frame.id, frame.value); |
|
|
|
} catch (e) { |
|
|
|
throw new Error('write unknown mp3 frame failed'); |
|
|
|
throw new Error(`failed to write ID3 tag '${frame.id}'`); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|