Browse Source

修正代码中的细节问题

20230320
xhacker-zzz 2 years ago
parent
commit
5c21f459c6
  1. 3
      src/decrypt/kgm.ts
  2. 2
      src/decrypt/qmccache.ts
  3. 2
      src/decrypt/raw.ts
  4. 9
      src/decrypt/utils.ts
  5. 2
      src/decrypt/xm.ts
  6. 4
      src/utils/qm_meta.ts

3
src/decrypt/kgm.ts

@ -34,12 +34,11 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string)
console.log('kgm: using wasm decoder');
const kgmDecrypted = await DecryptKgmWasm(oriData, raw_ext);
// 若 v2 检测失败,降级到 v1 再尝试一次
if (kgmDecrypted.success) {
musicDecoded = kgmDecrypted.data;
console.log('kgm wasm decoder suceeded');
} else {
console.warn('KgmWasm failed with error %s', kgmDecrypted.error || '(no error)');
console.warn('KgmWasm failed with error %s', kgmDecrypted.error || '(unknown error)');
}
}

2
src/decrypt/qmccache.ts

@ -54,7 +54,7 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string)
throw '不支持的QQ音乐缓存格式';
}
const tag = await metaParseBlob(audioBlob);
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artists == undefined ? tag.common.artist : tag.common.artists.toString());
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, String(tag.common.artists || tag.common.artist));
return {
title,

2
src/decrypt/raw.ts

@ -17,7 +17,7 @@ export async function Decrypt(
if (ext !== raw_ext) file = new Blob([buffer], { type: AudioMimeType[ext] });
}
const tag = await metaParseBlob(file);
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artists == undefined ? tag.common.artist : tag.common.artists.toString());
const { title, artist } = GetMetaFromFile(raw_filename, tag.common.title, String(tag.common.artists || tag.common.artist));
return {
title,

9
src/decrypt/utils.ts

@ -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}'`);
}
}
});

2
src/decrypt/xm.ts

@ -49,7 +49,7 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string)
const { title, artist } = GetMetaFromFile(
raw_filename,
musicMeta.common.title,
musicMeta.common.artists == undefined ? musicMeta.common.artist : musicMeta.common.artists.toString(),
String(musicMeta.common.artists || musicMeta.common.artist),
raw_filename.indexOf('_') === -1 ? '-' : '_',
);

4
src/utils/qm_meta.ts

@ -40,7 +40,7 @@ export async function extractQQMusicMeta(
if (musicMeta.native[metaIdx].some((item) => item.id === 'TCON' && item.value === '(12)')) {
console.warn('try using gbk encoding to decode meta');
musicMeta.common.artist = '';
if (musicMeta.common.artists == undefined) {
if (musicMeta.common.artists) {
musicMeta.common.artist = iconv.decode(new Buffer(musicMeta.common.artist ?? ''), 'gbk');
}
else {
@ -70,7 +70,7 @@ export async function extractQQMusicMeta(
return {
title: info.title,
artist: info.artist || '',
artist: info.artist,
album: musicMeta.common.album || '',
imgUrl: imageURL,
blob: await writeMetaToAudioFile({

Loading…
Cancel
Save