From 5c21f459c6b4d624c676f0a9c588a2504314879d Mon Sep 17 00:00:00 2001 From: xhacker-zzz <959220793@qq.com> Date: Mon, 21 Nov 2022 00:33:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=BB=86=E8=8A=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/decrypt/kgm.ts | 3 +-- src/decrypt/qmccache.ts | 2 +- src/decrypt/raw.ts | 2 +- src/decrypt/utils.ts | 9 ++++++--- src/decrypt/xm.ts | 2 +- src/utils/qm_meta.ts | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/decrypt/kgm.ts b/src/decrypt/kgm.ts index 2fd42a7..9ac5ccf 100644 --- a/src/decrypt/kgm.ts +++ b/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)'); } } diff --git a/src/decrypt/qmccache.ts b/src/decrypt/qmccache.ts index 26ebda7..cfa5ba5 100644 --- a/src/decrypt/qmccache.ts +++ b/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, diff --git a/src/decrypt/raw.ts b/src/decrypt/raw.ts index 1ef912a..3ff01ba 100644 --- a/src/decrypt/raw.ts +++ b/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, diff --git a/src/decrypt/utils.ts b/src/decrypt/utils.ts index d58a276..94b7593 100644 --- a/src/decrypt/utils.ts +++ b/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}'`); } } }); diff --git a/src/decrypt/xm.ts b/src/decrypt/xm.ts index 4f64894..1c487cf 100644 --- a/src/decrypt/xm.ts +++ b/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 ? '-' : '_', ); diff --git a/src/utils/qm_meta.ts b/src/utils/qm_meta.ts index 5824e8f..ea31795 100644 --- a/src/utils/qm_meta.ts +++ b/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({