From 02a146e0693681eed11eac289a4fdb34ac139b8f Mon Sep 17 00:00:00 2001 From: qq1010903229 <1010903229@qq.com> Date: Thu, 3 Jun 2021 13:00:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E7=BD=91=E6=98=93?= =?UTF-8?q?=E4=BA=91=E9=9F=B3=E4=B9=90.uc=E7=BC=93=E5=AD=98=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=92=8CQQ=E9=9F=B3=E4=B9=90.cache=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=94=AF=E6=8C=81=20(#161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update common.ts * Create ncmcache.ts * Create qmccache.ts --- src/decrypt/common.ts | 8 ++++++++ src/decrypt/ncmcache.ts | 32 ++++++++++++++++++++++++++++++ src/decrypt/qmc.ts | 3 +++ src/decrypt/qmccache.ts | 44 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/decrypt/ncmcache.ts create mode 100644 src/decrypt/qmccache.ts diff --git a/src/decrypt/common.ts b/src/decrypt/common.ts index 6c98892..8e2142d 100644 --- a/src/decrypt/common.ts +++ b/src/decrypt/common.ts @@ -1,6 +1,8 @@ import {Decrypt as NcmDecrypt} from "@/decrypt/ncm"; +import {Decrypt as NcmCacheDecrypt} from "@/decrypt/ncmcache"; import {Decrypt as XmDecrypt} from "@/decrypt/xm"; import {Decrypt as QmcDecrypt} from "@/decrypt/qmc"; +import {Decrypt as QmcCacheDecrypt} from "@/decrypt/qmccache"; import {Decrypt as KgmDecrypt} from "@/decrypt/kgm"; import {Decrypt as KwmDecrypt} from "@/decrypt/kwm"; import {Decrypt as RawDecrypt} from "@/decrypt/raw"; @@ -16,6 +18,9 @@ export async function CommonDecrypt(file: FileInfo): Promise { case "ncm":// Netease Mp3/Flac rt_data = await NcmDecrypt(file.raw, raw_filename, raw_ext); break; + case "uc":// Netease Cache + rt_data = await NcmCacheDecrypt(file.raw, raw_filename, raw_ext); + break; case "kwm":// Kuwo Mp3/Flac rt_data = await KwmDecrypt(file.raw, raw_filename, raw_ext); break @@ -54,6 +59,9 @@ export async function CommonDecrypt(file: FileInfo): Promise { case "tm6":// QQ Music IOS M4a rt_data = await TmDecrypt(file.raw, raw_filename); break; + case "cache"://QQ Music Cache + rt_data = await QmcCacheDecrypt(file.raw, raw_filename, raw_ext); + break; case "vpr": case "kgm": case "kgma": diff --git a/src/decrypt/ncmcache.ts b/src/decrypt/ncmcache.ts new file mode 100644 index 0000000..79db62c --- /dev/null +++ b/src/decrypt/ncmcache.ts @@ -0,0 +1,32 @@ +import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts"; + +import {DecryptResult} from "@/decrypt/entity"; + +import {parseBlob as metaParseBlob} from "music-metadata-browser"; + +export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true) + : Promise { + let ext = raw_ext; + if (detect) { + const buffer = new Uint8Array(await GetArrayBuffer(file)); + let length = buffer.length + for (let i = 0; i < length; i++) { + buffer[i] ^= 163 + } + ext = SniffAudioExt(buffer, raw_ext); + 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.artist) + + return { + title, + artist, + ext, + album: tag.common.album, + picture: GetCoverFromFile(tag), + file: URL.createObjectURL(file), + blob: file, + mime: AudioMimeType[ext] + } +} diff --git a/src/decrypt/qmc.ts b/src/decrypt/qmc.ts index eb22478..2aeb71d 100644 --- a/src/decrypt/qmc.ts +++ b/src/decrypt/qmc.ts @@ -25,6 +25,8 @@ interface Handler { const HandlerMap: { [key: string]: Handler } = { "mgg": {handler: QmcMaskDetectMgg, ext: "ogg", detect: true}, "mflac": {handler: QmcMaskDetectMflac, ext: "flac", detect: true}, + "mgg.cache": {handler: QmcMaskDetectMgg, ext: "ogg", detect: false}, + "mflac.cache": {handler: QmcMaskDetectMflac, ext: "flac", detect: false}, "qmc0": {handler: QmcMaskGetDefault, ext: "mp3", detect: false}, "qmc2": {handler: QmcMaskGetDefault, ext: "ogg", detect: false}, "qmc3": {handler: QmcMaskGetDefault, ext: "mp3", detect: false}, @@ -57,6 +59,7 @@ export async function Decrypt(file: File, raw_filename: string, raw_ext: string) } else { audioData = fileData; seed = handler.handler(audioData) as QmcMask; + if (!seed) throw raw_ext + "格式仅提供实验性支持"; } let musicDecoded = seed.Decrypt(audioData); diff --git a/src/decrypt/qmccache.ts b/src/decrypt/qmccache.ts new file mode 100644 index 0000000..34e7165 --- /dev/null +++ b/src/decrypt/qmccache.ts @@ -0,0 +1,44 @@ +import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts"; + +import {Decrypt as QmcDecrypt} from "@/decrypt/qmc"; + +import {DecryptResult} from "@/decrypt/entity"; + +import {parseBlob as metaParseBlob} from "music-metadata-browser"; + +export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true) + : Promise { + let ext = raw_ext; + if (detect) { + const buffer = new Uint8Array(await GetArrayBuffer(file)); + let length = buffer.length + for (let i = 0; i < length; i++) { + buffer[i] ^= 0xf4 + if(buffer[i] <= 0x3f)buffer[i] = buffer[i] * 4; + else if(buffer[i] <= 0x7f)buffer[i] = (buffer[i] - 0x40) * 4 + 1; + else if(buffer[i] <= 0xbf)buffer[i] = (buffer[i] - 0x80) * 4 + 2; + else buffer[i] = (buffer[i] - 0xc0) * 4 + 3; + } + ext = SniffAudioExt(buffer, raw_ext); + if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]}) + else { + file = new Blob([buffer], {type: "application/octet-stream"}) + let ext = raw_filename.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase(); + if (ext !== "mgg" && ext !== "mflac") throw "不支持的QQ音乐缓存格式:" + raw_filename + ".cache"; + return QmcDecrypt(file, raw_filename, ext+".cache"); + } + } + const tag = await metaParseBlob(file); + const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist) + + return { + title, + artist, + ext, + album: tag.common.album, + picture: GetCoverFromFile(tag), + file: URL.createObjectURL(file), + blob: file, + mime: AudioMimeType[ext] + } +}