forked from um/web
Fix #77 ncm flac meta duplicated
Fix #78 write flac cover sometimes fail
This commit is contained in:
parent
c9a4a901be
commit
4aa2ff7f91
@ -58,6 +58,6 @@ export async function CommonDecrypt(file) {
|
||||
|
||||
if (!rt_data.rawExt) rt_data.rawExt = raw_ext;
|
||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw_filename;
|
||||
|
||||
console.log(rt_data);
|
||||
return rt_data;
|
||||
}
|
||||
|
@ -39,25 +39,30 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
if (artists.length === 0) artists.push(info.artist);
|
||||
|
||||
if (musicMeta.format === undefined) musicMeta.format = DetectAudioExt(audioData, "mp3");
|
||||
console.log(musicMeta)
|
||||
|
||||
const imageInfo = await GetWebImage(musicMeta.albumPic);
|
||||
if (musicMeta.format === "mp3") {
|
||||
audioData = await WriteMp3Meta(
|
||||
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic);
|
||||
} else if (musicMeta.format === "flac") {
|
||||
const writer = new MetaFlac(Buffer.from(audioData))
|
||||
writer.setTag("TITLE=" + info.title);
|
||||
writer.setTag("ALBUM=" + musicMeta.album);
|
||||
artists.forEach(artist => writer.setTag("ARTIST=" + artist));
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
audioData = writer.save()
|
||||
}
|
||||
console.log(imageInfo)
|
||||
try {
|
||||
if (musicMeta.format === "mp3") {
|
||||
audioData = await WriteMp3Meta(
|
||||
audioData, artists, info.title, musicMeta.album, imageInfo.buffer, musicMeta.albumPic);
|
||||
} else if (musicMeta.format === "flac") {
|
||||
const writer = new MetaFlac(Buffer.from(audioData))
|
||||
//writer.setTag("TITLE=" + info.title);
|
||||
//writer.setTag("ALBUM=" + musicMeta.album);
|
||||
//artists.forEach(artist => writer.setTag("ARTIST=" + artist));
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
audioData = writer.save()
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
|
||||
const mime = AudioMimeType[musicMeta.format];
|
||||
const musicData = new Blob([audioData], {type: mime});
|
||||
|
||||
let x = {
|
||||
return {
|
||||
status: true,
|
||||
title: info.title,
|
||||
artist: info.artist,
|
||||
@ -67,8 +72,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
file: URL.createObjectURL(musicData),
|
||||
mime: mime
|
||||
};
|
||||
console.log(x)
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,6 +60,7 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||
for (let metaIdx in musicMeta.native) {
|
||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
||||
console.log("The metadata is using gbk encoding")
|
||||
musicMeta.common.artist = decode(musicMeta.common.artist, "gbk");
|
||||
musicMeta.common.title = decode(musicMeta.common.title, "gbk");
|
||||
musicMeta.common.album = decode(musicMeta.common.album, "gbk");
|
||||
@ -77,21 +78,25 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
||||
const imageInfo = await GetWebImage(imgUrl);
|
||||
if (imageInfo.url !== "") {
|
||||
imgUrl = imageInfo.url
|
||||
if (ext === "mp3") {
|
||||
let writer = new ID3Writer(musicDecoded)
|
||||
writer.setFrame('APIC', {
|
||||
type: 3,
|
||||
data: imageInfo.buffer,
|
||||
description: "Cover",
|
||||
})
|
||||
writer.addTag();
|
||||
musicDecoded = writer.arrayBuffer
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
const writer = new MetaFlac(Buffer.from(musicDecoded))
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
musicDecoded = writer.save()
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
try {
|
||||
if (ext === "mp3") {
|
||||
let writer = new ID3Writer(musicDecoded)
|
||||
writer.setFrame('APIC', {
|
||||
type: 3,
|
||||
data: imageInfo.buffer,
|
||||
description: "Cover",
|
||||
})
|
||||
writer.addTag();
|
||||
musicDecoded = writer.arrayBuffer
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
} else if (ext === 'flac') {
|
||||
const writer = new MetaFlac(Buffer.from(musicDecoded))
|
||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||
musicDecoded = writer.save()
|
||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error while appending cover image to file " + e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user