增加对网易云音乐.uc缓存格式和QQ音乐.cache缓存格式的支持 (#161)

* Update common.ts

* Create ncmcache.ts

* Create qmccache.ts
This commit is contained in:
qq1010903229 2021-06-03 13:00:35 +08:00 committed by GitHub
parent 2e31853ffb
commit 02a146e069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 0 deletions

View File

@ -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<DecryptResult> {
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<DecryptResult> {
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":

32
src/decrypt/ncmcache.ts Normal file
View File

@ -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<DecryptResult> {
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]
}
}

View File

@ -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);

44
src/decrypt/qmccache.ts Normal file
View File

@ -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<DecryptResult> {
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]
}
}