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.rawExt) rt_data.rawExt = raw_ext;
|
||||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw_filename;
|
if (!rt_data.rawFilename) rt_data.rawFilename = raw_filename;
|
||||||
|
console.log(rt_data);
|
||||||
return 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 (artists.length === 0) artists.push(info.artist);
|
||||||
|
|
||||||
if (musicMeta.format === undefined) musicMeta.format = DetectAudioExt(audioData, "mp3");
|
if (musicMeta.format === undefined) musicMeta.format = DetectAudioExt(audioData, "mp3");
|
||||||
|
console.log(musicMeta)
|
||||||
|
|
||||||
const imageInfo = await GetWebImage(musicMeta.albumPic);
|
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)
|
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 mime = AudioMimeType[musicMeta.format];
|
||||||
const musicData = new Blob([audioData], {type: mime});
|
const musicData = new Blob([audioData], {type: mime});
|
||||||
|
|
||||||
let x = {
|
return {
|
||||||
status: true,
|
status: true,
|
||||||
title: info.title,
|
title: info.title,
|
||||||
artist: info.artist,
|
artist: info.artist,
|
||||||
@ -67,8 +72,6 @@ export async function Decrypt(file, raw_filename, raw_ext) {
|
|||||||
file: URL.createObjectURL(musicData),
|
file: URL.createObjectURL(musicData),
|
||||||
mime: mime
|
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);
|
const musicMeta = await musicMetadata.parseBlob(musicBlob);
|
||||||
for (let metaIdx in musicMeta.native) {
|
for (let metaIdx in musicMeta.native) {
|
||||||
if (musicMeta.native[metaIdx].some(item => item.id === "TCON" && item.value === "(12)")) {
|
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.artist = decode(musicMeta.common.artist, "gbk");
|
||||||
musicMeta.common.title = decode(musicMeta.common.title, "gbk");
|
musicMeta.common.title = decode(musicMeta.common.title, "gbk");
|
||||||
musicMeta.common.album = decode(musicMeta.common.album, "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);
|
const imageInfo = await GetWebImage(imgUrl);
|
||||||
if (imageInfo.url !== "") {
|
if (imageInfo.url !== "") {
|
||||||
imgUrl = imageInfo.url
|
imgUrl = imageInfo.url
|
||||||
if (ext === "mp3") {
|
try {
|
||||||
let writer = new ID3Writer(musicDecoded)
|
if (ext === "mp3") {
|
||||||
writer.setFrame('APIC', {
|
let writer = new ID3Writer(musicDecoded)
|
||||||
type: 3,
|
writer.setFrame('APIC', {
|
||||||
data: imageInfo.buffer,
|
type: 3,
|
||||||
description: "Cover",
|
data: imageInfo.buffer,
|
||||||
})
|
description: "Cover",
|
||||||
writer.addTag();
|
})
|
||||||
musicDecoded = writer.arrayBuffer
|
writer.addTag();
|
||||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
musicDecoded = writer.arrayBuffer
|
||||||
} else if (ext === 'flac') {
|
musicBlob = new Blob([musicDecoded], {type: mime});
|
||||||
const writer = new MetaFlac(Buffer.from(musicDecoded))
|
} else if (ext === 'flac') {
|
||||||
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
const writer = new MetaFlac(Buffer.from(musicDecoded))
|
||||||
musicDecoded = writer.save()
|
writer.importPictureFromBuffer(Buffer.from(imageInfo.buffer))
|
||||||
musicBlob = new Blob([musicDecoded], {type: mime});
|
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